[Backtesting] Position ClosePrice calculation for Minute Bar data

[Backtesting] Position ClosePrice calculation for Minute Bar data
15 Jan 2025, 14:55
Hi,
This post is not reporting any misbehaviour, it is just a genuine question regarding what is happening “under the hood” on the backtesting engine.
I have been backtesting a few algos that I had running live. Naturally, since I was backtesting using M1 Bars from Server the close prices when positions hit SL or TP are not the same as live trades because the granularity of the ticks is not the same (live is actual ticks and backtest is an approximation with minute bars).
I would like to know the method used by the backtesting engine to determine the close price when a position hits the SL or TP when running the algo using M1 Bars from Server.
I have 4 examples, assuming a Buy Position with SL:
[1 - Open is above SL and Low is below SL]
SL = 1.12
Next Tick is a Minute Bar with:
Open = 1.13
High = 1.17
Low = 1.10
Close = 1.15
In this example, the SL is below the Open (so not hit) but above the Low (so hit). How would the engine get the position close price? Will it be the low price? Will it be the SL price? Will it be any average?
[ 2 - Open is below SL and Close is above SL]
Similar example, but now, maybe due to price slippage over weekend, the new tick opens below the SL. Will the position close price be the Open? Will it be the SL? Any average?
[ 3 - Close is below SL and High is above SL ]
Similar example, but now, again maybe due to price slippage over weekend, the new tick closes below the SL but goes High above it. Which will be the position closing price?
[ 4 - High is below SL ]
Similar example, but now, again maybe due to price slippage over weekend, the new tick closes below the SL and High goes below it as well. Which will be the position closing price?
These are my 4 questions, I assume the same logic is used for TP but in reverse and for sell positions but in reverse.
Thanks in advance,
Vicente