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
- 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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Smaller EMA length | 50 | int · min 30 · max 50 · step 5 | ema1 emasmooth1 |
| Longer EMA length | 100 | int · min 70 · max 200 · step 10 | ema2 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, 20
volMA · line 12 - RSIclose, 14
rsi · line 13 - ATR14
atr · 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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Buy long | BuysignalBuyCond and strategy.position_size == 0 and barstate.isconfirmed | On | 53 |
| Open Sell short | SellsignalSellCond and strategy.position_size == 0 and barstate.isconfirmed | On | 54 |
| Exit Exit stop and limit | strategy.position_size > 0 | On | 57 |
| Exit Exit stop and limit | strategy.position_size < 0 | On | 59 |
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 | +11.0% | +102.5% | 12 | 42% | 1.61 | 11.6% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | 0.0% | +5.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −4.3% | +9.8% | 9 | 33% | 0.86 | 17.6% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | 0.0% | +8.4% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +8.1% | +16.7% | 8 | 50% | 1.50 | 12.6% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | 0.0% | +21.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −5.9% | +148.3% | 14 | 36% | 0.81 | 15.1% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | 0.0% | +17.1% | 0 | 0% | — | 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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 4 | 25% | −$100,289.00 |
| Sideways market | 8 | 50% | $209,854.00 |
| Falling market | 0 | — | $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.
All 12 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 24 Aug 2024 64,037.20 | 28 Aug 2024 59,415.00 | 4 | −$36,090.20 |
| long | 29 Oct 2024 69,962.20 | 30 Dec 2024 93,738.20 | 62 | $163,788.00 |
| long | 7 Jan 2025 102,236.00 | 8 Jan 2025 96,954.60 | 1 | −$29,125.70 |
| long | 16 Jan 2025 100,497.00 | 25 Feb 2025 91,552.90 | 40 | −$48,887.60 |
| short | 4 Mar 2025 86,221.20 | 5 Mar 2025 87,282.00 | 1 | −$6,457.42 |
| short | 29 Mar 2025 84,424.40 | 10 Apr 2025 82,615.20 | 12 | $11,177.80 |
| long | 23 Apr 2025 93,443.00 | 6 Jun 2025 101,509.00 | 44 | $45,506.40 |
| long | 10 Jun 2025 110,263.00 | 18 Jun 2025 104,551.00 | 8 | −$28,488.80 |
| long | 3 Jul 2025 108,850.00 | 26 Aug 2025 110,112.00 | 54 | $6,212.94 |
| long | 11 Sep 2025 113,960.00 | 26 Sep 2025 108,994.00 | 15 | −$23,477.60 |
| long | 30 Sep 2025 114,312.00 | 11 Oct 2025 112,774.00 | 11 | −$7,089.14 |
| short | 4 Nov 2025 106,583.00 | 6 Jan 2026 93,859.70 | 63 | $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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| EMA crossover (daily TF) this page | — | v5 strategy | +11.0% | 12 | 11.6% |
| 3 x EMA + Stochastic RSI + ATR by tomimarson | ema rsi sma atr | v4 strategy | −42.3% | 18 | 44.8% |
| Atrend by OTS by prim722 | ema rsi sma atr | v4 strategy | +12.1% | 76 | 34.4% |
| Delta-RSI Strategy (with filters) by tbiktag | rsi ema atr sma | v4 strategy | −28.8% | 71 | 83.8% |
| [KL] Bollinger bands + RSI Strategy by DojiEmoji | sma atr ema rsi | v4 strategy | +28.2% | 30 | 14.7% |
| 3x Supertrend and Stoch RSI by M3RZI | rsi sma ema atr | v4 strategy | −128.7% | 24 | 207.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.
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.
⋯//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
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 40 ms | With a workaround 1,000 bars in 64 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 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)