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)
|
Just to summarise what already has been posted by Patrick, and perhaps extend it slightly.....
Downloading the file
To download the file:
[list=1:3d1d1c095b]
[*:3d1d1c095b]You have to be a registered member of the Equis community
[*:3d1d1c095b]Download the file, "ForumDll.[censored]" (current version available in this forum) to the MetaStock ExternalFunctionDll folder, most commonly found on your computer at C:\\Program Files\\Equis\\ExternalFunctionDll
[*:3d1d1c095b]Rename the downloaded file (ForumDll.[censored]) ForumDll.dll
[*:3d1d1c095b]If MetaStock is running, close it and re-open it
[/list:o:3d1d1c095b]
The file should now be able to be called from within MetaStock.
Using the file
Patrick has given us examples of how to use the latch for different purposes:
ENTER LONG :
LE:={your Condition here};
LX:={your Condition here};
SE:={your Condition here};
SX:={your Condition here};
B:= ExtFml("ForumDll.Latch",LE,LX,SE,SX);
B = 1 AND Ref(B,-1) <> 1
ENTER SHORT :
LE:={your Condition here};
LX:={your Condition here};
SE:={your Condition here};
SX:={your Condition here};
B:= ExtFml("ForumDll.Latch",LE,LX,SE,SX);
B = -1 AND Ref(B,-1) <> -1
EXIT LONG :
LE:={your Condition here};
LX:={your Condition here};
SE:={your Condition here};
SX:={your Condition here};
B:= ExtFml("ForumDll.Latch",LE,LX,SE,SX);
B = 0 AND Ref(B,-1) = 1
EXIT SHORT :
LE:={your Condition here};
LX:={your Condition here};
SE:={your Condition here};
SX:={your Condition here};
B:= ExtFml("ForumDll.Latch",LE,LX,SE,SX);
B = 0 AND Ref(B,-1) = -1
Long Trades ONLY
If you are interested in long trades only and do not short stocks, then you do not need to include the SE and SX variable declarations, but must replace the SE and SX passing variables with zero.
ENTER LONG :
LE:={your Condition here};
LX:={your Condition here};
B:= ExtFml("ForumDll.Latch",LE,LX,0,0);
B = 1 AND Ref(B,-1) <> 1
EXIT LONG :
LE:={your Condition here};
LX:={your Condition here};
B:= ExtFml("ForumDll.Latch",LE,LX,0,0);
B = 0 AND Ref(B,-1) = 1
Short Trades ONLY
If you are only interested in short trades, then you do not need to include the LE and LX variable declarations, but must replace the LE and LX passing variables with zero.
ENTER SHORT :
SE:={your Condition here};
SX:={your Condition here};
B:= ExtFml("ForumDll.Latch",0,0,SE,SX);
B = -1 AND Ref(B,-1) <> -1
EXIT SHORT :
SE:={your Condition here};
SX:={your Condition here};
B:= ExtFml("ForumDll.Latch",0,0,SE,SX);
B = 0 AND Ref(B,-1) = -1
So how do I know when I am in a trade?
or
Putting this latch-thingy to work!
If we only look at long trades for the moment...
Lets say you have developed your system, with defined entry and exit criteria, like a moving average crossover system. Your entries are when the fast MA crosses above the slow MA, and exits when the reverse happens, coded as:
fastMA:=Mov(C,7,S);
slowMA:=Mov(C,21,S);
LE:=Cross(fastMA,slowMA);
LX:=Cross(slowMA,fastMA);
I have changed the 'B' variable (below) to 'Z' to avoid getting confused with buy and sell signals....
Now the criteria has been defined, we call the external formula to only trigger a BUY signal if (and only if) a buy signal has not been previously set without a sell signal, or the last signal was a sell signal. Read both cases as, we arent already in a long trade. The sell signal will only set if we are in a long trade.
Z:= ExtFml("ForumDll.Latch",LE,LX,0,0);
EnterLong:=Z = 1 AND Ref(Z,-1) <> 1;
ExitLong:=Z = 0 AND Ref(Z,-1) = 1;
We now want to plot these on a chart. One of the easiest ways is to just plot:
EnterLong;
ExitLong;
If we plot this on a chart, the indicator value be zero, except when a buy or sell signal is generated and the value will be one. (Its handy to plot this as a histogram) But how do we tell the two signals a part? We could just keep track of which signal occurred when, but it might get a little confusing, so try plotting this instead:
EnterLong-ExitLong;
This indicator line will be +1 when a buy signal is generated and -1 when a sell signal is generated. You can now tell at a glance which signal is which.
Long Trade Code Summary:
fastMA:=Mov(C,7,S);
slowMA:=Mov(C,21,S);
LE:=Cross(fastMA,slowMA);
LX:=Cross(slowMA,fastMA);
Z:= ExtFml("ForumDll.Latch",LE,LX,0,0);
EnterLong:=Z = 1 AND Ref(Z,-1) <> 1;
ExitLong:=Z = 0 AND Ref(Z,-1) = 1;
EnterLong-ExitLong;
You can follow exactly the same process for short trading.
I hope this helps people use this new functionality. Remember if you like the latch system, post your thanks to Patrick for his excellent efforts here. He did this off his own back and in his own time, so we offer him our gratitude.
Hope this helps.
wabbit :D
P.S. More applications of the latch at a slightly higher level will follow...
|