Why this is trending now
Markets are not behaving the same all the time:
- Some periods → slow, sideways, low volatility
- Other periods → fast, explosive, high volatility Most strategies fail because they use the same rules in all conditions
So traders are now building strategies that:
- detect the current market regime
- switch behavior dynamically
This is becoming a big trend in Pine Script strategies
Strategy Idea
Instead of one fixed logic, this uses two modes:
Low Volatility Mode (Range Behavior)
- Market is quiet
- Trade small reversals
- Avoid breakouts
High Volatility Mode (Trend Behavior)
- Market is active
- Trade breakouts
- follow momentum
How It Works
Measure volatility using ATR
Compare current ATR with its average
Decide:
- Low volatility → mean reversion
- High volatility → breakout trading
Pine Script v6 Strategy Code
//@version=6
strategy("Adaptive Risk Regime Strategy", overlay=true, initial_capital=100000, default_qty_type=strategy.percent_of_equity, default_qty_value=5)
// ───── INPUTS ─────
atrLen = input.int(14, "ATR Length")
lookback = input.int(50, "Volatility Lookback")
rangeLen = input.int(20, "Range Length")
rr = input.float(2.0, "Risk Reward")
atrMult = input.float(1.5, "ATR Stop Multiplier")
// ───── VOLATILITY REGIME ─────
atrVal = ta.atr(atrLen)
atrAvg = ta.sma(atrVal, lookback)
highVol = atrVal > atrAvg
lowVol = atrVal < atrAvg
// ───── RANGE LEVELS ─────
rangeHigh = ta.highest(high, rangeLen)
rangeLow = ta.lowest(low, rangeLen)
// ───── GLOBAL CROSS (fix warnings too) ─────
crossUp = ta.crossover(close, rangeHigh[1])
crossDown = ta.crossunder(close, rangeLow[1])
// ───── LOGIC ─────
// Low volatility → mean reversion
longRange = lowVol and close < rangeLow[1]
shortRange = lowVol and close > rangeHigh[1]
// High volatility → breakout
longBreak = highVol and crossUp
shortBreak = highVol and crossDown
longCondition = longRange or longBreak
shortCondition = shortRange or shortBreak
// ───── ENTRIES ─────
if longCondition and strategy.position_size == 0
strategy.entry("Long", strategy.long)
if shortCondition and strategy.position_size == 0
strategy.entry("Short", strategy.short)
// ───── RISK MANAGEMENT ─────
longStop = strategy.position_avg_price - atrVal * atrMult
longTarget = strategy.position_avg_price + atrVal * atrMult * rr
shortStop = strategy.position_avg_price + atrVal * atrMult
shortTarget = strategy.position_avg_price - atrVal * atrMult * rr
strategy.exit("Exit Long", from_entry="Long", stop=longStop, limit=longTarget)
strategy.exit("Exit Short", from_entry="Short", stop=shortStop, limit=shortTarget)
// ───── VISUALS ─────
plot(rangeHigh, color=color.green, title="Range High")
plot(rangeLow, color=color.red, title="Range Low")
Top comments (0)