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)
|
Hi TM
Here are two forms of a simple latch that you can use to capture the state of a trade and from that reduce the buy and Sell signals down to just the active bar of each signal. The revised Buy and Sell signals use the Alert() function to monitor for a change in the Trade variable. Trade*Alert(Trade=0,2) requires Trade to be TRUE for the current bar and FALSE for the previous bar. The reverse applies to (Trade=0)*Alert(Trade,2). I've substituted * for AND and + for OR in these formulas - technically it might not look right but in practice it works fine when used properly, and the advantage is that it economises on space.
{Latch method 1 - Roy Larsen} Buy:=H>Ref(H,-1) AND Ref(H,-1)>Ref(H,-2) AND Ref(H,-2)>Ref(H,-3); Sell:=L<Ref(L,-1) AND Ref(L,-1)<Ref(L,-2) AND Ref(L,-2)<Ref(L,-3); I:=Cum(IsDefined(Buy+Sell))=1; Trade:=BarsSince(I+Buy)<BarsSince(I+Sell); Buy:=Trade*Alert(Trade=0,2); Sell:=(Trade=0)*Alert(Trade,2); Buy; Sell;
{Latch method 2 - Jose Silva} Buy:=H>Ref(H,-1) AND Ref(H,-1)>Ref(H,-2) AND Ref(H,-2)>Ref(H,-3); Sell:=L<Ref(L,-1) AND Ref(L,-1)<Ref(L,-2) AND Ref(L,-2)<Ref(L,-3); I:=Cum(IsDefined(Buy+Sell))=1; Trade:=ValueWhen(1,I+Buy+Sell,Buy); Buy:=Trade*Alert(Trade=0,2); Sell:=(Trade=0)*Alert(Trade,2); Buy; Sell;
Hope this helps
Roy
|