Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

EMA crossover (daily TF)

A Pine Script v5 strategy built on EMA (close, 50), SMA (volume, 20) and RSI (close, 14). 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 50% of equity and pays no commission. 2 settings; defaults include Smaller EMA length 50 and Longer EMA length 100.

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 EMA crossover (daily TF) 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 EMA crossover (daily TF) do on BTCUSDT 1D with default settings?
+10.96%
From 26 Jan 2024 to 21 Oct 2026, over 12 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Does EMA crossover (daily TF) run in Pine Script v6?
Yes
Same 12 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 EMA crossover (daily TF) use a stop loss?
Yes
strategy.exit sets a stop on line 57, 59.
Does EMA crossover (daily TF) run in Zeal Terminal?
Yes
It compiles in 40 ms and runs 1,000 bars in 64 ms, in the browser.

BTCUSDT · 1D · default settings

  • TSL long
  • TSL short
  • Candle nearest point
  • Long setup
  • Long setup
  • Smaller EMA
  • Longer EMA
  • 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 (2)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$1,109,560$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 53, 54) so the engine trades the way the script says. 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.
Net profit
+10.96%
$109,565.00
Buy and hold
+102.5%
same period
Closed trades
12
5 won · 7 lost
Profitable
41.7%
of closed trades
Profit factor
1.61
gross profit ÷ gross loss
Max drawdown
11.56%
−$130,309.00

One run with the author's default settings, $1,000,000 starting capital, commission as the script sets it. A single backtest says little about future results and is not a recommendation. Backtests are simulations on historical data and are not investment advice.

Review

What a careful reader of this script would point out, found by checking the source and the backtest.

  • 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.

  • Note

    Uses an argument v6 removed

    when = on line 53, 54, 57, 59. 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
Smaller EMA length50int · min 30 · max 50 · step 5ema1 emasmooth1
Longer EMA length100int · min 70 · max 200 · step 10ema2 emasmooth2

What it calculates

  • EMAclose, Smaller EMA length (50)ema1 · line 8
  • EMAema1, Smaller EMA length (50)emasmooth1 · line 9
  • EMAclose, Longer EMA length (100)ema2 · line 10
  • EMAema2, Longer EMA length (100)emasmooth2 · line 11
  • SMAvolume, 20volMA · line 12
  • RSIclose, 14rsi · line 13
  • ATR14atr · line 14

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 dataemalen1Smaller EMA lengthsetting · 50emalen2Longer EMA lengthsetting · 100volumevolumeprice datahigh · low · closehigh · low · closeprice datalowlowprice datahighhighprice dataopenopenprice dataohlc4ohlc4price dataema1EMA→ ema1emasmooth1EMA→ emasmooth1ema2EMA→ ema2emasmooth2EMA→ emasmooth2volMASMA→ volMArsiRSI→ rsiatrATR→ atrbodyperbodypervaluedailytimeframedailytimeframevaluesllong, slshortsllong · slshort2 valuesStopPriceStopPricevalueTargetPriceTargetPricevalueEntryPriceEntryPricevalueBuysignalBuysignalconditionSellsignalSellsignalconditionclosebull, closebearclosebull · closebear2 conditionsvolcheckvolcheckconditionBuyCondBuyCondconditionSellCondSellCondconditionentry:BuyOpen Buystrategy.entryentry:SellOpen Sellstrategy.entryexit:Exitexit Exitstrategy.exitplot:61TSL longplotplot:62TSL shortplotplot:64Candle nearest pointplotfill:65Fillfill × 2fill:66Fillfill × 2plotshape:68Long setupplotshapeplotshape:69Long setupplotshapeplot:71Smaller EMAplotplot:72Longer EMAplot

Order rules

OrderFires whenBy defaultLine
Open Buy longBuysignalBuyCond and strategy.position_size == 0 and barstate.isconfirmedOn53
Open Sell shortSellsignalSellCond and strategy.position_size == 0 and barstate.isconfirmedOn54
Exit Exit stop and limitstrategy.position_size > 0On57
Exit Exit stop and limitstrategy.position_size < 0On59

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+11.0%+102.5%1242%1.6111.6%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h0.0%+5.5%00%—0.0%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−4.3%+9.8%933%0.8617.6%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h0.0%+8.4%00%—0.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+8.1%+16.7%850%1.5012.6%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h0.0%+21.5%00%—0.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−5.9%+148.3%1436%0.8115.1%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h0.0%+17.1%00%—0.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 barsTradesWonP&L
Rising market425%−$100,289.00
Sideways market850%$209,854.00
Falling market0—$0.00

Rising and falling mean the market moved more than 15% over the 90 bars before entry.

How bad could the drawdown be?

14.2%

The 95th percentile of the worst drawdown when the same 12 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 6.1% to 14.2%; the tick is what actually happened, 7.5%. Order luck alone moves it this much.

0%16%
All 12 trades
SideEntryExitBarsP&L
long24 Aug 2024 64,037.2028 Aug 2024 59,415.004−$36,090.20
long29 Oct 2024 69,962.2030 Dec 2024 93,738.2062$163,788.00
long7 Jan 2025 102,236.008 Jan 2025 96,954.601−$29,125.70
long16 Jan 2025 100,497.0025 Feb 2025 91,552.9040−$48,887.60
short4 Mar 2025 86,221.205 Mar 2025 87,282.001−$6,457.42
short29 Mar 2025 84,424.4010 Apr 2025 82,615.2012$11,177.80
long23 Apr 2025 93,443.006 Jun 2025 101,509.0044$45,506.40
long10 Jun 2025 110,263.0018 Jun 2025 104,551.008−$28,488.80
long3 Jul 2025 108,850.0026 Aug 2025 110,112.0054$6,212.94
long11 Sep 2025 113,960.0026 Sep 2025 108,994.0015−$23,477.60
long30 Sep 2025 114,312.0011 Oct 2025 112,774.0011−$7,089.14
short4 Nov 2025 106,583.006 Jan 2026 93,859.7063$62,496.80

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
EMA crossover (daily TF) this page—v5 strategy+11.0%1211.6%
3 x EMA + Stochastic RSI + ATR by tomimarsonema rsi sma atrv4 strategy−42.3%1844.8%
Atrend by OTS by prim722ema rsi sma atrv4 strategy+12.1%7634.4%
Delta-RSI Strategy (with filters) by tbiktagrsi ema atr smav4 strategy−28.8%7183.8%
[KL] Bollinger bands + RSI Strategy by DojiEmojisma atr ema rsiv4 strategy+28.2%3014.7%
3x Supertrend and Stoch RSI by M3RZIrsi sma ema atrv4 strategy−128.7%24207.6%

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 53, 54, 57, 59). 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 12 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 53: when = Buysignal → if block
  • Line 54: when = Sellsignal → if block
  • Line 57: when = strategy.position_size > 0 → if block
  • Line 59: 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 close < StopPrice-    strategy.exit(id='Exit', from_entry='Buy', limit=TargetPrice, stop=StopPrice, when=strategy.position_size > 0, alert_message='Long closed')+    if strategy.position_size > 0+        strategy.exit(id='Exit', from_entry='Buy', limit=TargetPrice, stop=StopPrice, alert_message='Long closed')if close > StopPrice-    strategy.exit(id='Exit', from_entry='Sell', limit=TargetPrice, stop=StopPrice, when=strategy.position_size < 0, alert_message='Short closed')+    if strategy.position_size < 0+        strategy.exit(id='Exit', from_entry='Sell', limit=TargetPrice, stop=StopPrice, alert_message='Short closed')//Draw trade data⋯

Does it run in Pine Script v6?

Yes

Same 12 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 useful for positional trading-//@version=5+//@version=6//This strategy can be used for daily entry for positional trading⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 40 msWith a workaround 1,000 bars in 64 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 53, 54) so the engine trades the way the script says. 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.

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 useful for positional trading//@version=5//This strategy can be used for daily entry for positional tradingstrategy('EMA crossover (daily timeframe)', shorttitle='EMA crossver (daily timeframe)', overlay=true, default_qty_value=50, default_qty_type=strategy.percent_of_equity, initial_capital=1000000)emalen1 = input.int(title='Smaller EMA length', defval=50, minval=30, maxval=50, step=5)emalen2 = input.int(title='Longer EMA length', defval=100, minval=70, maxval=200, step=10)ema1 = ta.ema(close, emalen1)emasmooth1 = ta.ema(ema1, emalen1)ema2 = ta.ema(close, emalen2)emasmooth2 = ta.ema(ema2, emalen2)volMA = ta.sma(volume, 20)rsi = ta.rsi(close, 14)atr = ta.atr(14)bodyper = close > open ? (close - open) / (high - low) : (open - close) / (high - low)closebull = close > emasmooth1 and close > emasmooth2 and close > open and bodyper > 0.6closebear = close < emasmooth1 and close < emasmooth2 and close < open and bodyper > 0.6volcheck = volume > volMAdailytimeframe = timeframe.isdailyBuyCond = dailytimeframe and closebull and volcheck and rsi > 50 and emasmooth1 > emasmooth2 and volume > volume[1] and close > openSellCond = dailytimeframe and closebear and volcheck and rsi < 50 and emasmooth1 > emasmooth2 and volume > volume[1] and close < open//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(math.min(low, low[1]), emasmooth2)slshort = math.min(math.max(low, low[1]), emasmooth2)//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 := EntryPrice + 10 * (ohlc4 - StopPrice)    TargetPriceif Sellsignal    StopPrice := slshort    EntryPrice := ohlc4    TargetPrice := EntryPrice - 10 * (StopPrice - ohlc4)    TargetPrice//Trailing Stoplossesif strategy.position_size > 0 and volume > volMA and close > open and close > 1.10 * EntryPrice    StopPrice := StopPrice * 1.05    EntryPrice := 1.05 * EntryPrice    EntryPriceif strategy.position_size < 0 and volume > volMA and close < open and close < 0.90 * EntryPrice    StopPrice := 0.95 * StopPrice    EntryPrice := 0.95 * EntryPrice    EntryPrice//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 close < StopPrice    strategy.exit(id='Exit', from_entry='Buy', limit=TargetPrice, stop=StopPrice, when=strategy.position_size > 0, alert_message='Long closed')if close > StopPrice    strategy.exit(id='Exit', from_entry='Sell', limit=TargetPrice, stop=StopPrice, when=strategy.position_size < 0, alert_message='Short closed')//Draw trade datastoplong = plot(strategy.position_size > 0 or Buysignal ? StopPrice : na, title='TSL long', color=color.new(color.black, 0), style=plot.style_linebr, linewidth=1)stopshort = plot(strategy.position_size < 0 or Sellsignal ? StopPrice : na, title='TSL short', color=color.new(color.black, 0), style=plot.style_linebr, linewidth=1)//plot(strategy.position_size!=0?EntryPrice:na, title="EntryPrice", color=color.black, 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.labelup, location=location.belowbar, color=color.new(color.green, 0), title='Long setup', size=size.small)plotshape(Sellsignal ? 1 : na, style=shape.labeldown, location=location.abovebar, color=color.new(color.red, 0), title='Long setup', size=size.small)//Plot emasmooth and vwapplot(emasmooth1, title='Smaller EMA', color=color.new(color.green, 0), linewidth=2)plot(emasmooth2, title='Longer EMA', color=color.new(color.red, 0), linewidth=2)