Pine Script v5 · Strategy
EMA Pullback Strategy
A Pine Script v5 strategy built on EMA (close, 21), Lowest (low, 5) and Crossover (close, fastEma). It has 2 order rules, 1 entry among them, and trades long only with the default settings. Exits use a stop loss and a profit target. Each trade commits 10% of equity and pays 0.05% commission. 4 settings; defaults include Fast EMA length 21, Slow EMA length 55 and Swing low lookback 5.
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 EMA Pullback 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 EMA Pullback Strategy do on BTCUSDT 1D with default settings?
- −4.69%
- From 26 Jan 2024 to 21 Oct 2026, over 17 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- What alerts does EMA Pullback Strategy have?
- 1
- Pullback entry.
- Does EMA Pullback Strategy run in Pine Script v6?
- Yes
- Same 17 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. The v6 script can be downloaded below.
- Does EMA Pullback Strategy use a stop loss?
- Yes
- strategy.exit sets a stop on line 29.
BTCUSDT · 1D · default settings
- Fast EMA
- Slow EMA
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −4.69%
- −$469.47
- Buy and hold
- +102.5%
- same period
- Closed trades
- 17
- 4 won · 13 lost
- Profitable
- 23.5%
- of closed trades
- Profit factor
- 0.43
- gross profit ÷ gross loss
- Max drawdown
- 5.05%
- −$504.90
One run with the author's default settings, $10,000 starting capital, commission as the script sets it. A long position was still open at the last bar. 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.
Nothing to point out.
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 |
|---|---|---|---|
| Fast EMA length | 21 | int · min 1 | fastEma |
| Slow EMA length | 55 | int · min 1 | slowEma |
| Swing low lookback | 5 | int · min 1 | swingLo |
| Reward to risk | 2.0 | float · min 0.5 · step 0.5 | targetLevel |
What it calculates
- EMAclose, Fast EMA length (21)
fastEma · line 14 - EMAclose, Slow EMA length (55)
slowEma · line 15 - Lowestlow, Swing low lookback (5)
swingLo · line 16 - Crossoverclose, fastEma
reclaim · line 19
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 Long long | setup | On | 27 |
| Exit Exit stop and limit | strategy.position_size > 0 | On | 29 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Alerts
| Alert | Call | Message | Line |
|---|---|---|---|
| Pullback entry | alertcondition | Close reclaimed the fast EMA in an uptrend | 34 |
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 | −4.7% | +102.5% | 17 | 24% | 0.43 | 5.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +0.7% | +5.5% | 12 | 42% | 1.57 | 0.7% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −0.8% | +9.8% | 17 | 35% | 0.89 | 5.5% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −0.8% | +8.4% | 11 | 36% | 0.58 | 1.6% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +7.9% | +16.7% | 10 | 50% | 2.77 | 2.9% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −1.0% | +21.5% | 16 | 38% | 0.68 | 1.3% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +1.6% | +148.3% | 16 | 56% | 1.22 | 4.6% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −0.5% | +17.1% | 24 | 38% | 0.81 | 1.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 | 12 | 25% | −$382.88 |
| Sideways market | 5 | 20% | −$86.12 |
| 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?
7.0%
The 95th percentile of the worst drawdown when the same 17 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 4.7% to 7.0%; the tick is what actually happened, 5.0%. Order luck alone moves it this much.
All 17 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 21 Mar 2024 67,840.50 | 13 Apr 2024 60,775.00 | 23 | −$105.05 |
| long | 23 Apr 2024 66,819.30 | 30 Apr 2024 59,600.00 | 7 | −$107.79 |
| long | 5 May 2024 63,892.00 | 5 Jul 2024 56,552.80 | 61 | −$113.29 |
| long | 2 Aug 2024 65,354.00 | 3 Aug 2024 61,498.30 | 1 | −$57.98 |
| long | 7 Oct 2024 62,819.90 | 10 Oct 2024 59,828.10 | 3 | −$46.71 |
| long | 12 Oct 2024 62,540.00 | 28 Oct 2024 69,728.00 | 16 | $108.92 |
| long | 6 Nov 2024 69,372.00 | 7 Nov 2024 75,572.00 | 1 | $85.44 |
| long | 25 Dec 2024 98,663.60 | 30 Dec 2024 92,232.50 | 5 | −$64.55 |
| long | 3 Jan 2025 96,984.80 | 9 Jan 2025 91,530.40 | 6 | −$55.46 |
| long | 15 Jan 2025 96,560.90 | 25 Feb 2025 89,256.70 | 41 | −$73.84 |
| long | 2 Jun 2025 105,643.00 | 5 Jun 2025 103,069.00 | 3 | −$24.25 |
| long | 8 Jun 2025 105,552.00 | 22 Jun 2025 100,372.00 | 14 | −$47.75 |
| long | 24 Jun 2025 105,334.00 | 14 Jul 2025 119,602.00 | 20 | $127.57 |
| long | 8 Aug 2025 117,472.00 | 22 Aug 2025 111,920.00 | 14 | −$46.41 |
| long | 23 Aug 2025 116,936.00 | 24 Aug 2025 111,685.00 | 1 | −$43.93 |
| long | 12 Sep 2026 77,225.70 | 14 Sep 2026 79,583.90 | 2 | $28.13 |
| long | 15 Sep 2026 78,189.20 | 16 Sep 2026 75,644.50 | 1 | −$32.05 |
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 |
|---|---|---|---|---|---|
| EMA Pullback Strategy this page | — | v5 strategy | −4.7% | 17 | 5.0% |
| CC Trend strategy 2- Downtrend Short by CheatCode1 | ema lowest | v5 strategy | No trades on this market | ||
| TrianglePoint strategy by mohanee | lowest ema | v4 strategy | +45.4% | 11 | 101.9% |
| Lagged Donchian Channel + EMA by Mysteriown | ema lowest | v4 strategy | −12.3% | 4 | 12.3% |
| Backtest Custom HiLo Strategy by luyikaibr | ema lowest | v4 strategy | No trades on this market | ||
| CM_SlingShotSystem+_CassicEMA+Willams21EMA13 htc1977 edition by Arivadis | ema lowest | v5 strategy | No trades on this market | ||
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.
- No v6-only features. v6 is not needed to run this script.
Clean v5
VerifiedNothing to change.
Does it run in Pine Script v6?
Yes
Same 17 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.
⋯// © Zeal Terminal-//@version=5+//@version=6strategy("EMA Pullback Strategy", shorttitle = "EMA Pullback", overlay = true, initial_capital = 10000, default_qty_type = strategy.percent_of_equity, default_qty_value = 10, commission_type = strategy.commission.percent, commission_value = 0.05, slippage = 1)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 11 ms | Yes 1,000 bars in 24 ms | Not measured |
| PineTS | Not tested | Not tested | Not measured |
“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
Written by Zeal Terminal and published under the Mozilla Public License 2.0.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © Zeal Terminal//@version=5strategy("EMA Pullback Strategy", shorttitle = "EMA Pullback", overlay = true, initial_capital = 10000, default_qty_type = strategy.percent_of_equity, default_qty_value = 10, commission_type = strategy.commission.percent, commission_value = 0.05, slippage = 1) // Not investment advice. In an uptrend (fast EMA above slow EMA), buys the// first close back above the fast EMA after a dip below it. Exits at a fixed// reward-to-risk target or at the stop under the dip.fastLen = input.int(21, "Fast EMA length", minval = 1)slowLen = input.int(55, "Slow EMA length", minval = 1)swingLen = input.int(5, "Swing low lookback", minval = 1)rewardRisk = input.float(2.0, "Reward to risk", minval = 0.5, step = 0.5) fastEma = ta.ema(close, fastLen)slowEma = ta.ema(close, slowLen)swingLo = ta.lowest(low, swingLen) uptrend = fastEma > slowEmareclaim = ta.crossover(close, fastEma)setup = uptrend and reclaim and strategy.position_size == 0 var float stopLevel = navar float targetLevel = naif setup stopLevel := swingLo targetLevel := close + rewardRisk * (close - swingLo) strategy.entry("Long", strategy.long)if strategy.position_size > 0 strategy.exit("Exit", "Long", stop = stopLevel, limit = targetLevel) plot(fastEma, "Fast EMA", color = #42a5f5, linewidth = 2)plot(slowEma, "Slow EMA", color = #ffb74d, linewidth = 2) alertcondition(setup, "Pullback entry", "Close reclaimed the fast EMA in an uptrend")