Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Simple Momentum Strategy Based on SMA, EMA and Volume

A Pine Script v4 strategy built on SMA (close, 10), EMA (close, 20) and Crossunder (sma_line, ema_line). 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 is one contract and pays no commission. 3 settings; defaults include SMA (small length) 10, EMA (large length) 20 and Volume Trigger 10.

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 Simple Momentum Strategy Based on SMA, EMA and Volume repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 6 of 6 trades.
How did Simple Momentum Strategy Based on SMA, EMA and Volume do on BTCUSDT 1D with default settings?
+7.38%
From 26 Jan 2024 to 21 Oct 2026, over 18 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can Simple Momentum Strategy Based on SMA, EMA and Volume 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 Simple Momentum Strategy Based on SMA, EMA and Volume use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does Simple Momentum Strategy Based on SMA, EMA and Volume run in Zeal Terminal?
Yes
It compiles in 8 ms and runs 1,000 bars in 27 ms, in the browser.

BTCUSDT · 1D · default settings

  • SMA
  • EMA
  • Plot
  • 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$107,385$202,527Equity from $100,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 long = true as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (line 36) 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
+7.38%
$7,379.47
Buy and hold
+102.5%
same period
Closed trades
18
7 won · 11 lost
Profitable
38.9%
of closed trades
Profit factor
1.11
gross profit ÷ gross loss
Max drawdown
27.44%
−$37,298.10

One run with the author's default settings, $100,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.

  • 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 36, 37. The upgraded version below moves each call inside an if block.

  • Note

    Uses long =, which v5 renamed line 36

    long = on line 36. v5 writes it as direction = strategy.long or strategy.short.

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

v4 → v5

Verified

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

  • Line 3: //@version=4 → //@version=5
  • Line 15: input(type = input.integer) → input.int()
  • Line 16: input(type = input.integer) → input.int()
  • Line 17: input(type = input.integer) → input.int()
  • Line 18: sma → ta.sma
  • Line 19: ema → ta.ema
3 more edits
  • Line 23: cross → ta.cross
  • Line 34: crossunder → ta.crossunder
  • Line 36: long = true → direction = strategy.long
⋯// © slip_stream-//@version=4+//@version=5// Simple strategy for riding the momentum and optimising the timings of truer/longer price moves upwards for an long posistions on a daily basis (can be used, but with less effect⋯// Obtain inputs-sma_length = input(defval = 10, minval=1, type = input.integer, title = "SMA (small length)")+sma_length = input.int(defval = 10, minval=1, title = "SMA (small length)")-ema_length = input(defval = 20,minval=1, type = input.integer, title = "EMA (large length)")+ema_length = input.int(defval = 20,minval=1, title = "EMA (large length)")-volume_trigger = input(defval = 10, title = "Volume Trigger", type = input.integer)+volume_trigger = input.int(defval = 10, title = "Volume Trigger")-sma_line = sma(close, sma_length)+sma_line = ta.sma(close, sma_length)-ema_line = ema(close, ema_length)+ema_line = ta.ema(close, ema_length)// plot SMA and EMA lines with a cross for when they intersect⋯plot(ema_line, color = #e3d024, title = "EMA")-plot(cross(sma_line, ema_line) ? sma_line : na, style = plot.style_cross, linewidth = 4, color = color.white)+plot(ta.cross(sma_line, ema_line) ? sma_line : na, style = plot.style_cross, linewidth = 4, color = color.white)// Create variables⋯// exit criteria for the trade: when the sma line goes under the ema line-trade_exit_criteria = crossunder (sma_line, ema_line)+trade_exit_criteria = ta.crossunder (sma_line, ema_line)if (year >= 2019)-    strategy.entry(id = "long", long = true, qty = 1, when = trade_entry_criteria)+    strategy.entry(id = "long", direction = strategy.long, qty = 1, when = trade_entry_criteria)    strategy.close(id = "long", when = trade_exit_criteria, qty = 1)⋯

Clean v5

VerifiedDownload the v5 script

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

  • Line 36: when = trade_entry_criteria → if block
  • Line 37: when = trade_exit_criteria → if block
⋯if (year >= 2019)-    strategy.entry(id = "long", direction = strategy.long, qty = 1, when = trade_entry_criteria)+    if trade_entry_criteria+        strategy.entry(id = "long", direction = strategy.long, qty = 1)-    strategy.close(id = "long", when = trade_exit_criteria, qty = 1)+    if trade_exit_criteria+        strategy.close(id = "long", qty = 1)    // for when you want to brute force close all open positions: strategy.close_all (when = trade_exit_criteria)

Does it run in Pine Script v6?

Yes

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

⋯// © slip_stream-//@version=5+//@version=6// Simple strategy for riding the momentum and optimising the timings of truer/longer price moves upwards for an long posistions on a daily basis (can be used, but with less effect⋯

Settings

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

SettingDefaultType and rangeFeeds
SMA (small length)10int (written input.integer) · min 1sma_line
EMA (large length)20int (written input.integer) · min 1ema_line
Volume Trigger10int (written input.integer)enter_trade_3_bar_up

What it calculates

  • SMA (sma, ta.sma in v5)close, SMA (small length) (10)sma_line · line 18
  • EMA (ema, ta.ema in v5)close, EMA (large length) (20)ema_line · line 19
  • Crossunder (crossunder, ta.crossunder in v5)sma_line, ema_linetrade_exit_criteria · line 34

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 datasma_lengthSMA (small length)setting · 10ema_lengthEMA (large length)setting · 20volumevolumeprice datavolume_triggerVolume Triggersetting · 10openopenprice datalowlowprice datasma_lineSMA→ sma_lineema_lineEMA→ ema_linetrade_exit_criteriaCrossunder→ trade_exit_criteriatrade_entry_criteriatrade_entry_criteriaconditionenter_trade_3_bar_upenter_trade_3_bar_upconditionenter_3_bar_play, enter_4_bar_playenter_3_bar_play · ente…2 conditionsentry:longOpen longstrategy.entryclose:longClose longstrategy.closeplot:21SMAplotplot:22EMAplotplot:23plotplot

Order rules

OrderFires whenBy defaultLine
Open long longtrade_entry_criteriaenter_trade_3_bar_up or enter_3_bar_play or enter_4_bar_playOn36
Close longtrade_exit_criteriaOn37

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.

6/6trades 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+7.4%+102.5%1839%1.1127.4%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−0.3%+5.5%2025%0.9811.8%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+1.1%+9.8%1540%1.421.6%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+0.3%+8.4%2030%1.530.2%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+0.1%+16.7%1644%1.560.1%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.0%+21.5%2035%1.850.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+0.5%+148.3%2157%2.120.4%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−0.1%+17.1%2133%0.680.2%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 market540%$7,667.28
Sideways market825%−$19,922.30
Falling market560%$19,634.50

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

How bad could the drawdown be?

39.1%

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

0%45%
All 18 trades
SideEntryExitBarsP&L
long15 Feb 2024 51,795.2019 Apr 2024 63,470.1064$11,674.90
long21 May 2024 71,446.6018 Jun 2024 66,504.3028−$4,942.29
long23 Jul 2024 67,532.007 Aug 2024 56,022.0015−$11,510.00
long27 Aug 2024 62,834.004 Sep 2024 57,487.708−$5,346.26
long21 Sep 2024 63,201.1010 Oct 2024 60,636.0019−$2,565.04
long16 Oct 2024 67,074.1028 Dec 2024 94,299.0073$27,224.90
long20 Jan 2025 101,332.008 Feb 2025 96,506.8019−$4,824.77
long20 Apr 2025 85,077.008 Jun 2025 105,552.0049$20,475.10
long13 Jun 2025 105,672.0022 Jun 2025 102,120.009−$3,551.72
long2 Jul 2025 105,681.007 Aug 2025 114,992.0036$9,311.14
long14 Aug 2025 123,306.0024 Aug 2025 115,438.0010−$7,868.38
long6 Oct 2025 123,482.0017 Oct 2025 108,194.0011−$15,288.10
long7 Jan 2026 93,748.0027 Jan 2026 88,347.1020−$5,400.89
long13 Mar 2026 70,541.3016 Mar 2026 72,815.303$2,273.91
long17 Mar 2026 74,884.7028 Mar 2026 66,407.3011−$8,477.39
long12 Apr 2026 73,043.2023 May 2026 75,539.5041$2,496.34
long13 Jul 2026 63,780.003 Aug 2026 63,570.0021−$209.99
long22 Aug 2026 78,338.0016 Oct 2026 82,245.9055$3,907.90

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
Simple Momentum Strategy Based on SMA, EMA and Volume this page—v4 strategy+7.4%1827.4%
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%
BTC WaveTrend R-R=1-1.5 by TrendCrypto2022ema smav5 strategy+0.2%282.7%

Where it runs

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

Zeal Terminal's engine currently reads an order side written as long = true as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (line 36) 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. 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/// © slip_stream//@version=4// Simple strategy for riding the momentum and optimising the timings of truer/longer price moves upwards for an long posistions on a daily basis (can be used, but with less effect// on other time frames. Volume settings would have to be adjusted by the user accordingly. (short positions are not used).// This strategy has default settings of a short(er) SMA of 10, a long(er) EMA of 20, and Volume trigger of 10 units and above. All these settings can be changed by the user// using the GUI settings and not having to change the script.// The strategy will only open a long position when there is a clear indication that price momentum is upwards through the SMA moving and remaining above the EMA (mandatory) and price period indicators// of either 1) a standard 3 bar movement upwards, 2) a standard but "aggressive" 3 or 4 bar play where the low of the middle resting bars can be equal to or higher than (i.e. not// the more standard low of about half) of the opening of the ignition bar. The "aggression" of the 3/4 bar play was done in order to counteract the conservatisme of having a mandatory// SMA remaining higher than the EMA (this would have to be changed in the script by the user if they want to optimise to their own specifications. However, be warned, all programmatic// settings for the maximum acceptable low of the middle resting bars runs a risk of ignoring good entry points due to the low being minutely e.g. 0.01%, lower than the user defined setting)strategy(title = "Simple Momentum Strategy Based on SMA, EMA and Volume", overlay = true, pyramiding = 1, initial_capital = 100000, currency = currency.USD)// Obtain inputssma_length = input(defval = 10, minval=1, type = input.integer, title = "SMA (small length)")ema_length = input(defval = 20,minval=1, type = input.integer, title = "EMA (large length)")volume_trigger = input(defval = 10, title = "Volume Trigger", type = input.integer)sma_line = sma(close, sma_length)ema_line = ema(close, ema_length)// plot SMA and EMA lines with a cross for when they intersectplot(sma_line, color = #8b0000, title = "SMA")plot(ema_line, color = #e3d024, title = "EMA")plot(cross(sma_line, ema_line) ? sma_line : na, style = plot.style_cross, linewidth = 4, color = color.white)// Create variables// variables to check if trade should be entered//three consecutive bar bar moves upwards and volume of at least one bar is more than 10enter_trade_3_bar_up = sma_line > ema_line and close[1] >= close [2] and close[3] >= close[4] and close[2] >= close[3] and (volume[1] >= volume_trigger or volume[2] >= volume_trigger or volume[3] >= volume_trigger)// aggressive three bar play that ensures the low of the middle bar is equal to or greater than the open of the instigator bar. Volume is not taken into consideration (i.e. aggressive/risky)enter_3_bar_play = sma_line > ema_line and close[1] > close[3] and low[2] >= open[3]// aggressive four bar play similar to the 3 bar play aboveenter_4_bar_play = sma_line > ema_line and close[1] > close[4] and low[2] >= open[4]trade_entry_criteria = enter_trade_3_bar_up or enter_3_bar_play or enter_4_bar_play // has one of the trade entry criterias returned true?// exit criteria for the trade: when the sma line goes under the ema linetrade_exit_criteria = crossunder (sma_line, ema_line)if (year >= 2019)    strategy.entry(id = "long", long = true, qty = 1, when = trade_entry_criteria)    strategy.close(id = "long", when = trade_exit_criteria, qty = 1)    // for when you want to brute force close all open positions: strategy.close_all (when = trade_exit_criteria)