Pine Script v5 · Strategy
CCI + EMA with RSI Cross Strategy
A Pine Script v5 strategy built on EMA (close, 9), RMA or Change (9) and SMA (hlc3, 20). It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. Each trade is one contract and pays no commission. 11 settings; defaults include Fast EMA Length 9, Slow EMA Length 20 and Fast RSI Length 9.
Generated from the script's code by a template: every clause is a fact read from the source. Not written by a person or a model, and not taken from the author's description.
- Does CCI + EMA with RSI Cross Strategy repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
- How did CCI + EMA with RSI Cross Strategy do on BTCUSDT 1D with default settings?
- Not measured
- It closed no trades there from 26 Jan 2024 to 21 Oct 2026 with the default settings, so there is no result to report. Its code limits trading to a session window, which can leave these candles out. On ETHUSDT 4h it did trade; that row of the markets table below has its figures. A backtest, not investment advice.
- Does CCI + EMA with RSI Cross Strategy run in Pine Script v6?
- No
- The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 14 before, 0 after on ETHUSDT 4h, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download.
- Does CCI + EMA with RSI Cross Strategy use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does CCI + EMA with RSI Cross Strategy run in Zeal Terminal?
- Yes
- It compiles in 22 ms and runs 1,000 bars in 58 ms, in the browser.
BTCUSDT · 1D · default settings
- FastEMA
- SlowEMA
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- 0.00%
- $0.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 0
- 0 won · 0 lost
- Profitable
- 0.0%
- of closed trades
- Profit factor
- —
- gross profit ÷ gross loss
- Max drawdown
- 0.00%
- $0.00
One run with the author's default settings, $1,000,000 starting capital, commission as the script sets it. A single backtest says little about future results and is not a recommendation. Backtests are simulations on historical data and are not investment advice.
Review
What a careful reader of this script would point out, found by checking the source and the backtest.
-
Check
No stop loss
Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.
-
Check
No commission
The backtest assumes free trading. Results on any real exchange will be lower.
-
Note
No slippage
Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.
Settings
Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| EMA Settings | |||
| Fast EMA Length | 9 | int | fastEMA |
| Slow EMA Length | 20 | int | slowEMA |
| RSI Settings | |||
| Fast RSI Length | 9 | int · min 1 | up1 down1 |
| Fast RSI Source | close | source | up1 down1 |
| Slow RSI Length | 20 | int · min 1 | up2 down2 |
| Slow RSI Source | close | source | up2 down2 |
| CCI Settings | |||
| CCI Length | 20 | int · min 1 | ma cci |
| CCI Source | hlc3 | source | ma cci |
| CCI Cutoff | 50 | int | cciBull cciBear |
| Stop Settings | |||
| Trail Loss ($) | 0.67 | float · min 0.0 · step 0.01 | longStop shortStop stopValue |
| Session Settings | |||
| Session | 0930-1545 | session | session |
What it calculates
- EMAclose, Fast EMA Length (9)
fastEMA · line 8 - EMAclose, Slow EMA Length (20)
slowEMA · line 9 - RMA / Changemath.max(ta.change(rsiSource1Input), 0), Fast RSI Length (9)
up1 · line 23 - RMA / Change-math.min(ta.change(rsiSource1Input), 0), Fast RSI Length (9)
down1 · line 24 - RMA / Changemath.max(ta.change(rsiSource2Input), 0), Slow RSI Length (20)
up2 · line 26 - RMA / Change-math.min(ta.change(rsiSource2Input), 0), Slow RSI Length (20)
down2 · line 27 - SMACCI Source (hlc3), CCI Length (20)
ma · line 34 - DEVCCI Source (hlc3), CCI Length (20)
cci · line 35
Signal flow
How price data and settings reach the orders. Each box is a name in the script, or several computed the same way; each arrow is a value one of them reads. Hover a box for its members.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Long long | (longCondition) | On | 64 |
| Close Long | (longExit) | On | 70 |
| Open Short short | (shortCondition) | On | 75 |
| Close Short | (shortExit) | On | 80 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Does it repaint?
No
No repainting patterns in the source.
- ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
- ClearFuture-bar referencesNo negative history offsets such as close[-1].
- ClearIntrabar recalculationNo varip, calc_on_every_tick or realtime-only state. Orders are decided once per closed bar.
- ClearOrder timingprocess_orders_on_close = true: orders fill at the signal bar's close.
The checks read the source; the replay runs it. Together they catch the common causes, not every possible one.
Other markets
The same script with default settings on 8 Binance markets. Each row is a separate backtest over the most recent 1,000 bars.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | 0.0% | +102.5% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | 0.0% | +5.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | 0.0% | +9.8% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −0.0% | +8.4% | 14 | 43% | 0.97 | 0.7% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | 0.0% | +16.7% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.0% | +21.5% | 9 | 56% | 1.75 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | 0.0% | +148.3% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +0.0% | +17.1% | 9 | 44% | 1.49 | 0.1% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
Settings heatmap
Two settings that feed the entry signal, moved around their defaults. The best in-sample pair (Slow EMA Length 10, CCI Length 10) made 0.0% before 26 Dec 2025 and 0.0% after it, against 0.0% for the defaults. 0% of the 64 combinations made money in-sample and 0% out-of-sample.
| CCI Length ↓ · Slow EMA Length → | 10 | 12 | 14 | 17 | 20 | 24 | 28 | 34 |
|---|---|---|---|---|---|---|---|---|
| 10 | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% |
| 12 | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% |
| 14 | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% |
| 17 | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% |
| 20 | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% |
| 24 | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% |
| 28 | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% |
| 34 | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% |
| CCI Length ↓ · Slow EMA Length → | 10 | 12 | 14 | 17 | 20 | 24 | 28 | 34 |
|---|---|---|---|---|---|---|---|---|
| 10 | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% |
| 12 | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% |
| 14 | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% |
| 17 | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% |
| 20 | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% |
| 24 | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% |
| 28 | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% |
| 34 | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% |
Net P&L of trades opened in each period, as a share of starting capital. marks the defaults and the best in-sample cell. Hover a cell for its trade count. Backtests are simulations on historical data and are not investment advice.
Similar scripts
Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| CCI + EMA with RSI Cross Strategy this page | — | v5 strategy | 0.0% | 0 | 0.0% |
| Optimized Keltner Channels SL-TP Strategy for BTC by chanu_lev10k | sma ema rma | v4 strategy | −19.4% | 36 | 70.0% |
| CCI & EMA strategy by Tradeswithashish by tradeswithashish | ema sma dev | v5 strategy | +0.1% | 16 | 0.4% |
| Soheil PKO's 5 min Hitman Scalp - 3MA + Laguerre RSI + ADX [Pt] by PtGambler | ema sma rma | v5 strategy | No trades on this market | ||
| EMA-ADX-VOL-CRYPTO KILLER [15M] by Babehdyo | rma sma ema | v4 strategy | +4.5% | 22 | 5.3% |
| Crypto rsi cci mf stoch rsi oscillators all in one strategy by SoftKill21 | rma sma dev | v4 strategy | +1.6% | 3 | 26.8% |
Upgrade and export
Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.
- 3 settings use the untyped input() (line 6, 7, 33). It still compiles in v6; input.int, input.float or input.source state the type.
- No v6-only features. v6 is not needed to run this script.
Same 14 trades and the same P&L on ETHUSDT 4h, 1,000 bars, in Zeal Terminal's engine.
- Line 6: input() → input.int()
- Line 7: input() → input.int()
- Line 33: input() → input.source()
⋯//EMA-fastLen = input(title='Fast EMA Length', defval=9, group='EMA Settings')+fastLen = input.int(title='Fast EMA Length', defval=9, group='EMA Settings')-slowLen = input(title='Slow EMA Length', defval=20, group='EMA Settings')+slowLen = input.int(title='Slow EMA Length', defval=20, group='EMA Settings')fastEMA = ta.ema(close, fastLen)⋯cciLength = input.int(title='CCI Length', group='CCI Settings', defval=20, minval=1)-src = input(hlc3, title='CCI Source', group='CCI Settings')+src = input.source(hlc3, title='CCI Source', group='CCI Settings')ma = ta.sma(src, cciLength)⋯Does it run in Pine Script v6?
No
The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 14 before, 0 after on ETHUSDT 4h, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © rwestbrookjr-//@version=5+//@version=6strategy("CCI + EMA with RSI Cross Strategy", overlay=true, margin_long=100, margin_short=100, process_orders_on_close=true)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 22 ms | Yes 1,000 bars in 58 ms | Not measured |
| PineTS | Not tested | Not tested | Not measured |
“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report.
Source
Copied verbatim from the author's published script, with its licence header intact. The author may have updated the original since this snapshot.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © rwestbrookjr//@version=5strategy("CCI + EMA with RSI Cross Strategy", overlay=true, margin_long=100, margin_short=100, process_orders_on_close=true)//EMAfastLen = input(title='Fast EMA Length', defval=9, group='EMA Settings')slowLen = input(title='Slow EMA Length', defval=20, group='EMA Settings')fastEMA = ta.ema(close, fastLen)slowEMA = ta.ema(close, slowLen)fema = plot(fastEMA, title='FastEMA', color=color.new(color.green, 0), linewidth=1, style=plot.style_line)sema = plot(slowEMA, title='SlowEMA', color=color.new(color.red, 0), linewidth=1, style=plot.style_line)fill(fema, sema, color=fastEMA > slowEMA ? color.new(#417505, 50) : color.new(#890101, 50), title='Cloud')// Bull and Bear Alerts//Bull = ta.crossover(fastEMA, slowEMA)Bull = fastEMA > slowEMA//Bear = ta.crossunder(fastEMA, slowEMA)Bear = fastEMA < slowEMA//RSIsrsiLength1Input = input.int(9, minval=1, title="Fast RSI Length", group="RSI Settings")rsiSource1Input = input.source(close, "Fast RSI Source", group="RSI Settings")rsiLength2Input = input.int(20, minval=1, title="Slow RSI Length", group="RSI Settings")rsiSource2Input = input.source(close, "Slow RSI Source", group="RSI Settings")up1 = ta.rma(math.max(ta.change(rsiSource1Input), 0), rsiLength1Input)down1 = ta.rma(-math.min(ta.change(rsiSource1Input), 0), rsiLength1Input)rsi = down1 == 0 ? 100 : up1 == 0 ? 0 : 100 - (100 / (1 + up1 / down1))up2 = ta.rma(math.max(ta.change(rsiSource2Input), 0), rsiLength2Input)down2 = ta.rma(-math.min(ta.change(rsiSource2Input), 0), rsiLength2Input)rsi2 = down2 == 0 ? 100 : up2 == 0 ? 0 : 100 - (100 / (1 + up2 / down2))rsiBull = rsi > rsi2 and rsi > rsi[1]rsiBear = rsi < rsi2 and rsi < rsi[1]//CCIcciLength = input.int(title='CCI Length', group='CCI Settings', defval=20, minval=1)src = input(hlc3, title='CCI Source', group='CCI Settings')ma = ta.sma(src, cciLength)cci = (src - ma) / (0.015 * ta.dev(src, cciLength))cciCut = input.int(title = 'CCI Cutoff', group='CCI Settings', defval = 50)cciBull = cci > cciCutcciBear = cci < cciCut * -1//Trail Stop Setuptrstp = input.float(title="Trail Loss ($)", group='Stop Settings', minval = 0.0, step = 0.01, defval = 0.67)longStop = 0.0, shortStop = 0.0longStop := if Bull or strategy.position_size > 0 stopValue = slowEMA - trstp math.max(stopValue, longStop[1])else 0.0shortStop := if Bear or strategy.position_size < 0 stopValue = slowEMA + trstp math.min(stopValue, shortStop[1])else 999999 plotshape(title='Short Stop', series=shortStop != 999999 and strategy.opentrades > 0 and strategy.position_size < 0 ? shortStop : na, style=shape.cross, color=color.yellow, location=location.absolute)plotshape(title='Long Stop', series=longStop != 0.0 and strategy.opentrades > 0 and strategy.position_size > 0 ? longStop : na,style=shape.cross, color=color.yellow, location=location.absolute)//Session Setupopen_session=input.session(title='Session',group='Session Settings', defval="0930-1545")session = time("1", open_session)validSession=(na(session) ? 0 : 1)//Trade Signals//longCondition = Bull and cci > cciCut and ta.crossover(rsi,rsi2) and validSessionlongCondition = cciBull and ta.crossover(rsi,rsi2) and close > slowEMA and validSession//longCondition = cciBull and ta.crossover(rsi,rsi2) and Bull and validSessionif (longCondition) strategy.entry("Long", strategy.long, 100) //longExit = close > strategy.opentrades.entry_price(0) + 1.5 or close < strategy.opentrades.entry_price(0) - 0.75longExit = close < longStop or not validSession//longExit = ta.crossunder(low,longStop) or not validSessionif (longExit) strategy.close("Long")//shortCondition = Bear and cci < (cciCut*-1) and ta.crossunder(rsi,rsi2) and validSessionshortCondition = cciBear and ta.crossunder(rsi,rsi2) and close < slowEMA and validSession//shortCondition = cciBear and ta.crossunder(rsi,rsi2) and Bear and validSessionif (shortCondition) strategy.entry("Short", strategy.short, 100)//shortExit = close < strategy.opentrades.entry_price(0) - 1.5 or close > strategy.opentrades.entry_price(0) + 0.75shortExit = close > shortStop or not validSession//shortExit = ta.crossover(high, shortStop) or not validSessionif (shortExit) strategy.close("Short")