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

Notification

Icon
Error

Options
Go to last post Go to first unread
lcl  
#1 Posted : Sunday, January 22, 2006 4:06:11 PM(UTC)
lcl

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 5/22/2005(UTC)
Posts: 59

I am trying to remove the PREV function of the following code to speed up its execution... TurtleBuy:=If(H>Ref(HHV(H,20),-1),1,If(L<Ref(LLV(L,10),-1),0,Prev)); TurtleBuy Has anybody got any ideas? Thanks in advance!
Patrick  
#2 Posted : Sunday, January 22, 2006 5:22:52 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)
Try this: LE:=H>Ref(HHV(H,20),-1); SE:=L<Ref(LLV(L,10),-1); ExtFml("forum.Latch",LE,0,SE,0) Patrick :mrgreen:
lcl  
#3 Posted : Monday, January 23, 2006 11:20:28 AM(UTC)
lcl

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 5/22/2005(UTC)
Posts: 59

Hi Patrick, Thank you for your reply! But what is ExtFml("forum.Latch",LE,0,SE,0)? I am totally lost.....
Patrick  
#4 Posted : Monday, January 23, 2006 3:36: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)
It is the latch function from the forum dll ... Download and read the manual from the downloads section... Patrick :mrgreen:
mstt  
#5 Posted : Monday, January 23, 2006 7:15:34 PM(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)
lcl It might help if you take a little time to understand the concept of a non-PREV latch before you move to using the latch in Patrick's Forum DLL. Here are some examples of a simple latch (as opposed to the PREV latch that you asked the question about). This latch uses BarsSince() to test whether the most recent event was a "buy" or a "sell". If the most recent even was a buy then the latch is "on" or TRUE, and if the most recent event was a sell then the latch is "off" or FALSE. See example 1. {example 1} N:=H>Ref(HHV(H,20),-1); X:=L<Ref(LLV(L,10),-1); TurtleBuy:=If(BarsSince(N)<BarsSince(X),1,0); TurtleBuy; If you test example 1 against your PREV latch you'll see that it can miss the first buy signal, and it will certainly plot N/A for more bars than the PREV version. This can be remedied by adding an "initialisation" variable that simply generates a fake buy and sell signal on the first bar that both the buy and sell signals are valid. These fake signals allow each BarsSince() function to begin a valid plot (instead of N/A), and therefore the resulting plot from TurtleBuy is also valid as soon as both the buy and sell signals are valid. See example 2. {example 2} N:=H>Ref(HHV(H,20),-1); X:=L<Ref(LLV(L,10),-1); I:=Cum(IsDefined(N AND X))=1; TurtleBuy:=If(BarsSince(N OR I)<BarsSince(X OR I),1,0); TurtleBuy; The IsDefined() function offers nothing of particular value and the initialation variable can easily be constructed with just a Cum() function - see example 3. {example 3} N:=H>Ref(HHV(H,20),-1); X:=L<Ref(LLV(L,10),-1); I:=Cum(N+X>-1)=1; TurtleBuy:=If(BarsSince(N OR I)<BarsSince(X OR I),1,0); TurtleBuy; You don't need to use the If() function to generate TRUE and FALSE states - a simple comparison does the trick as the If() function is redundant. If() is useful if you want to assign constant values other than ONE and ZERO to the latch result. Also notice how the "+" operator can be used instead of the logical "OR" operator. This is not mandatory but it can be a useful space-saving technique. See example 4. {example 4} N:=H>Ref(HHV(H,20),-1); X:=L<Ref(LLV(L,10),-1); I:=Cum(N+X>-1)=1; TurtleBuy:=BarsSince(N+I)<BarsSince(X+I); TurtleBuy; You do not need to use PREV to construct a latch where the buy and sell signals (set and reset if you like) are independant of each other. Patrick's DLL-based latch function is an excellent substitute for the simple-latch exercises shown above. However, when a sell is based of some aspect of the buy (timing, price, indicator value, etc.) you do generally need to use a PREV-based latch to get the desired result. That's another story. Roy MetaStock Tips & Tools
lcl  
#6 Posted : Thursday, January 26, 2006 7:56:15 AM(UTC)
lcl

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 5/22/2005(UTC)
Posts: 59

Hi Roy, That are exactly what I want; thank you very much!!!
Users browsing this topic
Guest (Hidden)
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.