Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Equal-Length EMA-SMA Crossover Momentum Strategy

A Pine Script v4 strategy built on EMA (close, 50), SMA (close, 50) and Crossunder (ema, sma). It has 2 order rules, 1 entry among them, and trades long only with the default settings. Exits wait for a signal; there is no stop loss. Each trade commits 25% of equity and pays 0.2% commission. 5 settings; defaults include Momentum Length (EMA=SMA) 50, Golden Cross Length (Fast) 50 and Golden Cross Length (Slow) 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 Equal-Length EMA-SMA Crossover Momentum Strategy repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 2 of 2 trades.
How did Equal-Length EMA-SMA Crossover Momentum Strategy do on BTCUSDT 1D with default settings?
+10.08%
From 26 Jan 2024 to 21 Oct 2026, over 6 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can Equal-Length EMA-SMA Crossover Momentum 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 Equal-Length EMA-SMA Crossover Momentum Strategy use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does Equal-Length EMA-SMA Crossover Momentum Strategy run in Zeal Terminal?
Yes
It compiles in 12 ms and runs 1,000 bars in 38 ms, in the browser.

BTCUSDT · 1D · default settings

  • Trend Buy
  • Risky Buy
  • Late Buy
  • Sell
  • 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 (5)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$11,008$20,253Equity from $10,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. 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.08%
$1,007.98
Buy and hold
+102.5%
same period
Closed trades
6
3 won · 3 lost
Profitable
50.0%
of closed trades
Profit factor
4.32
gross profit ÷ gross loss
Max drawdown
2.83%
−$286.62

One run with the author's default settings, $10,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 stop loss

    Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.

  • 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 30. 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 ema → ta.ema, sma → ta.sma, crossover → ta.crossover, crossunder → ta.crossunder.
  • 1 strategy call uses the when = argument (line 30). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

Same 6 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 3: //@version=4 → //@version=5
  • Line 10: ema → ta.ema
  • Line 11: sma → ta.sma
  • Line 12: sma → ta.sma
  • Line 13: sma → ta.sma
  • Line 15: crossover → ta.crossover
4 more edits
  • Line 16: crossover → ta.crossover
  • Line 17: crossover → ta.crossover
  • Line 18: crossunder → ta.crossunder
  • Line 29: crossunder → ta.crossunder
⋯// © Cryptoluc1d-//@version=4+//@version=5strategy("Equal-Length EMA/SMA Crossover Strategy", initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=25, commission_type=strategy.commission.percent, commission_value=0.2, overlay=true)⋯// Define MAs-ema = ema(close, mom_length) // EMA/SMA crossover of the same period for detecting trend acceleration/deceleration+ema = ta.ema(close, mom_length) // EMA/SMA crossover of the same period for detecting trend acceleration/deceleration-sma = sma(close, mom_length)+sma = ta.sma(close, mom_length)-bias_fast = sma(close, bias_length_fast) // golden/death cross for overall trend bias+bias_fast = ta.sma(close, bias_length_fast) // golden/death cross for overall trend bias-bias_slow = sma(close, bias_length_slow)+bias_slow = ta.sma(close, bias_length_slow)// Define signal conditions-buy_trend = crossover(ema, sma) and bias_fast >= bias_slow // buy when EMA cross above SMA. if this happens during a bullish golden cross, buying is in confluence with the overall trend (bias).+buy_trend = ta.crossover(ema, sma) and bias_fast >= bias_slow // buy when EMA cross above SMA. if this happens during a bullish golden cross, buying is in confluence with the overall trend (bias).-buy_risky = crossover(ema, sma) and bias_fast < bias_slow // buy when EMA cross above SMA. if this happens during a bearish death cross, buying is early, more risky, and not in confluence with the overall trend (bias).+buy_risky = ta.crossover(ema, sma) and bias_fast < bias_slow // buy when EMA cross above SMA. if this happens during a bearish death cross, buying is early, more risky, and not in confluence with the overall trend (bias).-buy_late = crossover(sma, bias_slow) and ema > sma // the SMA crossing the Slow_SMA gives further confirmation of bullish trend, but signal comes later.+buy_late = ta.crossover(sma, bias_slow) and ema > sma // the SMA crossing the Slow_SMA gives further confirmation of bullish trend, but signal comes later.-sell = crossunder(ema, sma) // sell when EMA cross under SMA.+sell = ta.crossunder(ema, sma) // sell when EMA cross under SMA.// Enable option to hide signals, then plot signals⋯    strategy.entry("BUY TREND", strategy.long)-exitLong = crossunder(ema, sma) // close LONG when EMA cross under SMA+exitLong = ta.crossunder(ema, sma) // close LONG when EMA cross under SMAstrategy.close("BUY TREND", when=exitLong)⋯

Clean v5

VerifiedDownload the v5 script

Same 6 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 6: input() → input.int()
  • Line 7: input() → input.int()
  • Line 8: input() → input.int()
  • Line 20: input() → input.bool()
  • Line 30: when = exitLong → if block
  • Line 38: input() → input.bool()
⋯// Create inputs-mom_length = input(title="Momentum Length (EMA=SMA)", defval=50)+mom_length = input.int(title="Momentum Length (EMA=SMA)", defval=50)-bias_length_fast  = input(title="Golden Cross Length (Fast)", defval=50)+bias_length_fast  = input.int(title="Golden Cross Length (Fast)", defval=50)-bias_length_slow  = input(title="Golden Cross Length (Slow)", defval=100)+bias_length_slow  = input.int(title="Golden Cross Length (Slow)", defval=100)// Define MAs⋯// Enable option to hide signals, then plot signals-show_signal = input(title="Show Signals", defval=true)+show_signal = input.bool(title="Show Signals", defval=true)plotshape(show_signal ? buy_trend : na, title='Trend Buy', style=shape.triangleup, location=location.belowbar, color=color.green, text='TREND BUY')⋯exitLong = ta.crossunder(ema, sma) // close LONG when EMA cross under SMA-strategy.close("BUY TREND", when=exitLong)+if exitLong+    strategy.close("BUY TREND")// // short conditions. turned off because up only.⋯// Enable option to show MAs, then plot MAs-show_ma = input(title="Show MAs", defval=false)+show_ma = input.bool(title="Show MAs", defval=false)plot(show_ma ? ema : na, title="Momentum EMA", color=color.green, linewidth=1)⋯

Does it run in Pine Script v6?

Yes

Same 6 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

⋯// © Cryptoluc1d-//@version=5+//@version=6strategy("Equal-Length EMA/SMA Crossover Strategy", initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=25, commission_type=strategy.commission.percent, commission_value=0.2, overlay=true)⋯

Settings

Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.

SettingDefaultType and rangeFeeds
Momentum Length (EMA=SMA)50intema sma
Golden Cross Length (Fast)50intbias_fast
Golden Cross Length (Slow)100intbias_slow
Show SignalstrueboolTrend Buy Risky Buy Late Buy Sell
Show MAsfalseboolMomentum EMA Momentum SMA Golden Cross SMA (Fast) Golden Cross SMA (Slow)

What it calculates

  • EMA (ema, ta.ema in v5)close, Momentum Length (EMA=SMA) (50)ema · line 10
  • SMA (sma, ta.sma in v5)close, Momentum Length (EMA=SMA) (50)sma · line 11
  • SMA (sma, ta.sma in v5)close, Golden Cross Length (Fast) (50)bias_fast · line 12
  • SMA (sma, ta.sma in v5)close, Golden Cross Length (Slow) (100)bias_slow · line 13
  • Crossunder (crossunder, ta.crossunder in v5)ema, smasell · line 18
  • Crossunder (crossunder, ta.crossunder in v5)ema, smaexitLong · line 29

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 datamom_lengthMomentum Length (EMA=SM…setting · 50bias_length_fastGolden Cross Length (Fa…setting · 50bias_length_slowGolden Cross Length (Sl…setting · 100emaEMA→ emasmaSMA→ smabias_fastSMA→ bias_fastbias_slowSMA→ bias_slowsellCrossunder→ sellexitLongCrossunder→ exitLonglongConditionlongConditionconditionbuy_trend, buy_riskybuy_trend · buy_risky2 conditionsbuy_latebuy_lateconditionentry:BUY TRENDOpen BUY TRENDstrategy.entryclose:BUY TRENDClose BUY TRENDstrategy.closeplotshape:21Trend Buyplotshapeplotshape:22Risky Buyplotshapeplotshape:23Late Buyplotshapeplotshape:24Sellplotshapeplot:39Momentum EMAplotplot:40Momentum SMAplotplot:41Golden Cross SMA (Fast)plotplot:42Golden Cross SMA (Slow)plot

Order rules

OrderFires whenBy defaultLine
Open BUY TREND long(longCondition)On28
Close BUY TRENDexitLongOn30

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.

2/2trades identical when replayed liveThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, four per bar, and compared with the historical run. Orders are decided once per closed bar, so nothing can change mid-bar.
  • 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+10.1%+102.5%650%4.322.8%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−2.3%+5.5%911%0.462.6%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+11.8%+9.8%650%3.752.4%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+5.0%+8.4%1040%2.482.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−1.3%+16.7%944%0.9311.8%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+11.1%+21.5%743%5.081.4%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+13.1%+148.3%863%3.054.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−4.3%+17.1%1030%0.325.2%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 (Momentum Length (EMA=SMA) 85, Golden Cross Length (Fast) 25) made +19.0% before 26 Dec 2025 and −5.8% after it, worse than the defaults' +1.3% after. Tuning on the past did not carry forward. 100% of the 64 combinations made money in-sample and 25% out-of-sample.

Before 26 Dec 2025 · in-sample
Golden Cross Length (Fast) ↓ · Momentum Length (EMA=SMA) →2530354350607085
25+10%+14%+13%+13%+13%+8%+15%+19%
30+7%+12%+9%+9%+9%+5%+11%+15%
35+6%+12%+11%+10%+9%+6%+13%+16%
43+10%+13%+9%+9%+10%+7%+11%+12%
50+10%+14%+10%+8%+9%+8%+11%+12%
60+6%+9%+7%+3%+5%+8%+10%+11%
70+2%+5%+6%+5%+6%+3%+10%+8%
85+1%+4%+5%+4%+6%+2%+9%+13%
From 26 Dec 2025 · out-of-sample
Golden Cross Length (Fast) ↓ · Momentum Length (EMA=SMA) →2530354350607085
25−1%−1%−1%+1%+2%−1%−7%−6%
30−1%−0%−0%+2%+3%−1%−6%−5%
35−1%−0%−0%+2%+3%−1%−6%−5%
43−1%−1%−1%+1%+2%−1%−6%−5%
50−2%−1%−1%+1%+1%−2%−6%−5%
60−1%−1%−1%+1%+2%−1%−7%−6%
70−1%−1%−0%+1%+1%−1%−7%−6%
85−1%−2%−1%+6%+0%−3%−7%−6%

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 barsTradesWonP&L
Rising market10%−$37.08
Sideways market560%$1,045.06
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?

2.9%

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

0%3%
All 6 trades
SideEntryExitBarsP&L
long28 May 2024 69,436.4022 Jun 2024 64,143.6025−$199.78
long23 Oct 2024 67,426.0022 Dec 2024 97,292.0060$1,071.13
long16 May 2025 103,764.009 Jun 2025 105,734.0024$40.55
long15 Jul 2025 119,841.0012 Aug 2025 118,686.0028−$37.08
long3 May 2026 78,686.8025 May 2026 77,065.0022−$66.67
long28 Aug 2026 80,249.605 Oct 2026 86,530.0038$199.83

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
Equal-Length EMA-SMA Crossover Momentum Strategy this page—v4 strategy+10.1%62.8%
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%
Simple Momentum Strategy Based on SMA, EMA and Volume by slip_streamsma emav4 strategy+7.4%1827.4%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 12 msWith a workaround 1,000 bars in 38 msNot measured
PineTSNo v5 and v6 only—Not measured

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. 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/// © Cryptoluc1d//@version=4strategy("Equal-Length EMA/SMA Crossover Strategy", initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=25, commission_type=strategy.commission.percent, commission_value=0.2, overlay=true)// Create inputsmom_length = input(title="Momentum Length (EMA=SMA)", defval=50)bias_length_fast  = input(title="Golden Cross Length (Fast)", defval=50)bias_length_slow  = input(title="Golden Cross Length (Slow)", defval=100)// Define MAsema = ema(close, mom_length) // EMA/SMA crossover of the same period for detecting trend acceleration/decelerationsma = sma(close, mom_length)bias_fast = sma(close, bias_length_fast) // golden/death cross for overall trend biasbias_slow = sma(close, bias_length_slow)// Define signal conditionsbuy_trend = crossover(ema, sma) and bias_fast >= bias_slow // buy when EMA cross above SMA. if this happens during a bullish golden cross, buying is in confluence with the overall trend (bias).buy_risky = crossover(ema, sma) and bias_fast < bias_slow // buy when EMA cross above SMA. if this happens during a bearish death cross, buying is early, more risky, and not in confluence with the overall trend (bias).buy_late = crossover(sma, bias_slow) and ema > sma // the SMA crossing the Slow_SMA gives further confirmation of bullish trend, but signal comes later.sell = crossunder(ema, sma) // sell when EMA cross under SMA.// Enable option to hide signals, then plot signalsshow_signal = input(title="Show Signals", defval=true)plotshape(show_signal ? buy_trend : na, title='Trend Buy', style=shape.triangleup, location=location.belowbar, color=color.green, text='TREND BUY')plotshape(show_signal ? buy_risky : na, title='Risky Buy', style=shape.triangleup, location=location.belowbar, color=color.olive, text='RISKY BUY')plotshape(show_signal ? buy_late : na, title='Late Buy', style=shape.triangleup, location=location.belowbar, color=color.lime, text='LATE BUY')plotshape(show_signal ? sell : na, title='Sell', style=shape.triangledown, location=location.abovebar, color=color.red, text='SELL')// Define entry and exit conditionslongCondition = ema > sma and bias_fast >= bias_slow // LONG when EMA above SMA, and overall trend bias is bullishif (longCondition)    strategy.entry("BUY TREND", strategy.long)exitLong = crossunder(ema, sma) // close LONG when EMA cross under SMAstrategy.close("BUY TREND", when=exitLong)// // short conditions. turned off because up only.// shortCondition = ema < sma and bias_fast <= bias_slow // SHORT when EMA under SMA, and overall trend bias is bearish// if (shortCondition)//     strategy.entry("SELL TREND", strategy.short)// exitShort = crossover(ema, sma) // close SHORT when EMA cross over SMA// strategy.close("SELL TREND", when=exitShort)// Enable option to show MAs, then plot MAsshow_ma = input(title="Show MAs", defval=false)plot(show_ma ? ema : na, title="Momentum EMA", color=color.green, linewidth=1)plot(show_ma ? sma : na, title="Momentum SMA", color=color.yellow, linewidth=1)plot(show_ma ? bias_fast : na, title="Golden Cross SMA (Fast)", color=color.orange, linewidth=2)plot(show_ma ? bias_slow : na, title="Golden Cross SMA (Slow)", color=color.red, linewidth=2)