Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Momentum Strategy

A Pine Script v4 strategy built on EMA (close, 50), Rising or EMA (rs,trendMovingAverage, 1) and Rising (longMA, 1). It has 2 order rules, 2 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. Each trade is one contract and pays no commission. 6 settings; defaults include New Highs Period 63, New Relative Highs Period 40 and Uptrend Period 50.

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 Momentum Strategy repaint?
No
No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
How did Momentum Strategy do on BTCUSDT 1D with default settings?
Not measured
It closed no trades there from 26 Jan 2024 to 21 Oct 2026 with the default settings, so there is no result to report. Its entry conditions never all held on this data. It closed no trades on the other markets either. A backtest, not investment advice.
Can 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 Momentum Strategy use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does Momentum Strategy run in Zeal Terminal?
Yes
It compiles in 16 ms and runs 1,000 bars in 46 ms, in the browser.

BTCUSDT · 1D · default settings

  • Plot
  • Plot
  • Winning trade
  • Losing trade
  • Equity
  • Buy and hold
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$100,000$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. 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. Data the page supplies at the chart's own timeframe (another symbol, or Heikin-Ashi) reaches the script one bar later in Zeal Terminal's engine than on TradingView. The live re-run is not offered here: the script requests SPX D, BTCUSD D, which this page cannot load in your browser.

Needs SPX D data, not available: not a Binance spot market Values that depend on it are empty on this chart.

Net profit
0.00%
$0.00
Buy and hold
+102.5%
same period
Closed trades
0
0 won · 0 lost
Profitable
0.0%
of closed trades
Profit factor
—
gross profit ÷ gross loss
Max drawdown
0.00%
$0.00

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.

  • Likely bug

    ema(close, 200) ignores the settings line 14

    Line 14 hard-codes 200 where line 16 uses “Uptrend Period”. Changing those settings moves one band but not this one.

    ema(close, 200)ema(close, trendMovingAverage)
  • Likely bug

    ema(close, 200) ignores the settings line 14

    Line 14 hard-codes 200 where line 16 uses “Uptrend Period”. Changing those settings moves one band but not this one.

    ema(close, 200)ema(close, trendMovingAverage)
  • 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 transp =, which v5 removed line 18

    transp = on line 18, 19. v5 folds the transparency into the colour with color.new(c, transp).

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 rising → ta.rising, ema → ta.ema, security → request.security, highest → ta.highest, rsi → ta.rsi.

v4 → v5

VerifiedDownload the v5 script

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

  • Line 3: //@version=4 → //@version=5
  • Line 10: input(type = input.integer) → input.int()
  • Line 11: input(type = input.integer) → input.int()
  • Line 12: input(type = input.integer) → input.int()
  • Line 13: input(type = input.integer) → input.int()
  • Line 14: rising → ta.rising
19 more edits
  • Line 14: ema → ta.ema
  • Line 14: rising → ta.rising
  • Line 14: ema → ta.ema
  • Line 16: ema → ta.ema
  • Line 17: ema → ta.ema
  • Line 18: transp = 70 removed: the call sets no colour to fold it into, so its default colour loses the transparency
  • Line 19: transp = 70 removed: the call sets no colour to fold it into, so its default colour loses the transparency
  • Line 21: input(type = input.symbol) → input.symbol()
  • Line 22: input(type = input.symbol) → input.symbol()
  • Line 23: security → request.security
  • Line 24: security → request.security
  • Line 25: security → request.security
  • Line 30: highest → ta.highest
  • Line 31: rising → ta.rising
  • Line 31: ema → ta.ema
  • Line 33: highest → ta.highest
  • Line 36: rsi → ta.rsi
  • Line 37: rising → ta.rising
  • Line 52: ema → ta.ema
⋯// © PrattyCharts-//@version=4+//@version=5strategy("Momentum Strategy", overlay=true, process_orders_on_close =true)⋯// momentum settings-highPeriod = input(63, type = input.integer, title = "New Highs Period") +highPeriod = input.int(63, title = "New Highs Period") -relativeHighPeriod = input(40, type = input.integer, title = "New Relative Highs Period") +relativeHighPeriod = input.int(40, title = "New Relative Highs Period") -trendMovingAverage = input(50, type = input.integer, title = "Uptrend Period")+trendMovingAverage = input.int(50, title = "Uptrend Period")-trailingMovingAverage = input(20, type = input.integer, title = "First Moving Average Stop")+trailingMovingAverage = input.int(20, title = "First Moving Average Stop")-bullmarket = rising(ema(close, 200),1) and rising(ema(close, 200),1)+bullmarket = ta.rising(ta.ema(close, 200),1) and ta.rising(ta.ema(close, 200),1)strategy.risk.allow_entry_in(strategy.direction.long)-longMA = ema(close, trendMovingAverage)+longMA = ta.ema(close, trendMovingAverage)-shortMA = ema(close, trailingMovingAverage)+shortMA = ta.ema(close, trailingMovingAverage)-plot(shortMA, transp = 70)+plot(shortMA)-plot(longMA, transp = 70)+plot(longMA)// check for new relative high -comparativeTickerStock = input("SPX", type = input.symbol, title = "Stock Benchmark")+comparativeTickerStock = input.symbol("SPX", title = "Stock Benchmark")-comparativeTickerCrypto = input("BTCUSD", type = input.symbol, title = "Crypto Benchmark")+comparativeTickerCrypto = input.symbol("BTCUSD", title = "Crypto Benchmark")-baseSymbol = security(syminfo.tickerid, timeframe.period, close)+baseSymbol = request.security(syminfo.tickerid, timeframe.period, close)-benchmarkStock = security(comparativeTickerStock, timeframe.period, close)+benchmarkStock = request.security(comparativeTickerStock, timeframe.period, close)-benchmarkCrypto = security(comparativeTickerCrypto, timeframe.period, close)+benchmarkCrypto = request.security(comparativeTickerCrypto, timeframe.period, close)rs = baseSymbol / benchmarkStock⋯    rs := baseSymbol / benchmarkCrypto-newRelativeHigh = rs > highest(rs[1], relativeHighPeriod)+newRelativeHigh = rs > ta.highest(rs[1], relativeHighPeriod)-relativeUptrend = rising(ema(rs,trendMovingAverage),1)+relativeUptrend = ta.rising(ta.ema(rs,trendMovingAverage),1)// triggers-isNewHigh = close > highest(close[1], highPeriod)+isNewHigh = close > ta.highest(close[1], highPeriod)hasRelativeStrength = newRelativeHigh and relativeUptrendupperClosingRange = close-open > 0.85 * (open-high) // closing near upper 85% of candle range-hasBullishRSI = rsi(close, 14) > 60+hasBullishRSI = ta.rsi(close, 14) > 60-inUptrend = rising(longMA,1)+inUptrend = ta.rising(longMA,1)buyTrigger = isNewHigh and upperClosingRange and inUptrend and hasBullishRSI⋯// check if the stock is breaking down on a relative basis-rsEMA = ema(rs, trendMovingAverage)+rsEMA = ta.ema(rs, trendMovingAverage)if(rs < rsEMA )⋯

Clean v5

Verified

Nothing to change.

Does it run in Pine Script v6?

No

The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 2 before, 2 after on BTCUSDT 4h, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.

⋯// © PrattyCharts-//@version=5+//@version=6strategy("Momentum Strategy", overlay=true, process_orders_on_close =true)⋯

Settings

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

SettingDefaultType and rangeFeeds
New Highs Period63int (written input.integer)isNewHigh
New Relative Highs Period40int (written input.integer)newRelativeHigh
Uptrend Period50int (written input.integer)longMA relativeUptrend rsEMA
First Moving Average Stop20int (written input.integer)shortMA
Stock BenchmarkSPXsymbolbenchmarkStock
Crypto BenchmarkBTCUSDsymbolbenchmarkCrypto

What it calculates

  • EMA (ema, ta.ema in v5)close, Uptrend Period (50)longMA · line 16
  • EMA (ema, ta.ema in v5)close, First Moving Average Stop (20)shortMA · line 17
  • Rising / EMA (rising, ta.rising in v5)ema(rs,trendMovingAverage), 1relativeUptrend · line 31
  • Rising (rising, ta.rising in v5)longMA, 1inUptrend · line 37
  • EMA (ema, ta.ema in v5)rs, Uptrend Period (50)rsEMA · line 52

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 datatrendMovingAverageUptrend Periodsetting · 50trailingMovingAverageFirst Moving Average St…setting · 20comparativeTickerStockStock Benchmarksetting · SPXcomparativeTickerCryptoCrypto Benchmarksetting · BTCUSDrelativeHighPeriodNew Relative Highs Peri…setting · 40highPeriodNew Highs Periodsetting · 63highhighprice dataopenopenprice datalongMAEMA→ longMAshortMAEMA→ shortMArelativeUptrendRising / EMA→ relativeUptrendinUptrendRising→ inUptrendrsEMAEMA→ rsEMAbaseSymbolbaseSymbolvaluebenchmarkStockbenchmarkStockvaluebenchmarkCryptobenchmarkCryptovaluersrsvaluebuyTriggerbuyTriggerconditionexitTriggerexitTriggerconditionbenchmarkbenchmarkconditionbullmarket, hasBullishRSIbullmarket · hasBullish…2 conditionsnewRelativeHighnewRelativeHighconditionisNewHighisNewHighconditionhasRelativeStrengthhasRelativeStrengthconditionupperClosingRangeupperClosingRangeconditionentry:buy Open buy strategy.entryentry:sell Open sell strategy.entryplot:18plotplotplot:19plotplot

Order rules

OrderFires whenBy defaultLine
Open buy long(buyTrigger)On57
Open sell short(exitTrigger)On59

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 measuredNo trades to compareThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, but neither the live nor the historical run produced any trades in them, so the replay says nothing either way.
  • ClearHigher-timeframe data3 security call(s), none with lookahead on.
  • 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 timingprocess_orders_on_close = true: orders fill at the signal bar's close.

The checks read the source; the replay runs it. Together they catch the common causes, not every possible one.

Other markets

Not run on other markets: the script requests SPX D, and that data is not available here (not a Binance spot market). Its results would rest on empty values.

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
Momentum Strategy this page—v4 strategy0.0%00.0%
AMRS_LongOnly_PartTimer by ThePartTimeNSEema highestv4 strategy0.0%110.0%
BTC Good Signal by Majaztradesema highestv4 strategy−32.5%638.9%
Automated Bitcoin (BTC) Investment Strategy from Wunderbit by Wunderbitema highestv4 strategy−32.5%638.9%
PMA Strategy Idea by QuantCTema risingv4 strategy+51.7%12930.8%
CC Trend strategy 2- Downtrend Short by CheatCode1ema highestv5 strategyNo trades on this market

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 16 msWith a workaround 1,000 bars in 46 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. Data the page supplies at the chart's own timeframe (another symbol, or Heikin-Ashi) reaches the script one bar later in Zeal Terminal's engine than on TradingView.

“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/// © PrattyCharts//@version=4strategy("Momentum Strategy", overlay=true, process_orders_on_close =true)isCrypto = falseif(syminfo.prefix == "COINBASE" or syminfo.prefix == "BINANCE" or syminfo.prefix == "FTX" or syminfo.prefix == "BITSTAMP")    isCrypto := truebenchmark = syminfo.root == "SPX" or syminfo.root == "BTCUSD"// momentum settingshighPeriod = input(63, type = input.integer, title = "New Highs Period") relativeHighPeriod = input(40, type = input.integer, title = "New Relative Highs Period") trendMovingAverage = input(50, type = input.integer, title = "Uptrend Period")trailingMovingAverage = input(20, type = input.integer, title = "First Moving Average Stop")bullmarket = rising(ema(close, 200),1) and rising(ema(close, 200),1)strategy.risk.allow_entry_in(strategy.direction.long)longMA = ema(close, trendMovingAverage)shortMA = ema(close, trailingMovingAverage)plot(shortMA, transp = 70)plot(longMA, transp = 70)// check for new relative high comparativeTickerStock = input("SPX", type = input.symbol, title = "Stock Benchmark")comparativeTickerCrypto = input("BTCUSD", type = input.symbol, title = "Crypto Benchmark")baseSymbol = security(syminfo.tickerid, timeframe.period, close)benchmarkStock = security(comparativeTickerStock, timeframe.period, close)benchmarkCrypto = security(comparativeTickerCrypto, timeframe.period, close)rs = baseSymbol / benchmarkStock// check if bitcoin should be used for relative strength if(isCrypto)    rs := baseSymbol / benchmarkCryptonewRelativeHigh = rs > highest(rs[1], relativeHighPeriod)relativeUptrend = rising(ema(rs,trendMovingAverage),1)// triggersisNewHigh = close > highest(close[1], highPeriod)hasRelativeStrength = newRelativeHigh and relativeUptrendupperClosingRange = close-open > 0.85 * (open-high) // closing near upper 85% of candle rangehasBullishRSI = rsi(close, 14) > 60inUptrend = rising(longMA,1)buyTrigger = isNewHigh and upperClosingRange and inUptrend and hasBullishRSIif(not benchmark) // do not do relative analysis for benchmarks    buyTrigger := buyTrigger and hasRelativeStrength// determine which exit to useexitTrigger = close < shortMAvar trending = false// check if the stock is trending nicelyif(close > strategy.position_avg_price * 1.20)    trending := true // if the stock is trending well use a longer moving averageif(trending)    exitTrigger := close <  longMA    // check if the stock is breaking down on a relative basisrsEMA = ema(rs, trendMovingAverage)if(rs < rsEMA )    exitTrigger :=true// strategyif (buyTrigger)    strategy.entry("buy ", strategy.long, comment = "Buy")if(exitTrigger)    strategy.entry("sell ", strategy.short, comment = "Exit")    trending := false