Zeal Terminal Open in Zeal Terminal

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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (4)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$9,576$20,253Equity from $10,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.
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.

SettingDefaultType and rangeFeeds
Fast EMA length21int · min 1fastEma
Slow EMA length55int · min 1slowEma
Swing low lookback5int · min 1swingLo
Reward to risk2.0float · min 0.5 · step 0.5targetLevel

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, fastEmareclaim · 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.

closecloseprice datafastLenFast EMA lengthsetting · 21slowLenSlow EMA lengthsetting · 55lowlowprice dataswingLenSwing low lookbacksetting · 5rewardRiskReward to risksetting · 2.0fastEmaEMA→ fastEmaslowEmaEMA→ slowEmaswingLoLowest→ swingLoreclaimCrossover→ reclaimstopLevelstopLevelvaluetargetLeveltargetLevelvaluesetupsetupconditionuptrenduptrendconditionentry:LongOpen Longstrategy.entryexit:Exitexit Exitstrategy.exitplot:31Fast EMAplotplot:32Slow EMAplotalertcondition:34Pullback entryalertcondition

Order rules

OrderFires whenBy defaultLine
Open Long longsetupOn27
Exit Exit stop and limitstrategy.position_size > 0On29

Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.

Alerts

AlertCallMessageLine
Pullback entryalertconditionClose reclaimed the fast EMA in an uptrend34

Does it repaint?

No

No repainting patterns in the source, and the live replay matched history.

2/2trades 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−4.7%+102.5%1724%0.435.0%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+0.7%+5.5%1242%1.570.7%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−0.8%+9.8%1735%0.895.5%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−0.8%+8.4%1136%0.581.6%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+7.9%+16.7%1050%2.772.9%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−1.0%+21.5%1638%0.681.3%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+1.6%+148.3%1656%1.224.6%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−0.5%+17.1%2438%0.811.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 barsTradesWonP&L
Rising market1225%−$382.88
Sideways market520%−$86.12
Falling market0—$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.

0%8%
All 17 trades
SideEntryExitBarsP&L
long21 Mar 2024 67,840.5013 Apr 2024 60,775.0023−$105.05
long23 Apr 2024 66,819.3030 Apr 2024 59,600.007−$107.79
long5 May 2024 63,892.005 Jul 2024 56,552.8061−$113.29
long2 Aug 2024 65,354.003 Aug 2024 61,498.301−$57.98
long7 Oct 2024 62,819.9010 Oct 2024 59,828.103−$46.71
long12 Oct 2024 62,540.0028 Oct 2024 69,728.0016$108.92
long6 Nov 2024 69,372.007 Nov 2024 75,572.001$85.44
long25 Dec 2024 98,663.6030 Dec 2024 92,232.505−$64.55
long3 Jan 2025 96,984.809 Jan 2025 91,530.406−$55.46
long15 Jan 2025 96,560.9025 Feb 2025 89,256.7041−$73.84
long2 Jun 2025 105,643.005 Jun 2025 103,069.003−$24.25
long8 Jun 2025 105,552.0022 Jun 2025 100,372.0014−$47.75
long24 Jun 2025 105,334.0014 Jul 2025 119,602.0020$127.57
long8 Aug 2025 117,472.0022 Aug 2025 111,920.0014−$46.41
long23 Aug 2025 116,936.0024 Aug 2025 111,685.001−$43.93
long12 Sep 2026 77,225.7014 Sep 2026 79,583.902$28.13
long15 Sep 2026 78,189.2016 Sep 2026 75,644.501−$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.

ScriptSharesTypeNetTradesMax drawdown
EMA Pullback Strategy this page—v5 strategy−4.7%175.0%
CC Trend strategy 2- Downtrend Short by CheatCode1ema lowestv5 strategyNo trades on this market
TrianglePoint strategy by mohaneelowest emav4 strategy+45.4%11101.9%
Lagged Donchian Channel + EMA by Mysteriownema lowestv4 strategy−12.3%412.3%
Backtest Custom HiLo Strategy by luyikaibrema lowestv4 strategyNo trades on this market
CM_SlingShotSystem+_CassicEMA+Willams21EMA13 htc1977 edition by Arivadisema lowestv5 strategyNo 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

Verified

Nothing 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.

Download the v6 script

⋯// © 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

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 11 msYes 1,000 bars in 24 msNot measured
PineTSNot testedNot testedNot 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")