Pine Script v5 · Strategy
CCI Level Zone
A Pine Script v5 strategy built on CCI (ohlc4, 1000), SMA (cci, 200) and RSI (close, 9). 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 commits 100 in cash and pays 0.1 commission. 22 settings; defaults include len 200, level_CCI_ZON 30 and len RSI Long 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 Level Zone 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 Level Zone 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 date window, which can leave this period out. It closed no trades on the other markets either. A backtest, not investment advice.
- Does CCI Level Zone run in Pine Script v6?
- Not tested
- Neither version placed a trade on any of the 8 markets, so there was nothing to compare. The v6 version is shown for reference and is not offered as a download.
- Does CCI Level Zone use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does CCI Level Zone run in Zeal Terminal?
- Yes
- It compiles in 51 ms and runs 1,000 bars in 118 ms, in the browser.
BTCUSDT · 1D · default settings
- line cci
- line level
- line level
- line level
- line level
- line level
- line level
- line level
- 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, $100 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.
-
Likely bug
ta.crossunder(sto, 65) ignores the settings line 80
Line 80 hard-codes 65 where line 48 uses “cross B”. Changing those settings moves one band but not this one.
ta.crossunder(sto, 65)ta.crossunder(sto, level_RSI_LongB) -
Likely bug
ta.crossover(sto, 20) ignores the settings line 62
Line 62 hard-codes 20 where line 49 uses “cross S”. Changing those settings moves one band but not this one.
ta.crossover(sto ,20)ta.crossover(sto, level_RSI_LongS) -
Check
No stop loss
Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.
-
Note
No slippage
Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.
-
Note
Uses an argument v6 removed
when = on line 88, 89, 92, 93. The upgraded version below moves each call inside an if block.
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 |
|---|---|---|---|
| use sma( cci , len ) | false | bool | zoneB_Long zoneB_Short line hma CCi |
| len | 200 | int | sma_CCi |
| Show win loss | true | bool | plotchar |
| <<<<[ Long ]>>>>> | |||
| Open Trad Long | true | bool | entry L close L line 87 |
| level_CCI_ZON | 30 | int · step 10 | zoneB_Long |
| len RSI Long | 9 | int | rsi_Long |
| cross B | 54 | int | Con_Long |
| cross S | 28 | int | Con_close_Long |
| invert | true | bool | line 47 |
| <<<<[ Short ]>>>>> | |||
| Open Trad Short | true | bool | entry S close S line 91 |
| level_CCI_ZON | -70 | int · step 10 | zoneB_Short |
| len RSI Long | 13 | int | rsi_Short |
| cross B | 51 | int | Con_Short |
| cross S | 39 | int | Con_close_Short |
| invert | false | bool | line 66 |
| Set Test Date | |||
| ═════ Date Range Filtering ═════ | false | bool | line 33 |
| From Year | 2020 | int · min 1900 | fromDate |
| From Month | 1 | int · min 1 · max 12 | fromDate |
| From Day | 15 | int · min 1 · max 31 | fromDate |
| To Year | 2023 | int · min 1900 | toDate |
| To Month | 12 | int · min 1 · max 12 | toDate |
| To Day | 31 | int · min 1 · max 31 | toDate |
What it calculates
- CCIohlc4, 1000
cci · line 36 - SMAcci, len (200)
sma_CCi · line 37 - RSIclose, len RSI Long (9)
rsi_Long · line 38 - RSIclose, len RSI Long (13)
rsi_Short · line 39 - Stochclose, high, low, 14
sto · line 40 - Crossover / Crossunderrsi_Long, cross S (28)
Con_close_Long · line 49 - Crossunder / Crossoverrsi_Short, cross S (39)
Con_close_Short · line 68
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 L long | f_tradeDateIsAllowed() and Open_Long | On “Open Trad Long” | 88 |
| Close L | Con_close_Long | On “Open Trad Long” | 89 |
| Open S short | f_tradeDateIsAllowed() and Con_Short | On “Open Trad Short” | 92 |
| Close S | Con_close_Short | On “Open Trad Short” | 93 |
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 timingOrders fill at the next bar's open, after the signal bar has closed.
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% | 0 | 0% | — | 0.0% | 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% | 0 | 0% | — | 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% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
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 Level Zone this page | — | v5 strategy | 0.0% | 0 | 0.0% |
| Suchit RSI CCI by SuchitRaju | cci sma rsi | v4 strategy | +11.4% | 68 | 54.7% |
| Momentum Explosion 2CCI RSI by capam | sma cci rsi | v4 strategy | +24.1% | 6 | 42.3% |
| AVWAP Strategy by asfbhero | rsi stoch sma | v5 strategy | does not run in Zeal Terminal | ||
| SRJ RSI Outperformer Strategy by Sapt_Jash | rsi sma | v5 strategy | +0.6% | 8 | 2.4% |
| RSI SMA Crossover Strategy by reees | rsi sma | v5 strategy | +39.8% | 42 | 30.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.
- 4 strategy calls use the when = argument (line 88, 89, 92, 93). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
- No v6-only features. v6 is not needed to run this script.
Clean v5
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 88: when = f_tradeDateIsAllowed() and Open_Long → if block
- Line 89: when = Con_close_Long → if block
- Line 92: when = f_tradeDateIsAllowed() and Con_Short → if block
- Line 93: when = Con_close_Short → if block
⋯if trad_Long- strategy.entry('L' ,strategy.long , when =f_tradeDateIsAllowed() and Open_Long , alert_message = textAlert_Long )+ if f_tradeDateIsAllowed() and Open_Long+ strategy.entry('L' ,strategy.long , alert_message = textAlert_Long )- strategy.close('L' ,when = Con_close_Long , alert_message = textAlert_Long)+ if Con_close_Long+ strategy.close('L' , alert_message = textAlert_Long) if trad_Short- strategy.entry('S', strategy.short,when =f_tradeDateIsAllowed() and Con_Short , alert_message = textAlert_Short)+ if f_tradeDateIsAllowed() and Con_Short+ strategy.entry('S', strategy.short , alert_message = textAlert_Short)- strategy.close('S' ,when = Con_close_Short , alert_message = textAlert_Close_Short )+ if Con_close_Short+ strategy.close('S' , alert_message = textAlert_Close_Short )plot(cci , 'line cci', color = zoneB_Short ? color.purple : zoneB_Long ? color.green : color.new(color.gray, 50))⋯Does it run in Pine Script v6?
Not tested
Neither version placed a trade on any of the 8 markets, so there was nothing to compare. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © Naruephat-//@version=5+//@version=6strategy("CCI Level Zone", overlay= false ,pyramiding = 0, default_qty_type = strategy.cash,initial_capital = 100, default_qty_value =100 , commission_value=0.1)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 51 ms | Yes 1,000 bars in 118 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/// © Naruephat//@version=5strategy("CCI Level Zone", overlay= false ,pyramiding = 0, default_qty_type = strategy.cash,initial_capital = 100, default_qty_value =100 , commission_value=0.1)use_sma = input.bool( false , 'use sma( cci , len ) ' ,inline = 'u' )len_sma = input.int( 200 , 'len' ,inline = 'u' )GL = '<<<<[ Long ]>>>>>'trad_Long = input.bool(true , 'Open Trad Long' ,inline = 'T' , group = GL)level_CCI_ZON_L = input.int(30 , 'level_CCI_ZON' , step = 10,inline = 'CR', group = GL)len_RSI_L = input.int(9 , 'len RSI Long' ,inline = 'CR', group = GL)level_RSI_LongB = input.int(54 , 'cross B' ,inline = 'L', group = GL)level_RSI_LongS = input.int(28 , 'cross S' ,inline = 'L', group = GL)cross_invert_L = input.bool(true , 'invert' , inline = 'L' , group = GL)GS = '<<<<[ Short ]>>>>>'trad_Short = input.bool(true , 'Open Trad Short' ,inline = 'T' , group = GS)level_CCI_ZON_S = input.int(-70 , 'level_CCI_ZON' , step = 10,inline = 'CR', group = GS)len_RSI_S = input.int(13 , 'len RSI Long',inline = 'CR', group = GS)level_RSI_ShortB = input.int(51 , 'cross B' , inline = 'S' , group = GS)level_RSI_ShortS = input.int(39 , 'cross S' , inline = 'S' , group = GS)cross_invert_S = input.bool(false , 'invert' , inline = 'S' , group = GS)/////////////////////////////////////////////////////////[ Set Test Date ]///////////////////////////////////////////////////////////////////////////////////////////////////// G0 = 'Set Test Date'i_dateFilter = input.bool(false, "═════ Date Range Filtering ═════" ,group = G0)i_fromYear = input.int(2020, "From Year ", minval = 1900 ,inline = 'd1',group = G0)i_fromMonth = input.int(1, "From Month", minval = 1, maxval = 12,inline = 'd2',group = G0)i_fromDay = input.int(15, "From Day ", minval = 1, maxval = 31,inline = 'd3',group = G0)i_toYear = input.int(2023, "To Year ", minval = 1900,inline = 'd1',group = G0)i_toMonth = input.int(12, "To Month", minval = 1, maxval = 12,inline = 'd2',group = G0)i_toDay = input.int(31, "To Day ", minval = 1, maxval = 31,inline = 'd3',group = G0)fromDate = timestamp(i_fromYear, i_fromMonth, i_fromDay, 00, 00)toDate = time < timestamp(i_toYear, i_toMonth, i_toDay, 23, 59) ? time : timestamp(i_toYear, i_toMonth, i_toDay, 23, 59)// เอา f_tradeDateIsAllowed() ไปใช้f_tradeDateIsAllowed() => not i_dateFilter or (time >= fromDate and time <= toDate)Win_Loss_Show = input.bool(true,'Show win loss', inline = 's')// indicator cci = ta.cci(ohlc4 , 1000)sma_CCi = ta.sma(cci,len_sma)rsi_Long = ta.rsi(close,len_RSI_L)rsi_Short = ta.rsi(close,len_RSI_S)sto = ta.stoch(close, high, low, 14)// condition zonezoneB_Long = cci > level_CCI_ZON_L and ( use_sma ? cci > sma_CCi : true ) zoneB_Short = cci < level_CCI_ZON_S and ( use_sma ? cci < sma_CCi : true ) /////////////////////////////////////////////////[ condition Long ]/////////////////////////////////////////////////Con_Long = falseCon_close_Long = falseif cross_invert_L Con_Long := zoneB_Long and ta.crossunder(rsi_Long , level_RSI_LongB) Con_close_Long := ta.crossover(rsi_Long , level_RSI_LongS)else Con_Long := zoneB_Long and ta.crossover(rsi_Long , level_RSI_LongB) Con_close_Long := ta.crossunder(rsi_Long , level_RSI_LongS) // If conditions pass, remember this first. Find the opportunity to open the next order with stoch.var con_L_perss = 0if Con_Long and con_L_perss == 0 con_L_perss := 1// clear con_L_perssif strategy.position_avg_price != 0 or Con_close_Long con_L_perss := 0 // END Condition LongOpen_Long = con_L_perss == 1 and ta.crossover(sto ,20)/////////////////////////////////////////////////[ condition Short ]/////////////////////////////////////////////////Con_Short = falseCon_close_Short = falseif cross_invert_S Con_Short := zoneB_Short and ta.crossover(rsi_Short , level_RSI_ShortB) Con_close_Short := ta.crossunder(rsi_Short , level_RSI_ShortS)else Con_Short := zoneB_Short and ta.crossunder(rsi_Short , level_RSI_ShortB) Con_close_Short := ta.crossover(rsi_Short , level_RSI_ShortS)// If conditions pass, remember this first. Find the opportunity to open the next order with stoch.var con_S_perss = 0if Con_Short and con_S_perss == 0 con_S_perss := 1// clear con_S_perssif strategy.position_avg_price != 0 or Con_close_Short con_S_perss := 0 // END ConditionOpen_Short = con_S_perss == 1 and ta.crossunder(sto, 65)///////////////////////////////////////////////////////////////////////////////////////////////[ // this chang Alert message for utextAlert_Long = 'textAlert Long 'textAlert_close_Long = 'textAlert Close Long 'textAlert_Short = 'textAlert_Short'textAlert_Close_Short = 'textAlert_Close_Short'if trad_Long strategy.entry('L' ,strategy.long , when =f_tradeDateIsAllowed() and Open_Long , alert_message = textAlert_Long ) strategy.close('L' ,when = Con_close_Long , alert_message = textAlert_Long) if trad_Short strategy.entry('S', strategy.short,when =f_tradeDateIsAllowed() and Con_Short , alert_message = textAlert_Short) strategy.close('S' ,when = Con_close_Short , alert_message = textAlert_Close_Short )plot(cci , 'line cci', color = zoneB_Short ? color.purple : zoneB_Long ? color.green : color.new(color.gray, 50))plot(use_sma ? sma_CCi : na, 'line hma CCi ', color = zoneB_Short ? color.purple : zoneB_Long ? color.green : color.new(color.gray, 50))hline(350 ,'line level' , linestyle = hline.style_dotted ,color = color.new(color.green , 65 ))hline(200 ,'line level' , linestyle = hline.style_dotted ,color = color.new(color.green , 65 ))hline(100 ,'line level' , linestyle = hline.style_dotted ,color = color.new(color.green , 65 ))hline(0 ,'line level' , linestyle = hline.style_dotted ,color = color.new(color.white , 50 ))hline(-350 ,'line level' , linestyle = hline.style_dotted ,color = color.new(color.red ,65 ))hline(-200 ,'line level' , linestyle = hline.style_dotted ,color = color.new(color.red ,65 ))hline(-100 ,'line level' , linestyle = hline.style_dotted ,color = color.new(color.red ,65 ))/////////////////////////////////////////////////////////[ Plot ]///////////////////////////////////////////////////////////////////////////////////////////////////// var buy= 0. var sell = 0. if(ta.change(strategy.position_size) and strategy.position_size == 0) buy := nz(strategy.closedtrades.entry_price(strategy.closedtrades-1)) sell := nz(strategy.closedtrades.exit_price(strategy.closedtrades-1))var buy_SELL = 2buy_SELL := strategy.position_size > 0 ? 0 : strategy.position_size < 0 ? 1 : 2//plot(buy_SELL[1])plotchar( Win_Loss_Show ? nz(buy_SELL[1]) == 1 and ta.change(strategy.position_size) and strategy.position_size == 0 and buy > sell : na ,location = location.top ,color = color.new(color.green, 0), char='☺' , size = size.small) plotchar( Win_Loss_Show ? nz(buy_SELL[1]) == 1 and ta.change(strategy.position_size) and strategy.position_size == 0 and buy < sell : na ,location = location.top , color = color.new(color.red, 0), char='☹' , size = size.tiny) plotchar( Win_Loss_Show ? nz(buy_SELL[1]) ==0 and ta.change(strategy.position_size) and strategy.position_size == 0 and buy < sell : na ,location = location.top ,color = color.new(color.green, 0), char='☺' , size = size.small) plotchar( Win_Loss_Show ? nz(buy_SELL[1]) ==0 and ta.change(strategy.position_size) and strategy.position_size == 0 and buy > sell : na ,location = location.top , color = color.new(color.red, 0), char='☹' , size = size.tiny)