Intraday stop using daily bar

Good day to you all. I have a gap strategy (short only) using fixed stop loss and n-bar stop loss. When I try to set the fixed stop loss as 3-percent from the entry price, I observe that it does not close the position at (Entry price * 1.03) exactly but at some other prices, e.g. close price / prices I could not explain.

I have tried my very best to go through AFL Function Reference - APPLYSTOP and also post by ApplyStop query but I am still not be able to figure out the solution to this problem. Can anyone point me where I might have done wrong please?

SetPositionSize(100,spsPercentOfEquity);
SetTradeDelays( 0, 0, 0, 0 );
SetOption( "ActivateStopsImmediately", False );
SetOption( "AllowSameBarExit", False); 
SetOption("MaxOpenPositions",100);


GapD = GapDown();

MovingAv1 = MA(C,Optimize("M1",30,10,100,10));
MovingAv2 = MA(C,Optimize("M2",100,50,250,50));


Short = GapD AND MovingAv1 < MovingAv2;
Cover = 0;



ApplyStop( stopTypeNBar, stopModeBars,Optimize("Time Stop",21,1,40,2),1);
//ApplyStop( stopTypeTrailing, stopModePercent, Optimize("TS",5,3,10,1) ,1);
ApplyStop(stopTypeLoss,	stopModePercent, Optimize("Stop Loss",3,3,10,1),1);



Equity(1,-1);

Filter = 1;
AddColumn(ValueWhen(Short,Close)*1.03,"ValueWhen",1.2);
AddColumn(H,"H",1.2);
AddColumn(Short,"Short",1.2);
AddColumn(Cover,"Cover",1.2);
AddColumn(C,"Close",1.2);
AddColumn(ShortPrice,"ShortPrice",1.2);

I tried to set True for "ActivateStopsImmediately" for it could not be executed at the exact stop loss price still.

You do not have Coverprice column in your exploration.
Also Set Filter = Cover > 0;

So

//...

eq = Equity(1,-1);

Filter = Cover>0;
AddColumn(ValueWhen(Short,ShortPrice),"ShortPrice",1.2);
AddColumn(ValueWhen(Short,ShortPrice)*1.03,"SL Target",1.2);
AddColumn(O,"Open",1.2);
AddColumn(H,"H",1.2);
AddColumn(L,"L",1.2);
AddColumn(C,"Close",1.2);
AddColumn(Cover,"Cover",1.2);
AddColumn(IIf(Cover==2, 1, Null),"Cover SL",1);
AddColumn(IIf(Cover==5, 1, Null),"Cover nBar",1);
AddColumn(CoverPrice,"CoverPrice",1.2);

Complete code ->

SetPositionSize(100,spsPercentOfEquity);
SetTradeDelays( 0, 0, 0, 0 );
SetOption( "ActivateStopsImmediately", False );
SetOption( "AllowSameBarExit", False); 
SetOption("MaxOpenPositions",100);

GapD = GapDown();
MovingAv1 = MA(C,Optimize("M1",30,10,100,10));
MovingAv2 = MA(C,Optimize("M2",100,50,250,50));

ShortPrice = C;
Short = GapD AND MovingAv1 < MovingAv2;
Cover = 0;

ApplyStop( stopTypeNBar, stopModeBars,Optimize("Time Stop",21,1,40,2),1);
//ApplyStop( stopTypeTrailing, stopModePercent, Optimize("TS",5,3,10,1) ,1);
ApplyStop(stopTypeLoss,	stopModePercent, 3,1);

eq = Equity(1,-1);

Filter = Cover>0;
AddColumn(ValueWhen(Short,ShortPrice),"ShortPrice",1.2);
AddColumn(ValueWhen(Short,ShortPrice)*1.03,"SL Target",1.2);
AddColumn(O,"Open",1.2);
AddColumn(H,"H",1.2);
AddColumn(L,"L",1.2);
AddColumn(C,"Close",1.2);
AddColumn(Cover,"Cover",1.2);
AddColumn(IIf(Cover==2, 1, Null),"Cover SL",1);
AddColumn(IIf(Cover==5, 1, Null),"Cover nBar",1);
AddColumn(CoverPrice,"CoverPrice",1.2);

As you can see third and last column are in line when there is exit by stop loss:

Thanks fxshrat. But after I implemented the new code, it seems the trade is still exist on the day high instead of immediate stop loss price level. Did I miss anything?
image

What is output of explorer?
Look at Open price column!
The code I added is explorer (result list) code not backtest code.

Apparently you have a gap (with prices exceeding stop target) so it would exit at Open price.

(As aside: If you post table pictures then include table header)

2 Likes

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.