Exrem function and Stop loss

#1
Hello Members,
The signals generated by afl code on daily basis are correct but when I do period wise back testing few trades are ignored by afl.

My stop loss is low of last five candles from entry price. This SL is continuously being updated as position is open, which is causing trouble with afl back testing.

Can I fix my SL once position is open.

Your help will be deeply appreciated
Buy = 0;

Short = 0;

Sell = 0;

Cover = 0;



Buy = PriceActionCriteriaLong AND Status("BarInRAnge") AND TimeNum()<150500;

Short = PriceActionCriteriaShort AND Status("BarInRAnge") AND TimeNum()<150500;



Buy = (ExRem(Buy, Sell));

Short = (ExRem(Short,Cover));





BuyPrice = iif(Buy==1,ValueWhen(Buy,Close,1),Null);

Stoplevelbuy = 0;

Targetlevelbuy = 0;



Stoplevelbuy = ValueWhen(Buy,LLV(Low,5)-1.2*ATR(21),1);

Targetlevelbuy = ValueWhen(Buy,BuyPrice + (BuyPrice-Stoplevelbuy )*8,1);

StopBuy = Cross(Stoplevelbuy,Low);

TargetBuy = Cross(High,Targetlevelbuy);



ShortPrice = iif(Short==1,ValueWhen(Short,Close,1),Null);

Stoplevelshort = 0;

Targetlevelshort = 0;



Stoplevelshort = ValueWhen(Short,HHV(High,5)+1.2*ATR(21),1);

TargetlevelShort = ValueWhen(Short,ShortPrice-(Stoplevelshort-ShortPrice)*8,1);

StopShort = Cross(High,Stoplevelshort);

TargetShort = Cross(TargetlevelShort,Low);





Sell = IIf((Sum(Buy,BarsOfDay)-Sum(Sell,BarsofDay))>0, (StopBuy OR TargetBuy OR TimeNum()>151300),0) AND Status("BarInRAnge");

Cover =IIf((Sum(Short,BarsOfDay)-Sum(Cover,BarsofDay))>0,(StopShort OR TargetShort or TimeNum()>151300),0) AND Status("BarInRAnge");



/*

Sell = (StopBuy OR TargetBuy OR TimeNum()>151300) AND Status("BarInRAnge");

Cover = (StopShort OR TargetShort or TimeNum()>151300) AND Status("BarInRAnge");

*/



Filter = Buy OR Sell OR Cover OR Short;



Sell = Exrem(Sell,Buy);

Cover = Exrem(Cover,Short);

Buy = (ExRem(Buy, Sell));

Short = (ExRem(Short,Cover));
 

Similar threads

Intraday Higher Leverage

Save up to 90% in brokerage and get higher leverage for intraday trades.

Name:Phone:
Email:City:
State:
Are you a day trader?