Pine Script v4 · Strategy
CCI Strategy
A Pine Script v4 strategy built on SMA (close, 20), DEV (close, 20) and Crossover (cci, 0). It has 16 order rules, 6 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade commits 10000 in cash and pays no commission. 23 settings; defaults include CCI Length 20, Source close and CCI Simple Cross 0.
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 Strategy repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 31 of 31 trades.
- How did CCI Strategy do on BTCUSDT 1D with default settings?
- +62.07%
- From 26 Jan 2024 to 21 Oct 2026, over 103 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can CCI Strategy be converted to Pine Script v5?
- Yes
- The upgrade takes 1 step, from v4; each was run before and after on the same candles with identical results, and the v5 script can be downloaded below.
- Does CCI Strategy use a stop loss?
- Yes
- strategy.exit sets a stop on line 91, 93, 96, 98.
- Does CCI Strategy run in Zeal Terminal?
- Yes
- It compiles in 31 ms and runs 1,000 bars in 85 ms, in the browser.
BTCUSDT · 1D · default settings
- SMA
- DEV
- Crossover
- Crossunder
- Crossover
- Crossunder
- Crossunder
- Crossover
- Crossunder
- Crossover
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +62.07%
- $6,207.20
- Buy and hold
- +102.5%
- same period
- Closed trades
- 103
- 29 won · 74 lost
- Profitable
- 28.2%
- of closed trades
- Profit factor
- 1.33
- gross profit ÷ gross loss
- Max drawdown
- 44.44%
- −$5,603.27
One run with the author's default settings, $10,000 starting capital, commission as the script sets it. A short position was still open at the last bar. 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 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.
Upgrade and export
Written in Pine Script v4. The upgrade to v5 takes 1 step, one per version, each applied to the result of the one before. A last clean-v5 pass then types the settings and moves when = into if blocks, which v6 requires. Every step runs before and after on the same candles in Zeal Terminal's engine; a step whose results differ is shown but not offered as a download. Upgrades preserve behaviour: bugs are fixed in the Review, never silently here.
- Upgrading to v5 renames sma → ta.sma, dev → ta.dev, crossover → ta.crossover, crossunder → ta.crossunder.
v4 → v5
VerifiedSame 103 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 8: sma → ta.sma
- Line 9: dev → ta.dev
- Line 11: input(type = input.time) → input.time()
- Line 12: input(type = input.time) → input.time()
- Line 32: crossover → ta.crossover
9 more edits
- Line 33: crossunder → ta.crossunder
- Line 34: crossover → ta.crossover
- Line 35: crossunder → ta.crossunder
- Line 36: crossunder → ta.crossunder
- Line 37: crossover → ta.crossover
- Line 38: crossunder → ta.crossunder
- Line 39: crossover → ta.crossover
- Line 43: input(type = input.float) → input.float()
- Line 44: input(type = input.float) → input.float()
⋯// © REV0LUTI0N-//@version=4+//@version=5strategy(title="CCI Strategy", overlay=true, initial_capital = 10000, default_qty_value = 10000, default_qty_type = strategy.cash)⋯src = input(close, title="Source")-ma = sma(src, length)+ma = ta.sma(src, length)-cci = (src - ma) / (0.015 * dev(src, length))+cci = (src - ma) / (0.015 * ta.dev(src, length))// Strategy Backtesting-startDate = input(timestamp("2021-10-01T00:00:00"), type = input.time, title='Backtesting Start Date')+startDate = input.time(timestamp("2021-10-01T00:00:00"), title='Backtesting Start Date')-finishDate = input(timestamp("9999-12-31T00:00:00"), type = input.time, title='Backtesting End Date')+finishDate = input.time(timestamp("9999-12-31T00:00:00"), title='Backtesting End Date')time_cond = time >= startDate and time <= finishDate⋯//Strategy Settings - Crosses-simplecrossup = crossover(cci, ccisource)+simplecrossup = ta.crossover(cci, ccisource)-simplecrossdown = crossunder(cci, ccisource)+simplecrossdown = ta.crossunder(cci, ccisource)-uppercrossup = crossover(cci, upperbandsource)+uppercrossup = ta.crossover(cci, upperbandsource)-lowercrossdown = crossunder(cci, lowerbandsource)+lowercrossdown = ta.crossunder(cci, lowerbandsource)-uppercrossdown = crossunder(cci, upperbandexitsource)+uppercrossdown = ta.crossunder(cci, upperbandexitsource)-lowercrossup = crossover(cci, lowerbandexitsource)+lowercrossup = ta.crossover(cci, lowerbandexitsource)-upperstop = crossunder(cci, upperbandsource)+upperstop = ta.crossunder(cci, upperbandsource)-lowerstop = crossover(cci, lowerbandsource)+lowerstop = ta.crossover(cci, lowerbandsource)// Stop Loss & Take Profit % Based⋯enabletp = input(false, title='Enable Take Profit')-stopTick = input(5.0, title='Stop Loss %', type=input.float, step=0.1) / 100+stopTick = input.float(5.0, title='Stop Loss %', step=0.1) / 100-takeTick = input(10.0, title='Take Profit %', type=input.float, step=0.1) / 100+takeTick = input.float(10.0, title='Take Profit %', step=0.1) / 100longStop = strategy.position_avg_price * (1 - stopTick)⋯Same 103 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 6: input() → input.int()
- Line 7: input() → input.source()
- Line 15: input() → input.string()
- Line 16: input() → input.bool()
- Line 21: input() → input.bool()
- Line 22: input() → input.bool()
13 more edits
- Line 23: input() → input.bool()
- Line 24: input() → input.bool()
- Line 26: input() → input.int()
- Line 27: input() → input.int()
- Line 28: input() → input.int()
- Line 29: input() → input.int()
- Line 30: input() → input.int()
- Line 41: input() → input.bool()
- Line 42: input() → input.bool()
- Line 54: input() → input.string()
- Line 55: input() → input.string()
- Line 56: input() → input.string()
- Line 57: input() → input.string()
⋯//CCI Code-length = input(20, minval=1, title="CCI Length")+length = input.int(20, minval=1, title="CCI Length")-src = input(close, title="Source")+src = input.source(close, title="Source")ma = ta.sma(src, length)⋯//Time Restriction Settings-startendtime = input("", title='Time Frame To Enter Trades')+startendtime = input.string("", title='Time Frame To Enter Trades')-enableclose = input(false, title='Enable Close Trade At End Of Time Frame')+enableclose = input.bool(false, title='Enable Close Trade At End Of Time Frame')timetobuy = (time(timeframe.period, startendtime))⋯//Strategy Settings - Enable Check Boxes-enableentry = input(true, title="Enter First Trade ASAP")+enableentry = input.bool(true, title="Enter First Trade ASAP")-enableconfirmation = input(false, title="Wait For Cross To Enter First Trade")+enableconfirmation = input.bool(false, title="Wait For Cross To Enter First Trade")-enablezero =input(true, title="Use CCI Simple Cross Line For Entries & Exits")+enablezero =input.bool(true, title="Use CCI Simple Cross Line For Entries & Exits")-enablebands = input(false, title="Use Upper & Lower Bands For Entries & Exits")+enablebands = input.bool(false, title="Use Upper & Lower Bands For Entries & Exits")//Strategy Settings - Band Sources-ccisource = input(0, title="CCI Simple Cross")+ccisource = input.int(0, title="CCI Simple Cross")-upperbandsource =input(100, title="CCI Enter Long Band")+upperbandsource =input.int(100, title="CCI Enter Long Band")-upperbandexitsource =input(100, title="CCI Exit Long Band")+upperbandexitsource =input.int(100, title="CCI Exit Long Band")-lowerbandsource =input(-100, title="CCI Enter Short Band")+lowerbandsource =input.int(-100, title="CCI Enter Short Band")-lowerbandexitsource =input(-100, title="CCI Exit Short Band")+lowerbandexitsource =input.int(-100, title="CCI Exit Short Band")//Strategy Settings - Crosses⋯// Stop Loss & Take Profit % Based-enablesl = input(false, title='Enable Stop Loss')+enablesl = input.bool(false, title='Enable Stop Loss')-enabletp = input(false, title='Enable Take Profit')+enabletp = input.bool(false, title='Enable Take Profit')stopTick = input.float(5.0, title='Stop Loss %', step=0.1) / 100⋯// Alert messages-message_enterlong = input("", title="Long Entry message")+message_enterlong = input.string("", title="Long Entry message")-message_entershort = input("", title="Short Entry message")+message_entershort = input.string("", title="Short Entry message")-message_closelong = input("", title="Close Long message")+message_closelong = input.string("", title="Close Long message")-message_closeshort = input("", title="Close Short message")+message_closeshort = input.string("", title="Close Short message") ⋯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: 103 before, 6 after on BTCUSDT 1D, 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.
⋯// © REV0LUTI0N-//@version=5+//@version=6strategy(title="CCI Strategy", overlay=true, initial_capital = 10000, default_qty_value = 10000, default_qty_type = strategy.cash)⋯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 |
|---|---|---|---|
| CCI Length | 20 | int · min 1 | ma cci |
| Source | close | source | ma cci |
| Backtesting Start Date | timestamp("2021-10-01T00:00:00") | time | time_cond |
| Backtesting End Date | timestamp("9999-12-31T00:00:00") | time | time_cond |
| Time Frame To Enter Trades | | string | timetobuy timetoclose |
| Enable Close Trade At End Of Time Frame | false | bool | close_all close_all line 85 line 87 |
| Enter First Trade ASAP | true | bool | entry Long entry Short line 61 line 63 |
| Wait For Cross To Enter First Trade | false | bool | entry Long entry Short line 65 line 67 |
| Use CCI Simple Cross Line For Entries & Exits | true | bool | entry Long entry Short entry Long entry Short line 61 line 63 line 65 line 67 |
| Use Upper & Lower Bands For Entries & Exits | false | bool | entry Long entry Short close_all close_all close_all close_all line 70 line 72 line 75 line 77 line 80 line 82 |
| CCI Simple Cross | 0 | int | simplecrossup simplecrossdown entry Long entry Short line 61 line 63 |
| CCI Enter Long Band | 100 | int | uppercrossup upperstop |
| CCI Exit Long Band | 100 | int | uppercrossdown |
| CCI Enter Short Band | -100 | int | lowercrossdown lowerstop |
| CCI Exit Short Band | -100 | int | lowercrossup |
| Enable Stop Loss | false | bool | exit Close Long exit Close Short Long Fixed SL Short Fixed SL line 90 line 92 |
| Enable Take Profit | false | bool | exit Close Long exit Close Short Long Take Profit Short Take Profit line 95 line 97 |
| Stop Loss % | 5.0 | float · step 0.1 | longStop shortStop |
| Take Profit % | 10.0 | float · step 0.1 | shortTake longTake |
| Long Entry message | | string | entry Long |
| Short Entry message | | string | entry Short |
| Close Long message | | string | close_all exit Close Long |
| Close Short message | | string | close_all exit Close Short |
What it calculates
- SMA (
sma,ta.smain v5)Source (close), CCI Length (20)ma · line 8 - DEV (
dev,ta.devin v5)Source (close), CCI Length (20)cci · line 9 - Crossover (
crossover,ta.crossoverin v5)cci, CCI Simple Cross (0)simplecrossup · line 32 - Crossunder (
crossunder,ta.crossunderin v5)cci, CCI Simple Cross (0)simplecrossdown · line 33 - Crossover (
crossover,ta.crossoverin v5)cci, CCI Enter Long Band (100)uppercrossup · line 34 - Crossunder (
crossunder,ta.crossunderin v5)cci, CCI Enter Short Band (-100)lowercrossdown · line 35 - Crossunder (
crossunder,ta.crossunderin v5)cci, CCI Exit Long Band (100)uppercrossdown · line 36 - Crossover (
crossover,ta.crossoverin v5)cci, CCI Exit Short Band (-100)lowercrossup · line 37 - Crossunder (
crossunder,ta.crossunderin v5)cci, CCI Enter Long Band (100)upperstop · line 38 - Crossover (
crossover,ta.crossoverin v5)cci, CCI Enter Short Band (-100)lowerstop · line 39
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 | (cci > ccisource and enablezero and enableentry and time_cond and timetobuy) | On | 62 |
| Open Short short | (cci < ccisource and enablezero and enableentry and time_cond and timetobuy) | On | 64 |
| Open Long long | (simplecrossup and enablezero and enableconfirmation and time_cond and timetobuy) | On | 66 |
| Open Short short | (simplecrossdown and enablezero and enableconfirmation and time_cond and timetobuy) | On | 68 |
| Open Long long | (uppercrossup and enablebands and time_cond and timetobuy) | On | 71 |
| Open Short short | (lowercrossdown and enablebands and time_cond and timetobuy) | On | 73 |
| Close | strategy.position_size > 0 and uppercrossdown and enablebands and time_cond and timetobuy | On | 76 |
| Close | strategy.position_size < 0 and lowercrossup and enablebands and time_cond and timetobuy | On | 78 |
| Close | strategy.position_size > 0 and upperstop and enablebands and time_cond and timetobuy | On | 81 |
| Close | strategy.position_size < 0 and lowerstop and enablebands and time_cond and timetobuy | On | 83 |
| Close | strategy.position_size > 0 and timetoclose and enableclose and time_cond | On | 86 |
| Close | strategy.position_size < 0 and timetoclose and enableclose and time_cond | On | 88 |
| Exit Close Long stop and limit | strategy.position_size > 0 and enablesl and time_cond | On | 91 |
| Exit Close Short stop and limit | strategy.position_size < 0 and enablesl and time_cond | On | 93 |
| Exit Close Long stop and limit | strategy.position_size > 0 and enabletp and time_cond | On | 96 |
| Exit Close Short stop and limit | strategy.position_size < 0 and enabletp and time_cond | On | 98 |
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, and the live replay matched history.
- 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 | +62.1% | +102.5% | 103 | 28% | 1.33 | 44.4% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −3.7% | +5.5% | 108 | 22% | 0.96 | 26.3% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +87.6% | +9.8% | 101 | 25% | 1.30 | 36.8% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −34.9% | +8.4% | 152 | 15% | 0.74 | 44.9% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +48.9% | +16.7% | 95 | 33% | 1.14 | 42.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +1.1% | +21.5% | 122 | 22% | 1.01 | 23.7% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +124.7% | +148.3% | 99 | 31% | 1.76 | 25.1% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −10.1% | +17.1% | 128 | 23% | 0.88 | 26.0% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
The trades
By market direction
| At entry, last 90 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 35 | 31% | $347.94 |
| Sideways market | 40 | 33% | $2,938.73 |
| Falling market | 28 | 18% | $2,920.53 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
51.0%
The 95th percentile of the worst drawdown when the same 103 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 25.9% to 51.0%; the tick is what actually happened, 42.5%. Order luck alone moves it this much.
All 103 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 15 Feb 2024 51,795.20 | 17 Mar 2024 65,300.60 | 31 | $2,607.48 |
| short | 17 Mar 2024 65,300.60 | 18 Mar 2024 68,393.50 | 1 | −$473.63 |
| long | 18 Mar 2024 68,393.50 | 20 Mar 2024 61,937.40 | 2 | −$943.96 |
| short | 20 Mar 2024 61,937.40 | 21 Mar 2024 67,840.50 | 1 | −$953.08 |
| long | 21 Mar 2024 67,840.50 | 22 Mar 2024 65,501.30 | 1 | −$344.81 |
| short | 22 Mar 2024 65,501.30 | 26 Mar 2024 69,880.00 | 4 | −$668.49 |
| long | 26 Mar 2024 69,880.00 | 3 Apr 2024 65,464.00 | 8 | −$631.94 |
| short | 3 Apr 2024 65,464.00 | 5 Apr 2024 68,487.80 | 2 | −$461.90 |
| long | 5 Apr 2024 68,487.80 | 13 Apr 2024 67,116.50 | 8 | −$200.22 |
| short | 13 Apr 2024 67,116.50 | 23 Apr 2024 66,819.30 | 10 | $44.28 |
| long | 23 Apr 2024 66,819.30 | 24 Apr 2024 66,414.00 | 1 | −$60.66 |
| short | 24 Apr 2024 66,414.00 | 5 May 2024 63,892.00 | 11 | $379.74 |
| long | 5 May 2024 63,892.00 | 7 May 2024 63,165.20 | 2 | −$113.76 |
| short | 7 May 2024 63,165.20 | 14 May 2024 62,940.10 | 7 | $35.64 |
| long | 14 May 2024 62,940.10 | 15 May 2024 61,577.50 | 1 | −$216.49 |
| short | 15 May 2024 61,577.50 | 16 May 2024 66,206.50 | 1 | −$751.74 |
| long | 16 May 2024 66,206.50 | 12 Jun 2024 67,314.20 | 27 | $167.31 |
| short | 12 Jun 2024 67,314.20 | 15 Jul 2024 60,797.90 | 33 | $968.04 |
| long | 15 Jul 2024 60,797.90 | 1 Aug 2024 64,628.00 | 17 | $629.97 |
| short | 1 Aug 2024 64,628.00 | 22 Aug 2024 61,156.00 | 21 | $537.23 |
| long | 22 Aug 2024 61,156.00 | 28 Aug 2024 59,415.00 | 6 | −$284.69 |
| short | 28 Aug 2024 59,415.00 | 14 Sep 2024 60,498.00 | 17 | −$182.28 |
| long | 14 Sep 2024 60,498.00 | 2 Oct 2024 60,804.90 | 18 | $50.73 |
| short | 2 Oct 2024 60,804.90 | 13 Oct 2024 63,206.20 | 11 | −$394.92 |
| long | 13 Oct 2024 63,206.20 | 5 Nov 2024 67,850.00 | 23 | $734.70 |
| short | 5 Nov 2024 67,850.00 | 6 Nov 2024 69,372.00 | 1 | −$224.32 |
| long | 6 Nov 2024 69,372.00 | 11 Dec 2024 96,593.00 | 35 | $3,923.92 |
| short | 11 Dec 2024 96,593.00 | 12 Dec 2024 101,125.00 | 1 | −$469.19 |
| long | 12 Dec 2024 101,125.00 | 20 Dec 2024 97,461.90 | 8 | −$362.24 |
| short | 20 Dec 2024 97,461.90 | 4 Jan 2025 98,174.20 | 15 | −$73.09 |
| long | 4 Jan 2025 98,174.20 | 9 Jan 2025 95,060.60 | 5 | −$317.15 |
| short | 9 Jan 2025 95,060.60 | 15 Jan 2025 96,560.90 | 6 | −$157.82 |
| long | 15 Jan 2025 96,560.90 | 2 Feb 2025 100,636.00 | 18 | $421.99 |
| short | 2 Feb 2025 100,636.00 | 21 Feb 2025 98,305.00 | 19 | $231.59 |
| long | 21 Feb 2025 98,305.00 | 22 Feb 2025 96,182.00 | 1 | −$215.96 |
| short | 22 Feb 2025 96,182.00 | 3 Mar 2025 94,270.00 | 9 | $198.79 |
| long | 3 Mar 2025 94,270.00 | 4 Mar 2025 86,221.20 | 1 | −$853.81 |
| short | 4 Mar 2025 86,221.20 | 20 Mar 2025 86,845.90 | 16 | −$72.46 |
| long | 20 Mar 2025 86,845.90 | 21 Mar 2025 84,223.40 | 1 | −$301.98 |
| short | 21 Mar 2025 84,223.40 | 24 Mar 2025 86,082.50 | 3 | −$220.74 |
| long | 24 Mar 2025 86,082.50 | 30 Mar 2025 82,648.50 | 6 | −$398.92 |
| short | 30 Mar 2025 82,648.50 | 2 Apr 2025 85,158.40 | 3 | −$303.67 |
| long | 2 Apr 2025 85,158.40 | 3 Apr 2025 82,516.30 | 1 | −$310.25 |
| short | 3 Apr 2025 82,516.30 | 12 Apr 2025 83,423.80 | 9 | −$109.98 |
| long | 12 Apr 2025 83,423.80 | 30 May 2025 105,590.00 | 48 | $2,657.02 |
| short | 30 May 2025 105,590.00 | 10 Jun 2025 110,263.00 | 11 | −$442.59 |
| long | 10 Jun 2025 110,263.00 | 13 Jun 2025 105,672.00 | 3 | −$416.39 |
| short | 13 Jun 2025 105,672.00 | 17 Jun 2025 106,795.00 | 4 | −$106.25 |
| long | 17 Jun 2025 106,795.00 | 18 Jun 2025 104,551.00 | 1 | −$210.06 |
| short | 18 Jun 2025 104,551.00 | 24 Jun 2025 105,334.00 | 6 | −$74.87 |
| long | 24 Jun 2025 105,334.00 | 30 Jul 2025 117,951.00 | 36 | $1,197.79 |
| short | 30 Jul 2025 117,951.00 | 8 Aug 2025 117,472.00 | 9 | $40.59 |
| long | 8 Aug 2025 117,472.00 | 9 Aug 2025 116,675.00 | 1 | −$67.87 |
| short | 9 Aug 2025 116,675.00 | 11 Aug 2025 119,294.00 | 2 | −$224.52 |
| long | 11 Aug 2025 119,294.00 | 19 Aug 2025 116,227.00 | 8 | −$257.11 |
| short | 19 Aug 2025 116,227.00 | 23 Aug 2025 116,936.00 | 4 | −$61.00 |
| long | 23 Aug 2025 116,936.00 | 24 Aug 2025 115,438.00 | 1 | −$128.10 |
| short | 24 Aug 2025 115,438.00 | 9 Sep 2025 112,065.00 | 16 | $292.18 |
| long | 9 Sep 2025 112,065.00 | 23 Sep 2025 112,651.00 | 14 | $52.27 |
| short | 23 Sep 2025 112,651.00 | 30 Sep 2025 114,312.00 | 7 | −$147.44 |
| long | 30 Sep 2025 114,312.00 | 1 Oct 2025 114,049.00 | 1 | −$23.01 |
| short | 1 Oct 2025 114,049.00 | 2 Oct 2025 118,595.00 | 1 | −$398.61 |
| long | 2 Oct 2025 118,595.00 | 11 Oct 2025 112,774.00 | 9 | −$490.79 |
| short | 11 Oct 2025 112,774.00 | 27 Oct 2025 114,559.00 | 16 | −$158.27 |
| long | 27 Oct 2025 114,559.00 | 30 Oct 2025 110,021.00 | 3 | −$396.14 |
| short | 30 Oct 2025 110,021.00 | 3 Nov 2025 110,541.00 | 4 | −$47.21 |
| long | 3 Nov 2025 110,541.00 | 4 Nov 2025 106,583.00 | 1 | −$358.03 |
| short | 4 Nov 2025 106,583.00 | 3 Dec 2025 91,277.90 | 29 | $1,435.99 |
| long | 3 Dec 2025 91,277.90 | 6 Dec 2025 89,330.00 | 3 | −$213.40 |
| short | 6 Dec 2025 89,330.00 | 8 Dec 2025 90,395.30 | 2 | −$119.25 |
| long | 8 Dec 2025 90,395.30 | 13 Dec 2025 90,268.40 | 5 | −$14.04 |
| short | 13 Dec 2025 90,268.40 | 31 Dec 2025 88,485.50 | 18 | $197.51 |
| long | 31 Dec 2025 88,485.50 | 1 Jan 2026 87,648.20 | 1 | −$94.62 |
| short | 1 Jan 2026 87,648.20 | 2 Jan 2026 88,839.10 | 1 | −$135.87 |
| long | 2 Jan 2026 88,839.10 | 21 Jan 2026 88,427.70 | 19 | −$46.31 |
| short | 21 Jan 2026 88,427.70 | 3 Mar 2026 68,830.10 | 41 | $2,216.23 |
| long | 3 Mar 2026 68,830.10 | 8 Mar 2026 67,262.90 | 5 | −$227.68 |
| short | 8 Mar 2026 67,262.90 | 10 Mar 2026 68,432.20 | 2 | −$173.83 |
| long | 10 Mar 2026 68,432.20 | 20 Mar 2026 69,930.00 | 10 | $218.88 |
| short | 20 Mar 2026 69,930.00 | 21 Mar 2026 70,510.70 | 1 | −$83.04 |
| long | 21 Mar 2026 70,510.70 | 22 Mar 2026 68,918.10 | 1 | −$225.87 |
| short | 22 Mar 2026 68,918.10 | 24 Mar 2026 70,906.40 | 2 | −$288.51 |
| long | 24 Mar 2026 70,906.40 | 27 Mar 2026 68,820.30 | 3 | −$294.21 |
| short | 27 Mar 2026 68,820.30 | 6 Apr 2026 69,034.20 | 10 | −$31.08 |
| long | 6 Apr 2026 69,034.20 | 16 May 2026 79,113.20 | 40 | $1,460.00 |
| short | 16 May 2026 79,113.20 | 21 Jun 2026 64,298.00 | 36 | $1,872.66 |
| long | 21 Jun 2026 64,298.00 | 22 Jun 2026 63,312.00 | 1 | −$153.35 |
| short | 22 Jun 2026 63,312.00 | 23 Jun 2026 64,020.00 | 1 | −$111.83 |
| long | 23 Jun 2026 64,020.00 | 24 Jun 2026 62,734.60 | 1 | −$200.79 |
| short | 24 Jun 2026 62,734.60 | 4 Jul 2026 62,583.30 | 10 | $24.12 |
| long | 4 Jul 2026 62,583.30 | 25 Jul 2026 64,140.00 | 21 | $248.75 |
| short | 25 Jul 2026 64,140.00 | 26 Jul 2026 64,375.00 | 1 | −$36.64 |
| long | 26 Jul 2026 64,375.00 | 28 Jul 2026 63,755.90 | 2 | −$96.18 |
| short | 28 Jul 2026 63,755.90 | 31 Jul 2026 64,780.00 | 3 | −$160.64 |
| long | 31 Jul 2026 64,780.00 | 1 Aug 2026 62,887.90 | 1 | −$292.09 |
| short | 1 Aug 2026 62,887.90 | 6 Aug 2026 64,665.20 | 5 | −$282.62 |
| long | 6 Aug 2026 64,665.20 | 7 Aug 2026 64,323.60 | 1 | −$52.83 |
| short | 7 Aug 2026 64,323.60 | 8 Aug 2026 64,923.20 | 1 | −$93.21 |
| long | 8 Aug 2026 64,923.20 | 11 Aug 2026 63,970.00 | 3 | −$146.82 |
| short | 11 Aug 2026 63,970.00 | 18 Aug 2026 64,532.10 | 7 | −$87.87 |
| long | 18 Aug 2026 64,532.10 | 10 Sep 2026 78,306.40 | 23 | $2,134.49 |
| short | 10 Sep 2026 78,306.40 | 19 Sep 2026 80,883.90 | 9 | −$329.15 |
| long | 19 Sep 2026 80,883.90 | 8 Oct 2026 83,321.80 | 19 | $301.41 |
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 Strategy this page | — | v4 strategy | +62.1% | 103 | 44.4% |
| CCI & EMA strategy by Tradeswithashish by tradeswithashish | sma dev | v5 strategy | +0.1% | 16 | 0.4% |
| Crypto rsi cci mf stoch rsi oscillators all in one strategy by SoftKill21 | sma dev | v4 strategy | +1.6% | 3 | 26.8% |
| CCI + EMA with RSI Cross Strategy by rwestbrookjr | sma dev | v5 strategy | No trades on this market | ||
| Oath by OrcChieftain | sma dev | v4 strategy | +0.2% | 45 | 0.0% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 31 ms | With a workaround 1,000 bars in 85 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.
“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. PineTS runs Pine Script v5 and v6 only.
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/// © REV0LUTI0N//@version=4strategy(title="CCI Strategy", overlay=true, initial_capital = 10000, default_qty_value = 10000, default_qty_type = strategy.cash)//CCI Codelength = input(20, minval=1, title="CCI Length")src = input(close, title="Source")ma = sma(src, length)cci = (src - ma) / (0.015 * dev(src, length))// Strategy BacktestingstartDate = input(timestamp("2021-10-01T00:00:00"), type = input.time, title='Backtesting Start Date')finishDate = input(timestamp("9999-12-31T00:00:00"), type = input.time, title='Backtesting End Date')time_cond = time >= startDate and time <= finishDate//Time Restriction Settingsstartendtime = input("", title='Time Frame To Enter Trades')enableclose = input(false, title='Enable Close Trade At End Of Time Frame')timetobuy = (time(timeframe.period, startendtime))timetoclose = na(time(timeframe.period, startendtime))//Strategy Settings//Strategy Settings - Enable Check Boxesenableentry = input(true, title="Enter First Trade ASAP")enableconfirmation = input(false, title="Wait For Cross To Enter First Trade")enablezero =input(true, title="Use CCI Simple Cross Line For Entries & Exits")enablebands = input(false, title="Use Upper & Lower Bands For Entries & Exits")//Strategy Settings - Band Sourcesccisource = input(0, title="CCI Simple Cross")upperbandsource =input(100, title="CCI Enter Long Band")upperbandexitsource =input(100, title="CCI Exit Long Band")lowerbandsource =input(-100, title="CCI Enter Short Band")lowerbandexitsource =input(-100, title="CCI Exit Short Band")//Strategy Settings - Crossessimplecrossup = crossover(cci, ccisource)simplecrossdown = crossunder(cci, ccisource)uppercrossup = crossover(cci, upperbandsource)lowercrossdown = crossunder(cci, lowerbandsource)uppercrossdown = crossunder(cci, upperbandexitsource)lowercrossup = crossover(cci, lowerbandexitsource)upperstop = crossunder(cci, upperbandsource)lowerstop = crossover(cci, lowerbandsource)// Stop Loss & Take Profit % Basedenablesl = input(false, title='Enable Stop Loss')enabletp = input(false, title='Enable Take Profit')stopTick = input(5.0, title='Stop Loss %', type=input.float, step=0.1) / 100takeTick = input(10.0, title='Take Profit %', type=input.float, step=0.1) / 100longStop = strategy.position_avg_price * (1 - stopTick)shortStop = strategy.position_avg_price * (1 + stopTick)shortTake = strategy.position_avg_price * (1 - takeTick)longTake = strategy.position_avg_price * (1 + takeTick)plot(strategy.position_size > 0 and enablesl ? longStop : na, style=plot.style_linebr, color=color.red, linewidth=1, title="Long Fixed SL")plot(strategy.position_size < 0 and enablesl ? shortStop : na, style=plot.style_linebr, color=color.red, linewidth=1, title="Short Fixed SL")plot(strategy.position_size > 0 and enabletp ? longTake : na, style=plot.style_linebr, color=color.green, linewidth=1, title="Long Take Profit")plot(strategy.position_size < 0 and enabletp ? shortTake : na, style=plot.style_linebr, color=color.green, linewidth=1, title="Short Take Profit")// Alert messagesmessage_enterlong = input("", title="Long Entry message")message_entershort = input("", title="Short Entry message")message_closelong = input("", title="Close Long message")message_closeshort = input("", title="Close Short message") //Strategy Execution//Strategy Execution - Simple Line Crossif (cci > ccisource and enablezero and enableentry and time_cond and timetobuy) strategy.entry("Long", strategy.long, alert_message = message_enterlong)if (cci < ccisource and enablezero and enableentry and time_cond and timetobuy) strategy.entry("Short", strategy.short, alert_message = message_entershort)if (simplecrossup and enablezero and enableconfirmation and time_cond and timetobuy) strategy.entry("Long", strategy.long, alert_message = message_enterlong)if (simplecrossdown and enablezero and enableconfirmation and time_cond and timetobuy) strategy.entry("Short", strategy.short, alert_message = message_entershort)//Strategy Execution - Upper and Lower Band Entryif (uppercrossup and enablebands and time_cond and timetobuy) strategy.entry("Long", strategy.long, alert_message = message_enterlong)if (lowercrossdown and enablebands and time_cond and timetobuy) strategy.entry("Short", strategy.short, alert_message = message_entershort)//Strategy Execution - Upper and Lower Band Exitif strategy.position_size > 0 and uppercrossdown and enablebands and time_cond and timetobuy strategy.close_all(alert_message = message_closelong)if strategy.position_size < 0 and lowercrossup and enablebands and time_cond and timetobuy strategy.close_all(alert_message = message_closeshort)//Strategy Execution - Upper and Lower Band Stopsif strategy.position_size > 0 and upperstop and enablebands and time_cond and timetobuy strategy.close_all(alert_message = message_closelong)if strategy.position_size < 0 and lowerstop and enablebands and time_cond and timetobuy strategy.close_all(alert_message = message_closeshort)//Strategy Execution - Close Trade At End Of Time Frame if strategy.position_size > 0 and timetoclose and enableclose and time_cond strategy.close_all(alert_message = message_closelong)if strategy.position_size < 0 and timetoclose and enableclose and time_cond strategy.close_all(alert_message = message_closeshort)//Strategy Execution - Stop Loss and Take Profitif strategy.position_size > 0 and enablesl and time_cond strategy.exit(id="Close Long", stop=longStop, limit=longTake, alert_message = message_closelong)if strategy.position_size < 0 and enablesl and time_cond strategy.exit(id="Close Short", stop=shortStop, limit=shortTake, alert_message = message_closeshort) if strategy.position_size > 0 and enabletp and time_cond strategy.exit(id="Close Long", stop=longStop, limit=longTake, alert_message = message_closelong)if strategy.position_size < 0 and enabletp and time_cond strategy.exit(id="Close Short", stop=shortStop, limit=shortTake, alert_message = message_closeshort)