Pine Script v5 · Strategy
M0PB (Momentum Pullback)
A Pine Script v5 strategy built on RSI (close, 6), EMA (high, 5) and Highest (12). It has 6 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a profit target and no stop loss. Each trade is one contract and pays 0.0004 commission. 1 setting; defaults include atr stop 2.75.
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 M0PB (Momentum Pullback) repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 1 of 1 trades.
- How did M0PB (Momentum Pullback) do on BTCUSDT 1D with default settings?
- +51.26%
- From 26 Jan 2024 to 21 Oct 2026, over 3 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does M0PB (Momentum Pullback) run in Pine Script v6?
- No
- The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L29:C8: cannot use 'float' as a condition — Pine Script v6 does not cast 'int' or 'float' to 'bool' implicitly. Wrap it in bool(). The v6 version is shown for reference and is not offered as a download.
- Does M0PB (Momentum Pullback) use a stop loss?
- No
- Its exits set a profit target but no stop.
- Does M0PB (Momentum Pullback) run in Zeal Terminal?
- Yes
- It compiles in 26 ms and runs 1,000 bars in 29 ms, in the browser.
BTCUSDT · 1D · default settings
- l_entry
- s_entry
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +51.26%
- $15,377.40
- Buy and hold
- +102.5%
- same period
- Closed trades
- 3
- 3 won · 0 lost
- Profitable
- 100.0%
- of closed trades
- Profit factor
- —
- gross profit ÷ gross loss
- Max drawdown
- 17.46%
- −$7,332.83
One run with the author's default settings, $30,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
strategy.exit is used without a stop, loss or trailing stop.
-
Note
Uses an argument v6 removed
when = on line 75, 77, 83, 88. 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 |
|---|---|---|---|
| atr stop | 2.75 | float · min 0.1 · max 6.0 | stop_l stop_s |
What it calculates
- RSIclose, 6
r · line 15 - EMAhigh, 5
es · line 33 - EMAlow, 5
el · line 35 - Highest12
ph · line 66 - Lowest12
pl · line 68 - ATR10
atr · line 71
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 EL long | trade_l == 1.0 | On | 75 |
| Open ES short | trade_s == -1.0 | On | 77 |
| Exit ph limit | strategy.position_size == 2 | On | 81 |
| Close | low[1] > stop_l[1] and low <= stop_l | On | 83 |
| Exit pl limit | strategy.position_size == -2 | On | 86 |
| Close | high[1] < stop_s[1] and high >= stop_s | On | 88 |
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 | +51.3% | +102.5% | 3 | 100% | — | 17.5% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −14.1% | +5.5% | 3 | 33% | 0.27 | 17.6% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +7.8% | +9.8% | 4 | 100% | — | 0.3% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −0.9% | +8.4% | 5 | 40% | 0.29 | 1.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +0.3% | +16.7% | 5 | 80% | 6.23 | 0.2% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.0% | +21.5% | 5 | 80% | 1.51 | 0.1% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −0.1% | +148.3% | 5 | 60% | 0.84 | 1.2% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −0.2% | +17.1% | 2 | 50% | 0.29 | 0.4% | 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 | 2 | 100% | $12,002.40 |
| Sideways market | 1 | 100% | $3,374.98 |
| 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?
0.0%
The 95th percentile of the worst drawdown when the same 3 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 0.0% to 0.0%; the tick is what actually happened, 0.0%. Order luck alone moves it this much.
All 3 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 21 Feb 2024 52,258.80 | 26 Feb 2024 52,985.00 | 5 | $1,451.50 |
| long | 6 Mar 2024 63,724.00 | 8 Mar 2024 69,000.00 | 2 | $10,550.90 |
| short | 12 Jun 2026 63,626.00 | 24 Jun 2026 61,938.00 | 12 | $3,374.98 |
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 |
|---|---|---|---|---|---|
| M0PB (Momentum Pullback) this page | — | v5 strategy | +51.3% | 3 | 17.5% |
| R19 STRATEGY by SenatorVonShaft | atr ema highest lowest rsi | v4 strategy | No trades on this market | ||
| Richard's Strategy by Deepak8369 | highest lowest atr ema | v4 strategy | +34.6% | 70 | 26.3% |
| STRATEGY R18-F-BTC by SenatorVonShaft | ema highest lowest rsi | v4 strategy | −8.6% | 11 | 14.4% |
| Classic Long Term Trend Following System by Robrecht99 | ema highest lowest atr | v5 strategy | +2.9% | 5 | 1.1% |
| Dynamic Stop Loss Demo by Tindtily | highest lowest rsi atr | v5 strategy | does not run in Zeal Terminal | ||
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 75, 77, 83, 88). 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 3 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 75: when = trade_l == 1.0 → if block
- Line 77: when = trade_s == -1.0 → if block
- Line 83: when = low[1] > stop_l[1] and low <= stop_l → if block
- Line 88: when = high[1] < stop_s[1] and high >= stop_s → if block
⋯//strat entry long-strategy.entry("EL", strategy.long, 2, when = trade_l == 1.0)+if trade_l == 1.0+ strategy.entry("EL", strategy.long, 2)//strat entry short-strategy.entry("ES", strategy.short, 2, when = trade_s == -1.0) +if trade_s == -1.0+ strategy.entry("ES", strategy.short, 2) ⋯ if strategy.position_size == 2- strategy.close_all(when = low[1] > stop_l[1] and low <= stop_l)+ if low[1] > stop_l[1] and low <= stop_l+ strategy.close_all()// strat short exit⋯ if strategy.position_size == -2- strategy.close_all(when = high[1] < stop_s[1] and high >= stop_s)+ if high[1] < stop_s[1] and high >= stop_s+ strategy.close_all()// code below to trail remaining 50% of position //⋯Does it run in Pine Script v6?
No
The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L29:C8: cannot use 'float' as a condition — Pine Script v6 does not cast 'int' or 'float' to 'bool' implicitly. Wrap it in bool(). The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © Marcns_-//@version=5+//@version=6strategy("M0PB", commission_value = 0.0004, slippage = 1, initial_capital=30000)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 26 ms | With a workaround 1,000 bars in 29 ms | Not measured |
| PineTS | Not tested | Not tested | 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.
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/// © Marcns_//@version=5strategy("M0PB", commission_value = 0.0004, slippage = 1, initial_capital=30000)// commision is equal to approx $3.8 per round trip which is accurate for ES1! futures and slippage per trade is conservatively 1 tick in and 1 tick out. // *momentum pull back* //// long / short strategy that identifies extreme readings on the rsi as a *momentum signal*//Strategy buys/ sells a pullback to the 5ema(low)/ 5ema(high) and exits at rolling 12 bar high/ low. The rolling high/ low feature means that //if price enters into a pronlonged consolidation the profit target will begin to reduce with each new bar. The best trades tend to work within 2-6 bars// hard stop is X atr's from postion average price. This can be adjusted in user inputs.// built for use on 5 min & 1min intervals on: FX, Indexes, Crypto// there is a lot of slack left in entries and exits but the overall strategy is fairly robust across timeframes and markets and has between 60%-70% winrate with larger winners.// signals that occur from economic news volatility are best avoided. // define rsir = ta.rsi(close,6) // find rsi > 90b = 0.0if r >= 90 b := 1.0else na// find rsi < 10s = 0.0if r <= 10 s := -1.0else na// plot rsi extreme as painted background colorbgcolor(b ? color.rgb(255, 82, 82, 49): na)bgcolor(s? color.rgb(76, 175, 79, 51): na)// exponential moving averages for entries. note that source is high and low (normally close is def input) this creates entry bands//entry short price using high as a source ta.ema(high,5)es = ta.ema(high,5)//entry long price using low as a source ta.ema(low,5)el = ta.ema(low,5)// long pullback entry trigger: last period above ema and current low below target ema entry let = 0.0if low[1] > el[1] and low <= el let := 1.0else na//short entry trigger ""set = 0.0if high[1] < es[1] and high >= es set := -1.0else na// create signal "trade_l" if RSI > 90 and price pulls back to 5ema(low) within 6 barstrade_l = 0.0if ta.barssince(b == 1.0) < 6 and let == 1.0 trade_l := 1.0else naplot(trade_l, "l_entry", color.green)//create short signal "trade_s" if rsi < 10 and prices pullback to 5em(high) wihthin 6 barstrade_s = 0.0if ta.barssince(s == -1.0) < 6 and set == -1.0 trade_s := -1.0else naplot(trade_s, "s_entry", color.purple)// define price at time of trade_l signal and input value into trade_p to use for stop parems latertrade_p = strategy.position_avg_price//indentify previous 12 bar high as part of long exit strat// this creates a rolling 12 bar high target... a quick move back up will exit at previous swing high but if a consolidation occurs system will exit on a new 12 bar high which may be below prev local highph = ta.highest(12)// inverse of above for short exit strat - previous lowest low of 12 bars as exit (rolling)pl = ta.lowest(12)// 1.5 atr stop below entry price (trade_p defined earlier) as part of exit stratatr_inp = input.float(2.75, "atr stop", minval = 0.1, maxval = 6.0)atr = ta.atr(10)stop_l = trade_p - (atr* atr_inp)stop_s = trade_p + (atr* atr_inp)//strat entry longstrategy.entry("EL", strategy.long, 2, when = trade_l == 1.0)//strat entry shortstrategy.entry("ES", strategy.short, 2, when = trade_s == -1.0) //strat long exitif strategy.position_size == 2 strategy.exit(id = "ph", from_entry = "EL", qty = 2, limit = ph) if strategy.position_size == 2 strategy.close_all(when = low[1] > stop_l[1] and low <= stop_l)// strat short exitif strategy.position_size == -2 strategy.exit(id = "pl", from_entry = "ES", qty = 2, limit =pl) if strategy.position_size == -2 strategy.close_all(when = high[1] < stop_s[1] and high >= stop_s)// code below to trail remaining 50% of position // //if strategy.position_size == 1 //strategy.exit(id ="trail", from_entry = "EL", qty = 1, stop = el)