Hi, the following code uses a 3 day pattern to set up a BUY condition and sells 
on a trailing stop.


setup = H < Ref(H,-3) AND Ref(H,-1) < Ref(H,-3) AND Ref(H, -2) < Ref(H, -3) AND 
L > Ref(L,-3) AND Ref(L,-1) > Ref(L, -3) AND Ref(L, -2) > Ref(L, -3);
vsetup = ValueWhen(setup,Ref(H,-3),1); // Long Breakout.

Buy = Cross(C,vsetup);

ATR_Mult = Param("Multiple", 3, 1, 10, 1); //How many ATR's to be allowed below 
the highest high since latest "buy" bar
ATR_Pds = Param("ATR Periods", 14, 1, 50, 1); //How many periods to use for the 
ATR

Sell = Cross( HighestSince( Buy, C - ATR_Mult * ATR(ATR_Pds)), C ); 

Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);


InTrade = Flip( Buy , Sell );
SetOption("EveryBarNullCheck", True );

stopline = IIf( intrade, HighestSince( Buy, C - ATR_Mult * ATR(ATR_pds)), Null);


What happens is that the "vsetup" condition is held even after a BUY/SELL cycle 
hence multiple BUY/SELL happen from the original condition before a new 
"vsetup" condition is triggered.

What I want to do is reset the "vsetup" condition when either:

1. 5 bars have past without a BUY being triggered, or
2. After the first SELL is triggered.

I seems this is beyond my current level of expertise.

Can I get some help.

Thanks and regards..............Keith


Reply via email to