Hi all,
I'm running a custom loop-based backtester (not using ApplyStop) for a breakout strategy on 15-minute bars. My data source is 1-minute bars.
When a breakout entry and its stoploss are both within the same bar's range, my AFL exits immediately (same-candle SL exit). For example, for a long entry:
if(H[k] > entryLevel) // entry triggers
{
Buy[k] = 1;
BuyPrice[k] = entryLevel;
stoploss = entryLevel - entryLevel * 0.004; // 0.4% SL
if(L[k] <= stoploss) // same-candle SL check
{
Sell[k] = 1;
SellPrice[k] = stoploss;
}
}
I verified using bar replay at 1-minute resolution that in many cases, the bar's Low was established early in the bar (before price rallied to trigger the entry). The entry only happened after the Low was made, so the SL was never actually hit. The trade stayed open through that bar in bar replay and the SL was hit on the next bar instead.
My workaround:
I added an Open-based check. If the bar opened below the entry price, the price had to rally upward to trigger entry, which means the Low was likely formed before the entry. So I skip the same-candle SL in that case:
// Only apply same-candle SL if Open confirms entry could have happened before the Low
if(L[k] <= stoploss AND (O[k] >= buyPriceVal))
{
Sell[k] = 1;
SellPrice[k] = stoploss;
}
For short entries, the mirror: skip same-candle SL if O[k] > shortPriceVal.
My questions:
- Is the Open-based heuristic a reasonable approach, or are there edge cases I'm not considering?
- Has anyone used
TimeFrameSet(in1Minute)inside a custom loop to check the actual intra-bar sequence (which 1-min bar made the Low vs which triggered the entry)? Would that be more accurate than the Open heuristic? - Any other approaches people have used for this same-bar ambiguity in custom loop backtesters?
Thanks in advance.