Thank you very much mradtke,
As I didn't quite understand your answer, I asked Perplexity adding the question I asked and your answer and asking him to explain it better and with numbers.
This is his answer and I think I understood it (thanks mainly to you who bothered to give me an answer and then to the AI that expanded it):
"Certainly, I'll explain the difference between "backtestRegular" and "backtestRegularRaw" , with visual examples:
- backtestRegular:
- Removes redundant entry signals.
- Once a position is opened, it ignores new entry signals until there's an exit signal.
- backtestRegularRaw:
- Does not remove redundant entry signals.
- Considers all entry signals, even if a position is already open.
Visual example:
Let's imagine a price chart with the following signals:
Day 1: Buy signal (Price: $100)
Day 2: Buy signal (Price: $102)
Day 3: Buy signal (Price: $103)
Day 4: Sell signal (Price: $105)
Day 5: Buy signal (Price: $104)
With backtestRegular:
Day 1: Buy at $100
Day 2: Ignore (position already open)
Day 3: Ignore (position already open)
Day 4: Sell at $105
Day 5: Buy at $104
With backtestRegularRaw:
Day 1: Buy at $100
Day 2: Record signal (but don't buy more as position is open)
Day 3: Record signal (but don't buy more as position is open)
Day 4: Sell at $105
Day 5: Buy at $104
The key difference is that backtestRegularRaw records all signals, which can be useful for:
- Post-analysis of signal frequency.
- Systems using limit or conditional orders.
- Strategies that want to "remember" missed signals for future decisions.
Practical example with limit orders:
Suppose your system generates a buy signal, but you only want to buy if the price drops 2% from the signal:
With backtestRegular:
- Day 1: Buy signal at $100, places limit order at $98
- Days 2-5: Ignores new buy signals
- Day 6: Price touches $98, buys
With backtestRegularRaw:
- Day 1: Buy signal at $100, places limit order at $98
- Day 2: New signal at $102, updates limit order to $99.96
- Day 3: New signal at $103, updates limit order to $100.94
- Day 4: Price touches $100.94, buys
In this case, backtestRegularRaw allows for more flexible market entry, adapting to new signals and market conditions.
This explanation should provide a clearer understanding of the differences between these backtest modes, even when dealing with a single symbol.
Citations:
[1] Portfolio-level back testing
[2] AFL Function Reference - SETBACKTESTMODE
[3] Different backtest modes
Is it correct?