Pine Script v4 · Strategy
CCI Scalping Strategy
A Pine Script v4 strategy built on Lowest (10), Highest (10) and Valuewhen (bought, LL). It has 10 order rules, 8 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade commits 100% of equity and pays 0.04 commission. 15 settings; defaults include Strategy Direction 0, Strategy Stop Mult 0 and CCI Length 16.
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 Scalping Strategy repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 11 of 11 trades.
- How did CCI Scalping Strategy do on BTCUSDT 1D with default settings?
- −66.20%
- From 26 Jan 2024 to 21 Oct 2026, over 41 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can CCI Scalping 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 Scalping Strategy use a stop loss?
- Yes
- strategy.exit sets a stop on line 93, 94.
- Does CCI Scalping Strategy run in Zeal Terminal?
- Yes
- It compiles in 27 ms and runs 1,000 bars in 78 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- SL
- SSL
- TP
- STP
- Bullish Setup
- Bearish Setup
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −66.20%
- −$6,620.17
- Buy and hold
- +102.5%
- same period
- Closed trades
- 41
- 20 won · 21 lost
- Profitable
- 48.8%
- of closed trades
- Profit factor
- 0.48
- gross profit ÷ gross loss
- Max drawdown
- 72.97%
- −$7,297.05
One run with the author's default settings, $10,000 starting capital, commission as the script sets it. A long 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
2 settings do nothing
“-----------------Strategy Inputs-------------------”, “-----------------General Inputs-------------------” are declared but never read.
-
Check
Every trade uses all the equity
default_qty_value is 100% of equity.
-
Note
Uses an argument v6 removed
when = on line 77, 78, 80, 81, 84, 85, 87, 88, 93, 94. The upgraded version below moves each call inside an if block.
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 lowest → ta.lowest, highest → ta.highest, valuewhen → ta.valuewhen, atr → ta.atr, cci → ta.cci, wma → ta.wma, crossover → ta.crossover, crossunder → ta.crossunder.
- 10 strategy calls use the when = argument (line 77, 78, 80, 81, 84, 85, 87, 88, 93, 94). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 41 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 11: //@version=4 → //@version=5
- Line 20: input(type = input.integer) → input.int()
- Line 41: lowest → ta.lowest
- Line 42: highest → ta.highest
- Line 43: valuewhen → ta.valuewhen
- Line 44: valuewhen → ta.valuewhen
9 more edits
- Line 50: atr → ta.atr
- Line 53: valuewhen → ta.valuewhen
- Line 54: valuewhen → ta.valuewhen
- Line 61: cci → ta.cci
- Line 63: wma → ta.wma
- Line 65: valuewhen → ta.valuewhen
- Line 66: valuewhen → ta.valuewhen
- Line 69: crossover → ta.crossover
- Line 70: crossunder → ta.crossunder
⋯// Stop: Above 20 WMA"-//@version=4+//@version=5strategy("CCI Scalping Strat", ⋯ slippage=0)-direction = input(0, title = "Strategy Direction", type=input.integer, minval=-1, maxval=1)+direction = input.int(0, title = "Strategy Direction", minval=-1, maxval=1)strategy.risk.allow_entry_in(direction == 0 ? strategy.direction.all : (direction < 0 ? strategy.direction.short : strategy.direction.long))⋯// Price Action Stop and Take Profit-LL=(lowest(i_SPL))*(1-i_PercIncrement)+LL=(ta.lowest(i_SPL))*(1-i_PercIncrement)-HH=(highest(i_SPL))*(1+i_PercIncrement)+HH=(ta.highest(i_SPL))*(1+i_PercIncrement)-LL_price = valuewhen(bought, LL, 0)+LL_price = ta.valuewhen(bought, LL, 0)-HH_price = valuewhen(bought, HH, 0)+HH_price = ta.valuewhen(bought, HH, 0)entry_LL_price = strategy.position_size > 0 ? LL_price : na ⋯// ATR Stop-ATR=atr(i_ATR)*i_ATRMult+ATR=ta.atr(i_ATR)*i_ATRMultATRLong = ohlc4 - ATRATRShort = ohlc4 + ATR-ATRLongStop = valuewhen(bought, ATRLong, 0)+ATRLongStop = ta.valuewhen(bought, ATRLong, 0)-ATRShortStop = valuewhen(bought, ATRShort, 0)+ATRShortStop = ta.valuewhen(bought, ATRShort, 0)LongSL_ATR_price = strategy.position_size > 0 ? ATRLongStop : na ⋯//CCI-CCI=cci(close, i_CCI)+CCI=ta.cci(close, i_CCI)//WMA-WMA=wma(close, i_WMA)+WMA=ta.wma(close, i_WMA)//Stops-LongStop=valuewhen(bought, WMA, 0)*(1-i_Stop)+LongStop=ta.valuewhen(bought, WMA, 0)*(1-i_Stop)-ShortStop=valuewhen(bought, WMA, 0)*(1+i_Stop)+ShortStop=ta.valuewhen(bought, WMA, 0)*(1+i_Stop)StratTP=strategy.position_avg_price + (strategy.position_avg_price - LongStop)*i_TPRRRStratSTP=strategy.position_avg_price - (ShortStop - strategy.position_avg_price)*i_TPRRR-BUY = (close > WMA) and crossover(CCI , -100)+BUY = (close > WMA) and ta.crossover(CCI , -100)-SELL = (close < WMA) and crossunder(CCI , 100)+SELL = (close < WMA) and ta.crossunder(CCI , 100)//Trading Inputs⋯Same 41 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 23: input() → input.bool()
- Line 24: input() → input.int()
- Line 25: input() → input.int()
- Line 26: input() → input.int()
- Line 28: input() → input.bool()
- Line 30: input() → input.bool()
18 more edits
- Line 31: input() → input.string()
- Line 32: input() → input.int()
- Line 33: input() → input.int()
- Line 34: input() → input.int()
- Line 35: input() → input.int()
- Line 36: input() → input.float()
- Line 72: input() → input.bool()
- Line 73: input() → input.bool()
- Line 77: when = SELL and strategy.position_size == 0 → if block
- Line 78: when = BUY and strategy.position_size == 0 → if block
- Line 80: when = SELL → if block
- Line 81: when = BUY → if block
- Line 84: when = BUY and strategy.position_size == 0 → if block
- Line 85: when = SELL and strategy.position_size == 0 → if block
- Line 87: when = BUY → if block
- Line 88: when = SELL → if block
- Line 93: when = i_SL → if block
- Line 94: when = i_SL → if block
⋯/////////////////////// STRATEGY INPUTS ////////////////////////////////////////-title1=input(true, "-----------------Strategy Inputs-------------------") +title1=input.bool(true, "-----------------Strategy Inputs-------------------") -i_Stop = input(0, step=.05, title="Strategy Stop Mult")*.01+i_Stop = input.int(0, step=.05, title="Strategy Stop Mult")*.01-i_CCI=input(16, title="CCI Length")+i_CCI=input.int(16, title="CCI Length")-i_WMA=input(5, title="WMA Length")+i_WMA=input.int(5, title="WMA Length")/////////////////////// BACKTESTER /////////////////////////////////////////////-title2=input(true, "-----------------General Inputs-------------------") +title2=input.bool(true, "-----------------General Inputs-------------------") // Backtester General Inputs-i_SL=input(true, title="Use Stop Loss and Take Profit")+i_SL=input.bool(true, title="Use Stop Loss and Take Profit")-i_SLType=input(defval="ATR Stop", title="Type Of Stop", options=["Strategy Stop", "Swing Lo/Hi", "ATR Stop"])+i_SLType=input.string(defval="ATR Stop", title="Type Of Stop", options=["Strategy Stop", "Swing Lo/Hi", "ATR Stop"])-i_SPL=input(defval=10, title="Swing Point Lookback")+i_SPL=input.int(defval=10, title="Swing Point Lookback")-i_PercIncrement=input(defval=2, step=.1, title="Swing Point SL Perc Increment")*0.01+i_PercIncrement=input.int(defval=2, step=.1, title="Swing Point SL Perc Increment")*0.01-i_ATR = input(14, title="ATR Length")+i_ATR = input.int(14, title="ATR Length")-i_ATRMult = input(10, step=.1, title="ATR Multiple")+i_ATRMult = input.int(10, step=.1, title="ATR Multiple")-i_TPRRR = input(1.5, step=.1, title="Take Profit Risk Reward Ratio")+i_TPRRR = input.float(1.5, step=.1, title="Take Profit Risk Reward Ratio")// Bought and Sold Boolean Signal⋯//Trading Inputs-DPR=input(true, "Allow Direct Position Reverse")+DPR=input.bool(true, "Allow Direct Position Reverse")-reverse=input(false, "Reverse Trades")+reverse=input.bool(false, "Reverse Trades")// Entries⋯ if not DPR- strategy.entry("long", strategy.long, when=SELL and strategy.position_size == 0)+ if SELL and strategy.position_size == 0+ strategy.entry("long", strategy.long)- strategy.entry("short", strategy.short, when=BUY and strategy.position_size == 0)+ if BUY and strategy.position_size == 0+ strategy.entry("short", strategy.short) else - strategy.entry("long", strategy.long, when=SELL)+ if SELL+ strategy.entry("long", strategy.long)- strategy.entry("short", strategy.short, when=BUY)+ if BUY+ strategy.entry("short", strategy.short)else if not DPR - strategy.entry("long", strategy.long, when=BUY and strategy.position_size == 0)+ if BUY and strategy.position_size == 0+ strategy.entry("long", strategy.long)- strategy.entry("short", strategy.short, when=SELL and strategy.position_size == 0)+ if SELL and strategy.position_size == 0+ strategy.entry("short", strategy.short) else- strategy.entry("long", strategy.long, when=BUY)+ if BUY+ strategy.entry("long", strategy.long)- strategy.entry("short", strategy.short, when=SELL)+ if SELL+ strategy.entry("short", strategy.short)SL= i_SLType == "Swing Lo/Hi" ? entry_LL_price : i_SLType == "ATR Stop" ? LongSL_ATR_price : LongStop⋯STP= i_SLType == "Swing Lo/Hi" ? stp : i_SLType == "ATR Stop" ? ATRstp : StratSTP-strategy.exit("TP & SL", "long", limit=TP, stop=SL, when=i_SL)+if i_SL+ strategy.exit("TP & SL", "long", limit=TP, stop=SL)-strategy.exit("TP & SL", "short", limit=STP, stop=SSL, when=i_SL)+if i_SL+ strategy.exit("TP & SL", "short", limit=STP, stop=SSL)/////////////////////// PLOTS //////////////////////////////////////////////////⋯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: 41 before, 8 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.
⋯// Stop: Above 20 WMA"-//@version=5+//@version=6strategy("CCI Scalping Strat", ⋯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 |
|---|---|---|---|
| Strategy Direction | 0 | int (written input.integer) · min -1 · max 1 | line 21 |
| -----------------Strategy Inputs------------------- | true | bool | unused |
| Strategy Stop Mult | 0 | int · step .05 | LongStop ShortStop |
| CCI Length | 16 | int | CCI |
| WMA Length | 5 | int | WMA |
| -----------------General Inputs------------------- | true | bool | unused |
| Use Stop Loss and Take Profit | true | bool | exit TP & SL SL SSL TP STP |
| Type Of Stop | ATR Stop | string · options ["Strategy Stop", "Swing Lo/Hi", "ATR Stop"] | SL SSL TP STP |
| Swing Point Lookback | 10 | int | LL HH |
| Swing Point SL Perc Increment | 2 | int · step .1 | LL HH |
| ATR Length | 14 | int | ATR |
| ATR Multiple | 10 | int · step .1 | ATR |
| Take Profit Risk Reward Ratio | 1.5 | float · step .1 | tp stp ATRtp ATRstp StratTP StratSTP |
| Allow Direct Position Reverse | true | bool | entry long entry short entry long entry short entry long entry short entry long entry short line 76 line 83 |
| Reverse Trades | false | bool | line 75 |
What it calculates
- Lowest (
lowest,ta.lowestin v5)Swing Point Lookback (10)LL · line 41 - Highest (
highest,ta.highestin v5)Swing Point Lookback (10)HH · line 42 - Valuewhen (
valuewhen,ta.valuewhenin v5)bought, LL, 0LL_price · line 43 - Valuewhen (
valuewhen,ta.valuewhenin v5)bought, HH, 0HH_price · line 44 - ATR (
atr,ta.atrin v5)ATR Length (14)ATR · line 50 - Valuewhen (
valuewhen,ta.valuewhenin v5)bought, ATRLong, 0ATRLongStop · line 53 - Valuewhen (
valuewhen,ta.valuewhenin v5)bought, ATRShort, 0ATRShortStop · line 54 - CCI (
cci,ta.cciin v5)close, CCI Length (16)CCI · line 61 - WMA (
wma,ta.wmain v5)close, WMA Length (5)WMA · line 63 - Valuewhen (
valuewhen,ta.valuewhenin v5)bought, WMA, 0LongStop · line 65 - Valuewhen (
valuewhen,ta.valuewhenin v5)bought, WMA, 0ShortStop · line 66
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 | SELL and strategy.position_size == 0 | On | 77 |
| Open short short | BUY and strategy.position_size == 0 | On | 78 |
| Open long long | SELL(close < WMA) and crossunder(CCI , 100) | On | 80 |
| Open short short | BUY(close > WMA) and crossover(CCI , -100) | On | 81 |
| Open long long | BUY and strategy.position_size == 0 | On | 84 |
| Open short short | SELL and strategy.position_size == 0 | On | 85 |
| Open long long | BUY(close > WMA) and crossover(CCI , -100) | On | 87 |
| Open short short | SELL(close < WMA) and crossunder(CCI , 100) | On | 88 |
| Exit TP & SL stop and limit | i_SL | On | 93 |
| Exit TP & SL stop and limit | i_SL | On | 94 |
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 | −66.2% | +102.5% | 41 | 49% | 0.48 | 73.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +17.0% | +5.5% | 45 | 58% | 1.40 | 19.1% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −59.8% | +9.8% | 46 | 57% | 0.82 | 89.3% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −19.7% | +8.4% | 43 | 53% | 0.65 | 43.8% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −67.2% | +16.7% | 39 | 51% | 0.67 | 80.2% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −15.9% | +21.5% | 45 | 56% | 0.77 | 45.7% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −68.8% | +148.3% | 39 | 62% | 0.61 | 80.4% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +22.3% | +17.1% | 40 | 50% | 1.48 | 12.6% | 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 (CCI Length 8, WMA Length 9) made +265.4% before 26 Dec 2025 and −53.8% after it, worse than the defaults' −17.7% after. Tuning on the past did not carry forward. 46% of the 48 combinations made money in-sample and 38% out-of-sample.
| WMA Length ↓ · CCI Length → | 8 | 10 | 11 | 14 | 16 | 19 | 22 | 27 |
|---|---|---|---|---|---|---|---|---|
| 3 | +29% | −2% | −49% | −60% | −49% | −50% | −25% | −9% |
| 4 | +150% | +73% | +2% | −35% | −30% | −46% | −16% | −11% |
| 5 | +78% | +16% | −8% | −48% | −48% | −52% | −26% | −11% |
| 6 | +222% | +111% | +64% | +10% | −23% | −51% | −31% | −12% |
| 7 | +240% | +109% | +21% | +47% | +23% | −32% | −28% | −8% |
| 9 | +265% | +134% | +205% | +38% | +98% | +18% | +19% | −28% |
| WMA Length ↓ · CCI Length → | 8 | 10 | 11 | 14 | 16 | 19 | 22 | 27 |
|---|---|---|---|---|---|---|---|---|
| 3 | −9% | −43% | −9% | −8% | −11% | −13% | −23% | −26% |
| 4 | −14% | −19% | −22% | −14% | −24% | −14% | −26% | −25% |
| 5 | −54% | −39% | −34% | −11% | −18% | −12% | −18% | −25% |
| 6 | +122% | −21% | −30% | +0% | −4% | +10% | +17% | +64% |
| 7 | +128% | −10% | +41% | +77% | +71% | +61% | +17% | +67% |
| 9 | −54% | −73% | +8% | +120% | +22% | +34% | +18% | +49% |
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.
The trades
By market direction
| At entry, last 90 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 16 | 44% | −$3,321.32 |
| Sideways market | 17 | 53% | −$2,486.81 |
| Falling market | 8 | 50% | −$810.69 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
80.4%
The 95th percentile of the worst drawdown when the same 41 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 66.5% to 80.4%; the tick is what actually happened, 72.8%. Order luck alone moves it this much.
All 41 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 18 Feb 2024 51,642.60 | 4 Mar 2024 66,908.50 | 15 | −$2,964.06 |
| short | 6 Mar 2024 63,724.00 | 21 Mar 2024 67,840.50 | 15 | −$460.14 |
| long | 21 Mar 2024 67,840.50 | 2 Apr 2024 69,649.80 | 12 | $170.06 |
| short | 2 Apr 2024 69,649.80 | 19 Apr 2024 63,470.10 | 17 | $593.37 |
| long | 19 Apr 2024 63,470.10 | 20 May 2024 66,274.00 | 31 | $318.20 |
| short | 20 May 2024 66,274.00 | 17 Jun 2024 66,676.90 | 28 | −$52.69 |
| long | 17 Jun 2024 66,676.90 | 27 Aug 2024 62,834.00 | 71 | −$444.20 |
| short | 27 Aug 2024 62,834.00 | 3 Sep 2024 59,132.10 | 7 | $416.31 |
| long | 3 Sep 2024 59,132.10 | 16 Sep 2024 59,132.00 | 13 | −$6.08 |
| short | 16 Sep 2024 59,132.00 | 5 Oct 2024 62,086.00 | 19 | −$384.41 |
| long | 5 Oct 2024 62,086.00 | 22 Oct 2024 67,377.50 | 17 | $606.51 |
| short | 22 Oct 2024 67,377.50 | 11 Nov 2024 86,562.90 | 20 | −$2,226.10 |
| short | 26 Nov 2024 93,010.00 | 25 Dec 2024 98,663.60 | 29 | −$342.82 |
| long | 25 Dec 2024 98,663.60 | 8 Jan 2025 96,954.60 | 14 | −$94.63 |
| short | 8 Jan 2025 96,954.60 | 4 Feb 2025 101,329.00 | 27 | −$235.59 |
| long | 4 Feb 2025 101,329.00 | 22 Feb 2025 96,182.00 | 18 | −$252.38 |
| short | 22 Feb 2025 96,182.00 | 2 Mar 2025 86,064.50 | 8 | $484.71 |
| long | 2 Mar 2025 86,064.50 | 28 Apr 2025 93,749.30 | 57 | $453.39 |
| short | 28 Apr 2025 93,749.30 | 7 Jun 2025 104,288.00 | 40 | −$631.95 |
| long | 7 Jun 2025 104,288.00 | 12 Jun 2025 108,645.00 | 5 | $202.66 |
| short | 12 Jun 2025 108,645.00 | 24 Jun 2025 105,334.00 | 12 | $152.90 |
| long | 24 Jun 2025 105,334.00 | 1 Jul 2025 107,147.00 | 7 | $86.97 |
| short | 1 Jul 2025 107,147.00 | 5 Aug 2025 115,055.00 | 35 | −$402.31 |
| long | 5 Aug 2025 115,055.00 | 15 Aug 2025 118,295.00 | 10 | $136.42 |
| short | 15 Aug 2025 118,295.00 | 23 Aug 2025 116,936.00 | 8 | $54.80 |
| long | 23 Aug 2025 116,936.00 | 16 Sep 2025 115,350.00 | 24 | −$74.37 |
| short | 16 Sep 2025 115,350.00 | 25 Sep 2025 113,307.00 | 9 | $86.35 |
| long | 25 Sep 2025 113,307.00 | 8 Oct 2025 121,333.00 | 13 | $363.39 |
| short | 8 Oct 2025 121,333.00 | 20 Oct 2025 108,643.00 | 12 | $576.71 |
| long | 20 Oct 2025 108,643.00 | 8 Jan 2026 91,364.20 | 80 | −$979.52 |
| short | 8 Jan 2026 91,364.20 | 27 Jan 2026 88,347.10 | 19 | $166.06 |
| long | 27 Jan 2026 88,347.10 | 5 Feb 2026 64,451.20 | 9 | −$1,441.92 |
| long | 9 Feb 2026 70,330.40 | 7 Mar 2026 68,114.00 | 26 | −$125.14 |
| short | 7 Mar 2026 68,114.00 | 31 Mar 2026 66,797.40 | 24 | $69.53 |
| long | 31 Mar 2026 66,797.40 | 13 Apr 2026 70,741.60 | 13 | $222.41 |
| short | 13 Apr 2026 70,741.60 | 21 May 2026 77,552.20 | 38 | −$392.58 |
| long | 21 May 2026 77,552.20 | 1 Jul 2026 57,931.60 | 41 | −$926.04 |
| long | 2 Jul 2026 60,024.00 | 8 Jul 2026 63,364.00 | 6 | $149.27 |
| short | 8 Jul 2026 63,364.00 | 3 Aug 2026 63,570.00 | 26 | −$11.64 |
| long | 3 Aug 2026 63,570.00 | 8 Sep 2026 79,112.00 | 36 | $697.02 |
| short | 8 Sep 2026 79,112.00 | 11 Oct 2026 82,988.40 | 33 | −$177.28 |
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 Scalping Strategy this page | — | v4 strategy | −66.2% | 41 | 73.0% |
| Positive Bars - Strategy by tweakerID | lowest highest valuewhen atr | v4 strategy | −40.3% | 7 | 54.7% |
| Big Bar Strategy by tweakerID | lowest highest valuewhen atr | v4 strategy | −56.6% | 13 | 57.1% |
| SuperTrend Multi Time Frame Long and Short Trading Strategy by ranga_technologies | atr highest lowest valuewhen | v5 strategy | No trades on this market | ||
| Inside Bar Strategy w- SL by tweakerID | lowest highest valuewhen atr | v4 strategy | −61.3% | 25 | 65.0% |
| Modulo Logic + EMA Strat by tweakerID | lowest highest valuewhen atr | v4 strategy | −50.8% | 16 | 54.7% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 27 ms | Yes 1,000 bars in 78 ms | Not measured |
| PineTS | No v5 and v6 only | — | 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. 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/// © tweakerID// ---From the "Bitcoin Trading Strategies" book, by David Hanson---// After testing, works better with an ATR stop instead of the Strategy Stop. This paramater// can be changed from the strategy Inputs panel.// "CCI Scalping Strategy// Recommended Timeframe: 5 minutes// Indicators: 20 Period CCI, 20 WMA// Long when: Price closes above 20 WMA and CCI is below -100, enter when CCI crosses above -100.// Stop: Above 20 WMA"//@version=4strategy("CCI Scalping Strat", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=10000, commission_value=0.04, calc_on_every_tick=false, slippage=0)direction = input(0, title = "Strategy Direction", type=input.integer, minval=-1, maxval=1)strategy.risk.allow_entry_in(direction == 0 ? strategy.direction.all : (direction < 0 ? strategy.direction.short : strategy.direction.long))/////////////////////// STRATEGY INPUTS ////////////////////////////////////////title1=input(true, "-----------------Strategy Inputs-------------------") i_Stop = input(0, step=.05, title="Strategy Stop Mult")*.01i_CCI=input(16, title="CCI Length")i_WMA=input(5, title="WMA Length")/////////////////////// BACKTESTER /////////////////////////////////////////////title2=input(true, "-----------------General Inputs-------------------") // Backtester General Inputsi_SL=input(true, title="Use Stop Loss and Take Profit")i_SLType=input(defval="ATR Stop", title="Type Of Stop", options=["Strategy Stop", "Swing Lo/Hi", "ATR Stop"])i_SPL=input(defval=10, title="Swing Point Lookback")i_PercIncrement=input(defval=2, step=.1, title="Swing Point SL Perc Increment")*0.01i_ATR = input(14, title="ATR Length")i_ATRMult = input(10, step=.1, title="ATR Multiple")i_TPRRR = input(1.5, step=.1, title="Take Profit Risk Reward Ratio")// Bought and Sold Boolean Signalbought = strategy.position_size > strategy.position_size[1] or strategy.position_size < strategy.position_size[1]// Price Action Stop and Take ProfitLL=(lowest(i_SPL))*(1-i_PercIncrement)HH=(highest(i_SPL))*(1+i_PercIncrement)LL_price = valuewhen(bought, LL, 0)HH_price = valuewhen(bought, HH, 0)entry_LL_price = strategy.position_size > 0 ? LL_price : na entry_HH_price = strategy.position_size < 0 ? HH_price : na tp=strategy.position_avg_price + (strategy.position_avg_price - entry_LL_price)*i_TPRRRstp=strategy.position_avg_price - (entry_HH_price - strategy.position_avg_price)*i_TPRRR// ATR StopATR=atr(i_ATR)*i_ATRMultATRLong = ohlc4 - ATRATRShort = ohlc4 + ATRATRLongStop = valuewhen(bought, ATRLong, 0)ATRShortStop = valuewhen(bought, ATRShort, 0)LongSL_ATR_price = strategy.position_size > 0 ? ATRLongStop : na ShortSL_ATR_price = strategy.position_size < 0 ? ATRShortStop : na ATRtp=strategy.position_avg_price + (strategy.position_avg_price - LongSL_ATR_price)*i_TPRRRATRstp=strategy.position_avg_price - (ShortSL_ATR_price - strategy.position_avg_price)*i_TPRRR/////////////////////// STRATEGY LOGIC ///////////////////////////////////////////CCICCI=cci(close, i_CCI)//WMAWMA=wma(close, i_WMA)//StopsLongStop=valuewhen(bought, WMA, 0)*(1-i_Stop)ShortStop=valuewhen(bought, WMA, 0)*(1+i_Stop)StratTP=strategy.position_avg_price + (strategy.position_avg_price - LongStop)*i_TPRRRStratSTP=strategy.position_avg_price - (ShortStop - strategy.position_avg_price)*i_TPRRRBUY = (close > WMA) and crossover(CCI , -100)SELL = (close < WMA) and crossunder(CCI , 100)//Trading InputsDPR=input(true, "Allow Direct Position Reverse")reverse=input(false, "Reverse Trades")// Entriesif reverse if not DPR strategy.entry("long", strategy.long, when=SELL and strategy.position_size == 0) strategy.entry("short", strategy.short, when=BUY and strategy.position_size == 0) else strategy.entry("long", strategy.long, when=SELL) strategy.entry("short", strategy.short, when=BUY)else if not DPR strategy.entry("long", strategy.long, when=BUY and strategy.position_size == 0) strategy.entry("short", strategy.short, when=SELL and strategy.position_size == 0) else strategy.entry("long", strategy.long, when=BUY) strategy.entry("short", strategy.short, when=SELL)SL= i_SLType == "Swing Lo/Hi" ? entry_LL_price : i_SLType == "ATR Stop" ? LongSL_ATR_price : LongStopSSL= i_SLType == "Swing Lo/Hi" ? entry_HH_price : i_SLType == "ATR Stop" ? ShortSL_ATR_price : ShortStopTP= i_SLType == "Swing Lo/Hi" ? tp : i_SLType == "ATR Stop" ? ATRtp : StratTPSTP= i_SLType == "Swing Lo/Hi" ? stp : i_SLType == "ATR Stop" ? ATRstp : StratSTPstrategy.exit("TP & SL", "long", limit=TP, stop=SL, when=i_SL)strategy.exit("TP & SL", "short", limit=STP, stop=SSL, when=i_SL)/////////////////////// PLOTS //////////////////////////////////////////////////plot(WMA)plot(i_SL and strategy.position_size > 0 ? SL : na , title='SL', style=plot.style_cross, color=color.red)plot(i_SL and strategy.position_size < 0 ? SSL : na , title='SSL', style=plot.style_cross, color=color.red)plot(i_SL and strategy.position_size > 0 ? TP : na, title='TP', style=plot.style_cross, color=color.green)plot(i_SL and strategy.position_size < 0 ? STP : na, title='STP', style=plot.style_cross, color=color.green)// Draw price action setup arrowsplotshape(BUY ? 1 : na, style=shape.triangleup, location=location.belowbar, color=color.green, title="Bullish Setup", size=size.auto)plotshape(SELL ? 1 : na, style=shape.triangledown, location=location.abovebar, color=color.red, title="Bearish Setup", size=size.auto)