strategy · own pane · open source

CCI Mean Reversion

Deepwick · @deepwickv1Updated 2 Oct 2026▲ 0 users
Running…
Loading chart…

About

CCI mean reversion long-only: enter when CCI drops below the oversold threshold (default -100), exit when it climbs above the overbought threshold (default +100).

  • Tighter thresholds (-150 / +150) catch only the most extreme swings.
  • Combine with an ADX < 20 filter to confirm ranging conditions.
  • 20-period CCI is the canonical setting; shorter reacts faster.

Source code

//@version=5
strategy("CCI Mean Reversion", overlay=false, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.05)
len = input.int(20, "CCI Length", minval=5, maxval=100, step=1)
oversold = input.int(-100, "Oversold", minval=-300, maxval=-50, step=5)
overbought = input.int(100, "Overbought", minval=50, maxval=300, step=5)
stopPct = input.float(2, "Stop Loss %", minval=0.5, maxval=10, step=0.1)
tpPct = input.float(6, "Take Profit %", minval=0, maxval=20, step=0.1)
c = ta.cci(close, len)
longSignal = strategy.position_size == 0 and c < oversold
exitSignal = strategy.position_size > 0 and c > overbought
if longSignal
    strategy.entry("Long", strategy.long)
if strategy.position_size > 0
    strategy.exit("Risk", stop=stopPct > 0 ? strategy.position_avg_price * (1 - stopPct / 100) : na, limit=tpPct > 0 ? strategy.position_avg_price * (1 + tpPct / 100) : na)
if exitSignal
    strategy.close("Long", comment="CCI exit")
hline(100, "Overbought", color=color.gray, linestyle=hline.style_dashed)
hline(-100, "Oversold", color=color.gray, linestyle=hline.style_dashed)
hline(0, "Zero", color=color.gray, linestyle=hline.style_dotted)
p_CCI = plot(c, "CCI", color=color.teal, linewidth=2)
plotshape(longSignal, "Long", style=shape.triangleup, location=location.belowbar, color=color.green, text="L")
plotshape(exitSignal, "Exit", style=shape.triangledown, location=location.abovebar, color=color.red, text="X")
alertcondition(longSignal, "CCI long entry", "CCI dropped below oversold")
alertcondition(exitSignal, "CCI exit", "CCI climbed above overbought")

Comments

No comments yet.

Sign in to comment.