Zeal Terminal Open in Zeal Terminal

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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (3)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$1,002,700$2,025,273Equity from $1,000,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots. 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.
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.

SettingDefaultType and rangeFeeds
Smooth EMA length100int · min 50 · max 200 · step 10ema emasmooth
Return (%)5float · min 5 · max 100 · step 5longtarget shorttarget
Risk (%)3float · min 1 · max 10 · step 1unused

What it calculates

  • EMAclose, Smooth EMA length (100)ema · line 9
  • EMAema, Smooth EMA length (100)emasmooth · line 10
  • EMAclose, 50ema2 · line 11
  • EMAema2, 50emasmooth2 · line 12
  • SMAvolume, 20volMA · line 13
  • SMAhlc3, 100ma1 · line 16
  • DEVhlc3, 100cci100 · line 17
  • SMAhlc3, 20ma2 · line 18
  • DEVhlc3, 20cci20 · 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.

closecloseprice dataemalenSmooth EMA lengthsetting · 100volumevolumeprice datahlc3hlc3price dataohlc4ohlc4price dataReturnReturn (%)setting · 5high · low · closehigh · low · closeprice datahighhighprice datalowlowprice dataopenopenprice dataemaEMA→ emaemasmoothEMA→ emasmoothema2EMA→ ema2emasmooth2EMA→ emasmooth2volMASMA→ volMAma1SMA→ ma1cci100DEV→ cci100ma2SMA→ ma2cci20DEV→ cci20sllong, slshortsllong · slshort2 valueslongtarget, shorttargetlongtarget · shorttarget2 valuesStopPriceStopPricevalueTargetPriceTargetPricevalueEntryPriceEntryPricevalueBuysignalBuysignalconditionSellsignalSellsignalconditionvolcheckvolcheckconditionBuyCond, SellCondBuyCond · SellCond2 conditionsentry:BUYOpen BUYstrategy.entryentry:SELLOpen SELLstrategy.entryexit:Exitexit Exitstrategy.exitplot:63Trailing stoploss longplotplot:64Trailing stoploss shortplotplot:65Candle nearest pointplotfill:66Fillfill × 2fill:67Fillfill × 2plotshape:69Bullish setupplotshapeplotshape:70Bearish setupplotshapeplot:72VWAPplot

Order rules

OrderFires whenBy defaultLine
Open BUY longBuysignalBuyCond and strategy.position_size == 0 and barstate.isconfirmedOn55
Open SELL shortSellsignalSellCond and strategy.position_size == 0 and barstate.isconfirmedOn56
Exit Exit stop and limitstrategy.position_size > 0On59
Exit Exit stop and limitstrategy.position_size < 0On61

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.

Not measuredAn engine gap, not the scriptThe 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. The answer comes from the checks on the source alone.
  • 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D+0.1%+102.5%1638%1.150.4%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+0.0%+5.5%1817%1.060.1%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+0.7%+9.8%1155%2.510.3%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+0.3%+8.4%1631%2.600.1%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+0.2%+16.7%1631%1.250.3%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.3%+21.5%1527%1.920.1%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+0.4%+148.3%1436%1.890.3%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+0.1%+17.1%1136%2.310.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 barsTradesWonP&L
Rising market333%−$887.75
Sideways market944%$3,571.72
Falling market425%−$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.

0%1%
All 16 trades
SideEntryExitBarsP&L
short7 Sep 2024 53,963.0014 Sep 2024 60,498.007−$1,211.02
long27 Sep 2024 65,174.002 Oct 2024 60,804.905−$669.56
long16 Oct 2024 67,074.1031 Dec 2024 92,792.1076$3,827.04
long7 Jan 2025 102,236.0010 Jan 2025 92,552.503−$948.98
long16 Jan 2025 100,497.003 Feb 2025 97,700.6018−$278.57
short11 Mar 2025 78,595.9022 Apr 2025 87,516.2042−$1,135.78
long23 Apr 2025 93,443.0022 Jun 2025 102,120.0060$928.20
long3 Jul 2025 108,850.003 Aug 2025 112,546.0031$339.80
long14 Aug 2025 123,306.0020 Aug 2025 112,873.006−$846.86
long13 Sep 2025 116,029.0023 Sep 2025 112,651.0010−$291.17
long4 Oct 2025 122,232.0011 Oct 2025 112,774.007−$773.53
short17 Oct 2025 108,194.0021 Oct 2025 110,532.004−$215.85
short5 Nov 2025 101,497.006 Jan 2026 93,859.7062$751.52
short26 Jan 2026 86,670.4016 Mar 2026 72,815.3049$1,597.76
short28 Mar 2026 66,407.308 Apr 2026 71,924.2011−$831.66
short2 Jun 2026 71,408.9021 Jul 2026 65,255.5049$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.

ScriptSharesTypeNetTradesMax drawdown
CCI & EMA strategy by Tradeswithashish this page—v5 strategy+0.1%160.4%
CCI + EMA with RSI Cross Strategy by rwestbrookjrema sma devv5 strategyNo trades on this market
MACD Long Strat by TheGrindTodayema smav4 strategy+24.0%7920.1%
Stock trending strategy by exlux99ema smav4 strategy+35.3%2114.7%
4-Hour Stochastic EMA Trend by slymnturkogluema smav4 strategyNo trades on this market
4X EMA and volume strategy by SoftKill21ema smav4 strategy+1.8%325.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.

Clean v5

VerifiedDownload the v5 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.

Download the v6 script

⋯//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

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 35 msWith a workaround 1,000 bars in 68 msNot measured
PineTSNot testedNot testedNot 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)