logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

2 Pages12>
Options
Go to last post Go to first unread
Patrick  
#1 Posted : Tuesday, March 14, 2006 12:06:30 PM(UTC)
Patrick

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 9/8/2004(UTC)
Posts: 2,266

Was thanked: 1 time(s) in 1 post(s)
After reading Roy's article, I made a list of things to fix in the current forum Dll. I'm making a list here of what I have fixed and how or why .... Aroon Function is fixed ( Needed to adjust code to reflect only one array being used versus High and Low and corrected periods calc) Bollinger bands functions have been modified to add a method choise just like the moving average function. Created CCI (Equis) variable function. Fixed the trianguar avergage calculations. Fixed Date Range function (The original code was not very clean and my inputs were variable arrays instead of simple int, also added some error traps) Fixed Custom SAR (Here something happened in between versions, it was just a matter of copying the right code in the right place) Updated the source code to Visual Studio 2005 Also thanks to Brad Ulrich of www.thedml.com I was able to copy his work and create a solution where each function has it's own cpp file which helps with me not messing up something while trying to fix something else and etc ... :P Next I will try to fix the TD COMBO and the random value. I will try to create a prev based latch function and a loop function. Patrick :mrgreen:
wabbit  
#2 Posted : Tuesday, March 14, 2006 12:24:10 PM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
Patrick, Can you post the source code too? (You might have already, but honestly, I haven't checked!) If you like, I will attempt to update the Manual next week (its a non-teaching week at Uni). wabbit :D P.S. How are your new adventures going Patrick? You haven't provided many reports lately?
hayseed  
#3 Posted : Tuesday, March 14, 2006 12:29:38 PM(UTC)
hayseed

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 3/7/2005(UTC)
Posts: 1,346

hey patrick.... are theses changes reflected in the stable version dll posted now, meaning we should redownload for the updates or wait...... and for us unstable types, will the 30 function beta version be updated at the same time ...... its the one i use..... h
Patrick  
#4 Posted : Tuesday, March 14, 2006 12:30:54 PM(UTC)
Patrick

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 9/8/2004(UTC)
Posts: 2,266

Was thanked: 1 time(s) in 1 post(s)
:eek: You just gave me a deadline to finish everything by next week :D I' ll do my best ... Thanks for the help offer I appreciate it :) Well my adventures are going ... Not great not too bad but I'm having a culture shock here :lol: How are yours? I see you are taking it easy ... A week of vacation? :P Patrick :mrgreen:
Patrick  
#5 Posted : Tuesday, March 14, 2006 12:33:33 PM(UTC)
Patrick

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 9/8/2004(UTC)
Posts: 2,266

Was thanked: 1 time(s) in 1 post(s)
The new version is not yet posted ... I'm not done fixing everything yet. :oops: I will fix the 30 functions version and add more to it ... But I will post something when all is ready and available :) Patrick :mrgreen:
Patrick  
#6 Posted : Tuesday, March 14, 2006 1:47:59 PM(UTC)
Patrick

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 9/8/2004(UTC)
Posts: 2,266

Was thanked: 1 time(s) in 1 post(s)
I could use an example ... Please :) I remeber Jose posted one but I cant find it ... Patrick :mrgreen:
wabbit  
#7 Posted : Tuesday, March 14, 2006 2:11:57 PM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
From Roys Latches article that used to posted around here somewhere?.......
Roy wrote:
Latches Using latches in MetaStock (or flags as I prefer to call them) is a simple and convenient way of remembering code conditions or events. This document is an attempt to explain the various constructions and uses of latches as they relate to ‘Trade equity’ and ‘Trade Stop’, but it by no means covers all there is to write on the subject. A ‘latch’ is a device that stores and holds, or remembers, a particular event or condition. A ‘binary latch’ can be set to one of two values (normally zero and one but not necessarily so), while a ‘price latch’ can be set to virtually any value one could think of. Each type has both advantages and disadvantages that will be mentioned as appropriate. In the following discussion please note that ‘one’ is interchangeable with ‘true’ or ‘on’, and ‘zero’ with ‘false’ or ‘off’. You may wonder why I do not write a line such as - “ N:=Fml("set signal"); ” as “ N:=Fml("set signal")=1; ”. The reason is that MS “assumes” that I am referring to the “true” condition of that binary variable, and so adding “=1” is redundant. Only if I am looking for a “false” condition do I need to specify the state by adding “=0”. I should also need to point out that MetaStock does not know the difference between a ‘price’ variable and a ‘binary’ variable. For example it will treat a ‘price’ variable of 0.99c as a binary zero unless your coding makes it clear as to how the variable should be treated. In the same manner a ‘price’ variable of $1.00 or higher will be treated as a binary one unless your coding clarifies the intended usage. Binary Latch Description Example 1 presents the simplest form of a latch. It requires two signals to operate – a ‘set’ signal, and a ‘reset’ signal. You could think of these signals as the latch ‘on’ switch and the ‘off’ switch. By using the BarsSince() function we are able to decide which signal occurred most recently, and therefore whether the current state of the latch should be ‘on’ or ‘off’. MetaStock processes a chart from the first bar on the left to the last bar on the right. This means that the latch condition is checked and updated as each new bar is processed from left to right. {Example 1} N:=Fml("set signal"); X:=Fml("reset signal"); BarsSince(N)<BarsSince(X); One problem to be addressed with this simple code is that the output line (using BarsSince) can have an extended invalid signal period. In other words it will return a value of N/A instead of a legitimate value. This N/A period will extend from the first bar on the chart until the ‘set’ signal is true and the ‘reset’ signal is valid. This extended N/A can be addressed by adding an ‘initialized’ variable into the output line. I normally name this variable ‘I’, and its purpose is to inform any code following ‘N’ and ‘X’ that the set and reset signals are valid – i.e. are not returning N/A. In this latch configuration it also serves to create ‘fake’ set and reset signals that provide a specific starting point (bar) for the latch. It is also convenient to name the output line variable because additional code usually follows. Example 2 is a complete binary latch and as such it can store only two values – zero and one. {Example 2} N:=Fml("set signal"); X:=Fml("reset signal"); I:=Cum(N+X>-1)=1; Tr:=BarsSince(I OR N)<BarsSince(I OR X); Tr; The ‘I’ variable confuses many people. It will be ‘true’ (or one) for the first bar when both set and reset signals are valid, and ‘false’ (zero) for every bar thereafter. Until both set and reset signals are valid it also will be invalid and return a value of N/A. ‘I’ being true for one bar provides the ‘fake’ set and reset signals used to kick the latch into action. Notice that the construction if ‘I’ is not concerned with actual values, but whether or not ‘N’ and ‘X’ are VALID. The sum of the two inputs (‘N’ and ‘X’) cannot be tested as being greater than –1 until both return a value of at least zero once both are valid. Since ‘N’ and ‘X’ are binary signals (zero or one), by definition they will never be less than zero. The Cum() count equal to one ensures that this signal is true for the first valid bar only, and false for every bar after that. That’s OK because its whole purpose is generate a ‘true’ for just the one initial bar. It is possible to assign values other than zero and one to the latch output, but be aware that this latch can’t be used to store prices. The reason is that multiple set signals will allow the stored price to change. However the If() function can be used to select the two values that that latch can swing between. {Example 3} N:=Fml("set signal"); X:=Fml("reset signal"); I:=Cum(N+X>-1)=1; Tr:=If(BarsSince(I OR N)<BarsSince(I OR X),1,0); Tr; Now that we are able to assign different values to the ‘Tr’ variable one needs to be aware that not all methods of making ‘Tr’ are equal. Tr:=If(BarsSince(I OR N)<BarsSince(I OR X),1,0); Is functionally identical to Tr:=If(BarsSince(I OR N)>=BarsSince(I OR X),0,1); But neither is the same as Tr:=If(BarsSince(I OR N)>BarsSince(I OR X),0,1); The difference is in the use of “=” with “>” or “<” symbols. Written the wrong way the section of the flag prior to the first ‘set’ signal will be the inverse of its proper state. This may be only a small point but to my mind it is still the difference between right and wrong. The testing of historical data demands that our test signals are accurate for ALL data under test so please take care with this potential trap. Typical Signal Timing for Binary Latch. High is ‘one’, low is ‘zero’, __ _ __/ \\_____/\\_______________/ \\__ set (N) __ N/A ___/\\____________/ \\________ reset (X) N/A \\____________________________ Initialization (I) _________ ____ N/A _______/ \\______/ latch state (Tr) Price Latch Description A PREV version of the humble latch offers more options for MS coding because it can “remember” a user determined value. This value can then be accessed from within the latch (by using the PREV function) to manage a number of resets that can be related to the ‘set’ signal or timing. The one major down side to using PREV is that it is resource hungry and it will significantly slow the execution time of any code using it. Each additional PREV further increases the resource burden. {Example 4} N:=Fml("set signal"); X:=Fml("reset signal"); Tr:=If(N,1,If(X,0,PREV)); Tr; Example 4 is the simplest form of a PREV based latch, and here it is still being used to give a binary result because it has no way of discriminating between the first and subsequent ‘set’ signals. By checking the previous state of ‘Tr’ (using PREV) we can ensure that only the FIRST bar of the entry signal is used to decide what value to store in the latch. Notice that the ‘I’ variable is not used in this latch. It is not needed to provide a starting point once PREV is introduced, and neither is there any problem, other than a lack of skill, in setting the correct polarity of the output signal ‘Tr’. I suggest that all PREV variables be named, and this is particularly important when is used in what is effectively the output line – I have had some unpredictable results when using PREV as an unnamed output line. {Example 5} N:=Fml("set signal"); X:=Fml("reset signal"); Tr:=If(PREV=0,If(N,CLOSE,0),If(X,0,PREV)); Tr;
... to be continue
wabbit  
#8 Posted : Tuesday, March 14, 2006 2:13:24 PM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
....continued
Roy wrote:
Example 5 has expanded the role of the latch to that of a true ‘price’ latch, and here it is storing the CLOSE from the initial ‘set’ bar. The only time the latch will set to something other than zero is when the previous bar of the latch was zero (latch not active) and the ‘N’ variable (set) is active for the current bar. If these conditions are not both met then the latch can either retain its previous value, or it can reset to zero if the ‘X’ variable is active. From that configuration it is an easy step to create a latch that can monitor its own value and be self-resetting when specific ‘set’ related criteria are met. Example 6 shows how to reset the latch when the closing price rises to 20% above that when the latch was set. Notice that in this example the reset signal ‘X’ is ‘ORed’ with the price condition to reset the latch (reset signal OR price condition). Either condition true will force a reset. {Example 6} N:=Fml("set signal"); X:=Fml("reset signal"); Tr:=If(PREV=0,If(N,CLOSE,0),If(X OR C>=PREV*1.2,0,PREV)); Tr; The independent reset signal may well be unnecessary with this type of latch if both positive and negative movements can be checked against the stored value, as demonstrated in Example 7 below. {Example 7} N:=Fml("set signal"); Tr:=If(PREV=0,If(N,CLOSE,0),If(C>=PREV*1.2 OR C<=PREV*0.9,0,PREV)); Tr; I hope that this explanation has cleared away some of the mystery regarding the construction and potential use of binary and price latches. A binary latch forms the heart of all my ‘Trade Equity’ indicators, and a price latch fills a very similar role in all of my ‘Trade Stop’ indicators. Roy Larsen rlarsen@man.quik.co.nz
wabbit :
Patrick  
#9 Posted : Tuesday, March 14, 2006 2:20:13 PM(UTC)
Patrick

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 9/8/2004(UTC)
Posts: 2,266

Was thanked: 1 time(s) in 1 post(s)
Smart ass :lol: I knew that one but it is too complex for me :D :cry: I added the Variable Wilder's Smoothing function. Patrick :mrgreen:
Patrick  
#10 Posted : Tuesday, March 14, 2006 2:25:44 PM(UTC)
Patrick

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 9/8/2004(UTC)
Posts: 2,266

Was thanked: 1 time(s) in 1 post(s)
I guess My Problem is that I'm trying to create just one latch function, should I just create another Function called "Lacth Prev Based" versus "Latches - Simple Flags" ??? Patrick :mrgreen:
Patrick  
#11 Posted : Tuesday, March 14, 2006 4:15:31 PM(UTC)
Patrick

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 9/8/2004(UTC)
Posts: 2,266

Was thanked: 1 time(s) in 1 post(s)
This function is fixed here is the new code: [code:1:6200e4eedc]#include <string.h> #include <float.h> #include <math.h> #include <limits.h> #include <stdlib.h> #include <ctime> // For Random Function void RandomCalc (const MSXDataRec * Data,const MSXDataInfoRec * Min, const MSXDataInfoRec * Max, MSXDataInfoRec * Result) { int startIdx = Data->sClose.iFirstValid; int endIdx = Data->sClose.iLastValid; int i; int random_integer = 0; int range; int Mini; time_t seconds; time(&seconds); for(i=startIdx;i<=endIdx;i++) { srand((unsigned)time(0)); range = (int)ForceIntRange(Max->pfValue[i]-Min->pfValue[i])+1; Mini = (int)ForceIntRange(Min->pfValue[i]); random_integer = Mini+int(range*rand()/(RAND_MAX + 1.0)); Result->pfValue[i] = (float)ForceFloatRange(random_integer); } }[/code:1:6200e4eedc] Patrick :mrgreen:
StorkBite  
#12 Posted : Tuesday, March 14, 2006 6:23:25 PM(UTC)
StorkBite

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 3/19/2005(UTC)
Posts: 2,995

Was thanked: 14 time(s) in 10 post(s)
Wow, P... that was a speedy response! You rule! :rockin:
Patrick  
#13 Posted : Tuesday, March 14, 2006 7:35:08 PM(UTC)
Patrick

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 9/8/2004(UTC)
Posts: 2,266

Was thanked: 1 time(s) in 1 post(s)
I don't kid around :jbond: I should have something for you to test soon g :lol: Patrick :mrgreen:
Patrick  
#14 Posted : Tuesday, March 14, 2006 9:10:53 PM(UTC)
Patrick

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 9/8/2004(UTC)
Posts: 2,266

Was thanked: 1 time(s) in 1 post(s)
Well besides the Touchy TD COMBO and teh Latch Prev based that is not complete, everything else should be good. G you want to give it a ride? This is a testing version do not use it unless you know what you are doing :D Patrick :mrgreen:
StorkBite  
#15 Posted : Tuesday, March 14, 2006 11:00:06 PM(UTC)
StorkBite

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 3/19/2005(UTC)
Posts: 2,995

Was thanked: 14 time(s) in 10 post(s)
Will do, P... it will be tomorrow before I can get to it though... slammed right now. :(
Patrick  
#16 Posted : Tuesday, March 14, 2006 11:08:09 PM(UTC)
Patrick

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 9/8/2004(UTC)
Posts: 2,266

Was thanked: 1 time(s) in 1 post(s)
No problem, babies come first :D
Marilyn  
#17 Posted : Wednesday, March 15, 2006 12:43:40 AM(UTC)
Marilyn

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 9/10/2004(UTC)
Posts: 863
Location: Salt Lake City, UT

:lol: :lol: :lol: Yeah - I think my job has issues... g - you are the man!
mstt  
#18 Posted : Wednesday, March 15, 2006 12:54:39 AM(UTC)
mstt

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/25/2005(UTC)
Posts: 1,042

Was thanked: 57 time(s) in 54 post(s)
Patrick For what it's worth, I think a "PREV-Based" latch is a totally different animal from a "simple" latch. I wouldn't presume to tell you whether to integrate the two types into one function, but it seems to me that a PREV-based latch would require additional user parameters, and it would not benefit (IMO) from long and short versions. I can see the reasoning for long and short in a simple latch setup, but I remain of the opinion that two seperate latches that are completely independant are preferable to two that have an internal linking (even if it is only by virtue of having a common output). Because there are so many ways that a PREV-based latch can be used, and different outputs possible, I don't envy you the task of trying to come up with something that is universally acceptable. Good luck with whatever approach you take, and may the critics like myself be more than satisfied with the eventual result. Roy MetaStock Tips & Tools
smg  
#19 Posted : Wednesday, March 15, 2006 4:46:27 PM(UTC)
smg

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 8/13/2005(UTC)
Posts: 90

It is nice to see the DLL zone active again. Obviously, I jumped to the WSM function first on downloading the new DLL. On the right side of the chart it is working fine. Just on the left side of the chart there is a small issue: PDN := If(Cum(1)<14,Cum(1),14); ExtFml("Forum_NEW.WSM",C,PDN); The above formula does not have a plot for the first 27 bars. Thanks again. Regards SMG
smg  
#20 Posted : Wednesday, March 15, 2006 4:53:54 PM(UTC)
smg

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 8/13/2005(UTC)
Posts: 90

Patrick, I tested LinearReg funtion also in an Exploration and one of the securities threw up the following error: An MSX DLL is reporting a floating point invalid operation error. Referenced DLL: "Forum_NEW.LinearReg" Regards SMG
Users browsing this topic
Guest (Hidden)
2 Pages12>
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.