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
- 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
VerifiedSame 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)⋯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.
⋯// © 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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Momentum Length (EMA=SMA) | 50 | int | ema sma |
| Golden Cross Length (Fast) | 50 | int | bias_fast |
| Golden Cross Length (Slow) | 100 | int | bias_slow |
| Show Signals | true | bool | Trend Buy Risky Buy Late Buy Sell |
| Show MAs | false | bool | Momentum EMA Momentum SMA Golden Cross SMA (Fast) Golden Cross SMA (Slow) |
What it calculates
- EMA (
ema,ta.emain v5)close, Momentum Length (EMA=SMA) (50)ema · line 10 - SMA (
sma,ta.smain v5)close, Momentum Length (EMA=SMA) (50)sma · line 11 - SMA (
sma,ta.smain v5)close, Golden Cross Length (Fast) (50)bias_fast · line 12 - SMA (
sma,ta.smain v5)close, Golden Cross Length (Slow) (100)bias_slow · line 13 - Crossunder (
crossunder,ta.crossunderin v5)ema, smasell · line 18 - Crossunder (
crossunder,ta.crossunderin 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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open BUY TREND long | (longCondition) | On | 28 |
| Close BUY TREND | exitLong | On | 30 |
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.
- 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 | +10.1% | +102.5% | 6 | 50% | 4.32 | 2.8% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −2.3% | +5.5% | 9 | 11% | 0.46 | 2.6% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +11.8% | +9.8% | 6 | 50% | 3.75 | 2.4% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +5.0% | +8.4% | 10 | 40% | 2.48 | 2.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −1.3% | +16.7% | 9 | 44% | 0.93 | 11.8% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +11.1% | +21.5% | 7 | 43% | 5.08 | 1.4% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +13.1% | +148.3% | 8 | 63% | 3.05 | 4.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −4.3% | +17.1% | 10 | 30% | 0.32 | 5.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.
| Golden Cross Length (Fast) ↓ · Momentum Length (EMA=SMA) → | 25 | 30 | 35 | 43 | 50 | 60 | 70 | 85 |
|---|---|---|---|---|---|---|---|---|
| 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% |
| Golden Cross Length (Fast) ↓ · Momentum Length (EMA=SMA) → | 25 | 30 | 35 | 43 | 50 | 60 | 70 | 85 |
|---|---|---|---|---|---|---|---|---|
| 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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 1 | 0% | −$37.08 |
| Sideways market | 5 | 60% | $1,045.06 |
| 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?
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.
All 6 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 28 May 2024 69,436.40 | 22 Jun 2024 64,143.60 | 25 | −$199.78 |
| long | 23 Oct 2024 67,426.00 | 22 Dec 2024 97,292.00 | 60 | $1,071.13 |
| long | 16 May 2025 103,764.00 | 9 Jun 2025 105,734.00 | 24 | $40.55 |
| long | 15 Jul 2025 119,841.00 | 12 Aug 2025 118,686.00 | 28 | −$37.08 |
| long | 3 May 2026 78,686.80 | 25 May 2026 77,065.00 | 22 | −$66.67 |
| long | 28 Aug 2026 80,249.60 | 5 Oct 2026 86,530.00 | 38 | $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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Equal-Length EMA-SMA Crossover Momentum Strategy this page | — | v4 strategy | +10.1% | 6 | 2.8% |
| 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% |
| Simple Momentum Strategy Based on SMA, EMA and Volume by slip_stream | sma ema | v4 strategy | +7.4% | 18 | 27.4% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 12 ms | With a workaround 1,000 bars in 38 ms | Not measured |
| PineTS | No 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)