Pine Script v5 · Strategy
CCI & EMA strategy by Tradeswithashish
A Pine Script v5 strategy built on EMA (close, 100), SMA (volume, 20) and DEV (hlc3, 100). It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade commits 1% of equity and pays no commission. 3 settings; defaults include Smooth EMA length 100, Return (%) 5 and Risk (%) 3.
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 strategy by Tradeswithashish repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: the script acts only when barstate.isconfirmed is true, which Zeal Terminal's engine never reports during a live replay (it does not run a bar's closing update in live mode), so the replay cannot test this script.
- How did CCI & EMA strategy by Tradeswithashish do on BTCUSDT 1D with default settings?
- +0.11%
- From 26 Jan 2024 to 21 Oct 2026, over 16 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does CCI & EMA strategy by Tradeswithashish run in Pine Script v6?
- Yes
- Same 16 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. The v6 script can be downloaded below.
- Does CCI & EMA strategy by Tradeswithashish use a stop loss?
- Yes
- strategy.exit sets a stop on line 59, 61.
- Does CCI & EMA strategy by Tradeswithashish run in Zeal Terminal?
- Yes
- It compiles in 35 ms and runs 1,000 bars in 68 ms, in the browser.
BTCUSDT · 1D · default settings
- Trailing stoploss long
- Trailing stoploss short
- Candle nearest point
- Bullish setup
- Bearish setup
- VWAP
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +0.11%
- $1,103.26
- Buy and hold
- +102.5%
- same period
- Closed trades
- 16
- 6 won · 10 lost
- Profitable
- 37.5%
- of closed trades
- Profit factor
- 1.15
- gross profit ÷ gross loss
- Max drawdown
- 0.39%
- −$3,888.12
One run with the author's default settings, $1,000,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.
-
Likely bug
ta.ema(close, 50) ignores the settings line 11
Line 11 hard-codes 50 where line 9 uses “Smooth EMA length”. Changing those settings moves one band but not this one.
ta.ema(close, 50)ta.ema(close, emalen) -
Likely bug
ta.ema(ema2, 50) ignores the settings line 12
Line 12 hard-codes 50 where line 9 uses “Smooth EMA length”. Changing those settings moves one band but not this one.
ta.ema(ema2, 50)ta.ema(ema2, emalen) -
Check
1 setting does nothing
“Risk (%)” is declared but never read.
-
Check
No commission
The backtest assumes free trading. Results on any real exchange will be lower.
-
Check
Every trade uses all the equity
default_qty_value is 100% of equity.
-
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 55, 56, 59, 61. 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 |
|---|---|---|---|
| Smooth EMA length | 100 | int · min 50 · max 200 · step 10 | ema emasmooth |
| Return (%) | 5 | float · min 5 · max 100 · step 5 | longtarget shorttarget |
| Risk (%) | 3 | float · min 1 · max 10 · step 1 | unused |
What it calculates
- EMAclose, Smooth EMA length (100)
ema · line 9 - EMAema, Smooth EMA length (100)
emasmooth · line 10 - EMAclose, 50
ema2 · line 11 - EMAema2, 50
emasmooth2 · line 12 - SMAvolume, 20
volMA · line 13 - SMAhlc3, 100
ma1 · line 16 - DEVhlc3, 100
cci100 · line 17 - SMAhlc3, 20
ma2 · line 18 - DEVhlc3, 20
cci20 · line 19
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 BUY long | BuysignalBuyCond and strategy.position_size == 0 and barstate.isconfirmed | On | 55 |
| Open SELL short | SellsignalSellCond and strategy.position_size == 0 and barstate.isconfirmed | On | 56 |
| Exit Exit stop and limit | strategy.position_size > 0 | On | 59 |
| Exit Exit stop and limit | strategy.position_size < 0 | On | 61 |
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.1% | +102.5% | 16 | 38% | 1.15 | 0.4% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +0.0% | +5.5% | 18 | 17% | 1.06 | 0.1% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +0.7% | +9.8% | 11 | 55% | 2.51 | 0.3% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +0.3% | +8.4% | 16 | 31% | 2.60 | 0.1% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +0.2% | +16.7% | 16 | 31% | 1.25 | 0.3% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.3% | +21.5% | 15 | 27% | 1.92 | 0.1% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +0.4% | +148.3% | 14 | 36% | 1.89 | 0.3% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +0.1% | +17.1% | 11 | 36% | 2.31 | 0.1% | 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 | 3 | 33% | −$887.75 |
| Sideways market | 9 | 44% | $3,571.72 |
| Falling market | 4 | 25% | −$1,580.71 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
0.6%
The 95th percentile of the worst drawdown when the same 16 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 0.2% to 0.6%; the tick is what actually happened, 0.3%. Order luck alone moves it this much.
All 16 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 7 Sep 2024 53,963.00 | 14 Sep 2024 60,498.00 | 7 | −$1,211.02 |
| long | 27 Sep 2024 65,174.00 | 2 Oct 2024 60,804.90 | 5 | −$669.56 |
| long | 16 Oct 2024 67,074.10 | 31 Dec 2024 92,792.10 | 76 | $3,827.04 |
| long | 7 Jan 2025 102,236.00 | 10 Jan 2025 92,552.50 | 3 | −$948.98 |
| long | 16 Jan 2025 100,497.00 | 3 Feb 2025 97,700.60 | 18 | −$278.57 |
| short | 11 Mar 2025 78,595.90 | 22 Apr 2025 87,516.20 | 42 | −$1,135.78 |
| long | 23 Apr 2025 93,443.00 | 22 Jun 2025 102,120.00 | 60 | $928.20 |
| long | 3 Jul 2025 108,850.00 | 3 Aug 2025 112,546.00 | 31 | $339.80 |
| long | 14 Aug 2025 123,306.00 | 20 Aug 2025 112,873.00 | 6 | −$846.86 |
| long | 13 Sep 2025 116,029.00 | 23 Sep 2025 112,651.00 | 10 | −$291.17 |
| long | 4 Oct 2025 122,232.00 | 11 Oct 2025 112,774.00 | 7 | −$773.53 |
| short | 17 Oct 2025 108,194.00 | 21 Oct 2025 110,532.00 | 4 | −$215.85 |
| short | 5 Nov 2025 101,497.00 | 6 Jan 2026 93,859.70 | 62 | $751.52 |
| short | 26 Jan 2026 86,670.40 | 16 Mar 2026 72,815.30 | 49 | $1,597.76 |
| short | 28 Mar 2026 66,407.30 | 8 Apr 2026 71,924.20 | 11 | −$831.66 |
| short | 2 Jun 2026 71,408.90 | 21 Jul 2026 65,255.50 | 49 | $861.92 |
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 strategy by Tradeswithashish this page | — | v5 strategy | +0.1% | 16 | 0.4% |
| CCI + EMA with RSI Cross Strategy by rwestbrookjr | ema sma dev | v5 strategy | No trades on this market | ||
| MACD Long Strat by TheGrindToday | ema sma | v4 strategy | +24.0% | 79 | 20.1% |
| Stock trending strategy by exlux99 | ema sma | v4 strategy | +35.3% | 21 | 14.7% |
| 4-Hour Stochastic EMA Trend by slymnturkoglu | ema sma | v4 strategy | No trades on this market | ||
| 4X EMA and volume strategy by SoftKill21 | ema sma | v4 strategy | +1.8% | 3 | 25.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 55, 56, 59, 61). 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.
Same 16 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 55: when = Buysignal → if block
- Line 56: when = Sellsignal → if block
- Line 59: when = strategy.position_size > 0 → if block
- Line 61: when = strategy.position_size < 0 → if block
⋯//enter trades whenever there is signal-strategy.entry(id='BUY', direction=strategy.long, when=Buysignal, alert_message='Buy signal given')+if Buysignal+ strategy.entry(id='BUY', direction=strategy.long, alert_message='Buy signal given')-strategy.entry(id='SELL', direction=strategy.short, when=Sellsignal, alert_message='Sell signal given')+if Sellsignal+ strategy.entry(id='SELL', direction=strategy.short, alert_message='Sell signal given')//Exit entriesif cci100 < 0 or close < emasmooth or close < ema2- strategy.exit(id='Exit', from_entry='BUY', limit=TargetPrice, stop=StopPrice, when=strategy.position_size > 0, alert_message='Long entry closed')+ if strategy.position_size > 0+ strategy.exit(id='Exit', from_entry='BUY', limit=TargetPrice, stop=StopPrice, alert_message='Long entry closed')if cci100 > 0 or close > emasmooth or close > ema2- strategy.exit(id='Exit', from_entry='SELL', limit=TargetPrice, stop=StopPrice, when=strategy.position_size < 0, alert_message='Short entry closed')+ if strategy.position_size < 0+ strategy.exit(id='Exit', from_entry='SELL', limit=TargetPrice, stop=StopPrice, alert_message='Short entry closed')//Draw trade data⋯Does it run in Pine Script v6?
Yes
Same 16 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. It differs from the v5 version by 1 edit.
⋯//This strategy is excellent in timeperiod above 15min. So use it carefully-//@version=5+//@version=6//This strategy can be used for daily entry for positional trading⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 35 ms | With a workaround 1,000 bars in 68 ms | Not measured |
| PineTS | Not tested | Not tested | Not measured |
Zeal Terminal's engine currently reads an order side written as direction = strategy.long, direction = strategy.short as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 55, 56) so the engine trades the way the script says.
“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///This strategy is excellent in timeperiod above 15min. So use it carefully//@version=5//This strategy can be used for daily entry for positional tradingstrategy('CCI & EMA strategy by Tradeswithashish', shorttitle='CC-EMA by tradeswithashish', overlay=true, default_qty_type=strategy.percent_of_equity, initial_capital=1000000)emalen = input.int(title='Smooth EMA length', defval=100, minval=50, maxval=200, step=10)Return = input.float(title='Return (%)', defval=5, minval=5, maxval=100, step=5)Risk = input.float(title='Risk (%)', defval=3, minval=1, maxval=10, step=1)ema = ta.ema(close, emalen)emasmooth = ta.ema(ema, emalen)ema2 = ta.ema(close, 50)emasmooth2 = ta.ema(ema2, 50)volMA = ta.sma(volume, 20)volcheck = volume > volMA//fidning CCI-100 and CCI-20 values valuema1 = ta.sma(hlc3, 100)cci100 = (hlc3 - ma1) / (0.015 * ta.dev(hlc3, 100))ma2 = ta.sma(hlc3, 20)cci20 = (hlc3 - ma2) / (0.015 * ta.dev(hlc3, 20))//conditions for short and long entriesBuyCond = close > emasmooth and close > open and volcheck and cci100 > 0 and cci20 > 100 and close > ta.vwap and barstate.isconfirmed and (close - low) / (high - low) > 0.6 and volume > volume[1]SellCond = close < emasmooth and close < open and volcheck and cci100 < 0 and cci20 < -100 and close < ta.vwap and barstate.isconfirmed and (close - low) / (high - low) < 0.4 and volume > volume[1]//Buy and Sell SignalsBuysignal = BuyCond and strategy.position_size == 0 and barstate.isconfirmedSellsignal = SellCond and strategy.position_size == 0 and barstate.isconfirmed//settingup stoplosssllong = math.max(ema2, emasmooth)slshort = math.min(ema2, emasmooth)//Setting up Targetslongtarget = ohlc4 * (1 + Return / 100)shorttarget = ohlc4 * (1 - Return / 100)//Save SLs and Target pricesvar StopPrice = 0.0var TargetPrice = 0.0var EntryPrice = 0.0//Detect Valid long setup and trigger alertsif Buysignal StopPrice := sllong EntryPrice := ohlc4 TargetPrice := longtarget TargetPriceif Sellsignal StopPrice := slshort TargetPrice := shorttarget EntryPrice := ohlc4 EntryPrice//Trailing Stoplossesif strategy.position_size > 0 StopPrice := math.max(StopPrice, ema2, emasmooth) StopPriceif strategy.position_size < 0 StopPrice := math.min(StopPrice, ema2, emasmooth) StopPrice//enter trades whenever there is signalstrategy.entry(id='BUY', direction=strategy.long, when=Buysignal, alert_message='Buy signal given')strategy.entry(id='SELL', direction=strategy.short, when=Sellsignal, alert_message='Sell signal given')//Exit entriesif cci100 < 0 or close < emasmooth or close < ema2 strategy.exit(id='Exit', from_entry='BUY', limit=TargetPrice, stop=StopPrice, when=strategy.position_size > 0, alert_message='Long entry closed')if cci100 > 0 or close > emasmooth or close > ema2 strategy.exit(id='Exit', from_entry='SELL', limit=TargetPrice, stop=StopPrice, when=strategy.position_size < 0, alert_message='Short entry closed')//Draw trade datastoplong = plot(strategy.position_size > 0 or Buysignal or Sellsignal ? StopPrice : na, title='Trailing stoploss long', color=color.new(color.red, 80), style=plot.style_linebr, linewidth=1)stopshort = plot(strategy.position_size < 0 or Sellsignal ? StopPrice : na, title='Trailing stoploss short', color=color.new(color.red, 80), style=plot.style_linebr, linewidth=1)candlenearest = plot(strategy.position_size < 0 ? high : strategy.position_size > 0 ? low : na, title='Candle nearest point', color=color.new(color.green, 80), style=plot.style_linebr, linewidth=1)fill(stoplong, candlenearest, color=color.new(color.green, 80))fill(stopshort, candlenearest, color=color.new(color.red, 80))//Draw Price action arrowplotshape(Buysignal ? 1 : na, style=shape.triangleup, location=location.belowbar, color=color.new(color.green, 0), title='Bullish setup', size=size.small)plotshape(Sellsignal ? 1 : na, style=shape.triangledown, location=location.abovebar, color=color.new(color.red, 0), title='Bearish setup', size=size.small)//Plot emasmooth and vwapplot(ta.vwap, title='VWAP', color=color.new(color.black, 0), linewidth=2, show_last=75)