I’m developing a strategy that imports numerical values (1, -1, or 0) from a separate indicator to represent market regimes (e.g., Bullish, Bearish, Neutral).
These values are then converted to boolean flags in my strategy.
So basically indicator plot export, –> to source imports in strategy.
However, I’m struggling to achieve accurate deep back testing. The regime flags seem not to reflect the actual historical state throughout the back test. As if the deep / backtester takes the strategy back but not the indicator values.
I am not sure what I am doing wrong or if it is possible at all to use, and back test with indicator on strategy?
I’ve attempted to address this using barstate.ishistory to update the flags only when back testing historical data, but the issue persists.
This is the code from the export indicator:
indicator("Regime Signal Exporter", overlay=true)
// Example conditions for regime detection
bool bullishCondition = close > open[1]
bool bearishCondition = close < open[1]
// Regime flags
var bool isBullish = false
var bool isBearish = false
// Update regime flags based on conditions (mutual exclusivity)
if bullishCondition
isBullish := true
isBearish := false
else
isBullish := false
if bearishCondition
isBearish := true
isBullish := false
else
isBearish := false
// Numerical values for export
exportBullRegime = isBullish ? 1 : 0
exportBearRegime = isBearish ? -1 : 0
plot(exportBullRegime, title="Mr. Bull", style=plot.style_line, display=display.none)
plot(exportBearRegime, title="Mr. Bear", style=plot.style_line, display=display.none)
And here is how I import in into the strategy:
strategy("Regime imports", overlay=true)
// Input source
imported_BullRegime = input.source(title="Mr. Bull", group="Market Regime Imports", defval=close)
imported_BearRegime = input.source(title="Mr. Bear", group="Market Regime Imports", defval=close)
// Market Regime Variables
bool isBull = false
bool isBear = false
if barstate.ishistory
if imported_BullRegime == 1
isBull := true
isBear := false
else if imported_BearRegime == -1
isBear := true
isBull := false
else // Neither regime is active, reset the flags
isBull := false
isBear := false
Thank you for your time and help !
Pokeas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.