Backtest entry time inconsistent with Explore signal

My system operates on 1 second interval. I use SetBacktestMode(backtestRegularRaw). I allow same bar entry / exit (as visible on 2nd screenshot).

On 1st screenshot I marked position reversals which are correct (happen within the same second) with green checkmarks. The ones I have problem with, have dates surrounded with red circles. Remaining rows have position closed just before end of session, what is correct and can be ignored.

I wonder why the ones with red circles have some gaps before reverse position is opened. On backtest (2nd screenshot) I presented signals for one such situation from backtest (2nd red circles pair). Current signal is Short, then on 09:26:08 Buy appears, so I would expect Long position to be opened since this bar, but it is entered on next buy signal on 09:27:02 instead. Buy condition is in this case High >= 2139. In other 2 cases also Long position has been entered on the very next Buy signal.

The problem exists for Buy -> Short reversal as well and the one I checked had Long closed on 1st Short signal, but Short opened 3 Short signals later.

All candle prices and signal prices are integers.



Thanks to @fxshrat who recommended running backtest with "Detailed log" in Settings, Report tab, I was able to find the reason behind this behavior.

It came out that entering position was delayed due to insufficient trading volume on this 1 second bar. The same does NOT apply to exiting position, so that's where gap between exit and entry comes from.

With small size of position I use in real trading compared to market liquidity and backtest settings to always use worst price of 1 second bar for Buy, Short, Sell and Close, I don't need volume restriction to be applied on top of it.

I can change value in settings to 0 to make it work as I intend, but I would preferably apply this setting through code, so that I can send script to my friend and it would generate the same results for him, is it possible to do? I checked SetOption statements, but couldn't find one which would do it.


Save to project file (*.apx file extension) then you can send whole analysis project saving all analysis settings plus applied AFL.