strategy · own pane · open source
CCI mean reversion strategy (CCI 20, −100 / +100)
CCI(20) mean reversion strategy: buy when CCI drops below −100, exit when it climbs above +100. Plain-English rules, copyable code and a costed backtest. Deepwick Script runs a subset of Pine Script.
What the CCI Mean Reversion strategy does
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.
Entry and exit rules
Language reference: Deepwick Script.
Default inputs
| Input | Default | Min | Max |
|---|---|---|---|
CCI Length | 20 | 5 | 100 |
Oversold | -100 | -300 | -50 |
Overbought | 100 | 50 | 300 |
Stop Loss % | 2 | 0.5 | 10 |
Take Profit % | 6 | 0 | 20 |
How Deepwick fills this strategy
- Market orders fill at the next bar's open.
- Stops and limits follow the bar's path: open → nearer extreme → farther extreme → close.
- Gaps fill at the open.
- Commission is charged on every fill, and slippage applies to market and stop fills, as set in
strategy().
Source code
Deepwick Script, a subset of Pine Script · read-only
//@version=6
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)
colorMid2 = input.color("color.teal", "Color Mid2")
colorUp = input.color("color.green", "Color Up")
colorDown = input.color("color.red", "Color Down")
colorNeutral = input.color("color.gray", "Color Neutral")
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=colorNeutral, linestyle=hline.style_dashed)
hline(-100, "Oversold", color=colorNeutral, linestyle=hline.style_dashed)
hline(0, "Zero", color=colorNeutral, linestyle=hline.style_dotted)
p_CCI = plot(c, "CCI", color=colorMid2, linewidth=2)
plotshape(longSignal, "Long", style=shape.triangleup, location=location.belowbar, color=colorUp, text="L")
plotshape(exitSignal, "Exit", style=shape.triangledown, location=location.abovebar, color=colorDown, text="X")
alertcondition(longSignal, "CCI long entry", "CCI dropped below oversold")
alertcondition(exitSignal, "CCI exit", "CCI climbed above overbought")
Run it in Deepwick
- Open a chart of any crypto pair or CFD.
- Click “Scripts” and add this strategy.
- Press Run and read the trades in the Strategy Tester.
FAQ
Does it use close or typical price?
It computes CCI on close. The classic CCI uses the typical price (hlc3); change the source to hlc3 to test that version.
Why exit at +100 and not at 0?
Waiting for +100 lets a rebound run further, but many trades will end at the 6% target or 2% stop first. Testing an exit at 0 is a one-line change.
Is CCI a trend or a mean-reversion indicator?
Both uses exist: breakouts above +100 for trend, extremes below −100 for reversals. This page tests the reversal reading.
No comments yet.
Sign in to comment.