Execution bar sell signals

Hello all,

I'm trying to understand how the execution of buy/sell works in AFL. Currently I have made a custom max loss stop to get a better understanding of the engine. Buy signals work as expected but when checking the sell signal, I noticed that this only gets executed the NEXT bar and not intrabar (see backtest result screenshot). I do have the options checked. There is probably a logical explanation for this but I'm not seeing it. Help would be much appreciated.

//exits
SetOption( "AllowSameBarExit", true);
SetOption("ActivateStopsImmediately", True );

priceatbuy=0; 
trailmax=0;
tradeopen=False;
for( i = 0; i < BarCount-1; i++ ) 
{ 
    if( priceatbuy == 0 && Buy[ i ] AND tradeopen==false) 
    {
		priceatbuy = BuyPrice[ i+1 ];
		trailmax[i]=0;
		stop=priceatbuy-stopx[i];
		tradeopen=True;
	}

    if( priceatbuy > 0 AND tradeopen==true) 
    { 
		trading=True;
		
		if(stopn>0 AND trading==true)
		{
			if(Low[i]<=stop)
			{
				_tracef("Stop triggered");
				_tracef(NumToStr(priceatbuy));
				_tracef(NumToStr(priceatbuy-stop));
				_tracef(NumToStr(stop));
				exitp=Detgap(High[i-1],Low[i-1],Open [i],1,stop);
				_tracef(NumToStr(exitp));
				Sell[ i ] = 2; 
				SellPrice[ i ] = exitp;
				priceatbuy = 0;
				trading=False;
				tradeopen=False;
			}
		}
	}		
}

image

image

Solved with:
settradedelays( 1, 0, 1, 0);

Knowledge base and forum are great!

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