Pine Script v4 · Strategy
dEMA w- VWAP filter
A Pine Script v4 strategy built on EMA (close, 34). 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 commits 1 in cash and pays no commission. 1 setting; defaults include EMA Length 34.
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 dEMA w- VWAP filter repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 10 of 10 trades.
- How did dEMA w- VWAP filter do on BTCUSDT 1D with default settings?
- +9,246.98%
- From 26 Jan 2024 to 21 Oct 2026, over 31 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can dEMA w- VWAP filter 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 dEMA w- VWAP filter use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does dEMA w- VWAP filter run in Zeal Terminal?
- Yes
- It compiles in 8 ms and runs 1,000 bars in 25 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- Plot
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +9,246.98%
- $46,234.90
- Buy and hold
- +102.5%
- same period
- Closed trades
- 31
- 10 won · 21 lost
- Profitable
- 32.3%
- of closed trades
- Profit factor
- 2.07
- gross profit ÷ gross loss
- Max drawdown
- 425.20%
- −$20,213.30
One run with the author's default settings, $500 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.
-
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.
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 ema → ta.ema, change → ta.change, crossunder → ta.crossunder.
v4 → v5
VerifiedSame 31 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 6: ema → ta.ema
- Line 7: change → ta.change
- Line 7: vwap → ta.vwap
- Line 9: strategy.entry(…, true) → strategy.entry(…, strategy.long)
- Line 10: change → ta.change
5 more edits
- Line 10: vwap → ta.vwap
- Line 10: crossunder → ta.crossunder
- Line 10: vwap → ta.vwap
- Line 10: change → ta.change
- Line 13: vwap → ta.vwap
⋯// © shiner_trading-//@version=4+//@version=5strategy("dEMA w/ VWAP filter", overlay=true, default_qty_type=strategy.cash, initial_capital=500)len = input(34, "EMA Length")-ma = ema(close, len)+ma = ta.ema(close, len)-longCondition = change(ma) > 0 and ma < vwap+longCondition = ta.change(ma) > 0 and ma < ta.vwapif (longCondition)- strategy.entry("Buy", true, 1)+ strategy.entry("Buy", strategy.long, 1)-shortCondition = (change(ma) < 0 and close > vwap) or (crossunder(ma, vwap) and change(ma) > 0)+shortCondition = (ta.change(ma) < 0 and close > ta.vwap) or (ta.crossunder(ma, ta.vwap) and ta.change(ma) > 0)if (shortCondition) strategy.close("Buy")-plot (vwap, color=color.fuchsia)+plot (ta.vwap, color=color.fuchsia)plot (ma)Same 31 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 5: input() → input.int()
⋯strategy("dEMA w/ VWAP filter", overlay=true, default_qty_type=strategy.cash, initial_capital=500)-len = input(34, "EMA Length")+len = input.int(34, "EMA Length")ma = ta.ema(close, len)⋯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: 31 before, 0 after on BTCUSDT 1D, 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.
⋯// © shiner_trading-//@version=5+//@version=6strategy("dEMA w/ VWAP filter", overlay=true, default_qty_type=strategy.cash, initial_capital=500)⋯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 |
|---|---|---|---|
| EMA Length | 34 | int | ma |
What it calculates
- EMA (
ema,ta.emain v5)close, EMA Length (34)ma · line 6
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 Buy long | (longCondition) | On | 9 |
| Close Buy | (shortCondition) | On | 12 |
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 | +9,247.0% | +102.5% | 31 | 32% | 2.07 | 425.2% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +765.6% | +5.5% | 24 | 42% | 1.18 | 1,496.7% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +254.4% | +9.8% | 28 | 32% | 1.40 | 150.3% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +49.8% | +8.4% | 28 | 29% | 1.32 | 39.7% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +1.5% | +16.7% | 32 | 34% | 1.04 | 19.8% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +5.1% | +21.5% | 22 | 36% | 1.97 | 3.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +66.1% | +148.3% | 34 | 41% | 1.56 | 31.5% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +12.2% | +17.1% | 25 | 40% | 1.40 | 17.1% | 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 | 9 | 33% | $5,170.45 |
| Sideways market | 15 | 33% | $43,051.40 |
| Falling market | 7 | 29% | −$1,986.90 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
7,365.4%
The 95th percentile of the worst drawdown when the same 31 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 193.4% to 7,365.4%; the tick is what actually happened, 374.3%. Order luck alone moves it this much.
All 31 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 1 Mar 2024 61,131.00 | 15 Apr 2024 65,661.90 | 45 | $4,530.86 |
| long | 23 Apr 2024 66,819.30 | 26 Apr 2024 64,498.30 | 3 | −$2,320.99 |
| long | 16 May 2024 66,206.50 | 13 Jun 2024 68,264.00 | 28 | $2,057.47 |
| long | 16 Jul 2024 64,724.10 | 6 Aug 2024 54,018.80 | 21 | −$10,705.20 |
| long | 24 Aug 2024 64,037.20 | 31 Aug 2024 59,124.00 | 7 | −$4,913.25 |
| long | 14 Sep 2024 60,498.00 | 18 Sep 2024 60,314.00 | 4 | −$184.00 |
| long | 19 Sep 2024 61,760.00 | 4 Oct 2024 60,752.70 | 15 | −$1,007.26 |
| long | 5 Oct 2024 62,086.00 | 11 Oct 2024 60,326.40 | 6 | −$1,759.60 |
| long | 12 Oct 2024 62,540.00 | 24 Dec 2024 94,881.50 | 73 | $32,341.50 |
| long | 25 Dec 2024 98,663.60 | 29 Dec 2024 95,300.00 | 4 | −$3,363.58 |
| long | 3 Jan 2025 96,984.80 | 9 Jan 2025 95,060.60 | 6 | −$1,924.18 |
| long | 15 Jan 2025 96,560.90 | 9 Feb 2025 96,444.80 | 25 | −$116.10 |
| long | 26 Mar 2025 87,392.90 | 28 Mar 2025 87,232.00 | 2 | −$160.87 |
| long | 13 Apr 2025 85,276.90 | 7 Jun 2025 104,288.00 | 55 | $19,011.50 |
| long | 8 Jun 2025 105,552.00 | 20 Jun 2025 104,659.00 | 12 | −$893.56 |
| long | 25 Jun 2025 106,083.00 | 4 Aug 2025 114,209.00 | 40 | $8,125.81 |
| long | 5 Aug 2025 115,055.00 | 6 Aug 2025 114,130.00 | 1 | −$925.28 |
| long | 8 Aug 2025 117,472.00 | 19 Aug 2025 116,227.00 | 11 | −$1,244.97 |
| long | 11 Sep 2025 113,960.00 | 25 Sep 2025 113,307.00 | 14 | −$652.99 |
| long | 30 Sep 2025 114,312.00 | 11 Oct 2025 112,774.00 | 11 | −$1,537.48 |
| long | 27 Oct 2025 114,559.00 | 2 Nov 2025 110,098.00 | 6 | −$4,461.31 |
| long | 3 Jan 2026 89,995.10 | 22 Jan 2026 89,454.70 | 19 | −$540.41 |
| long | 14 Mar 2026 70,930.00 | 21 Mar 2026 70,510.70 | 7 | −$419.28 |
| long | 26 Mar 2026 71,336.50 | 1 Apr 2026 68,284.50 | 6 | −$3,052.04 |
| long | 8 Apr 2026 71,924.20 | 19 May 2026 77,001.90 | 41 | $5,077.66 |
| long | 11 Jul 2026 64,161.70 | 15 Jul 2026 65,044.00 | 4 | $882.27 |
| long | 16 Jul 2026 64,756.30 | 19 Jul 2026 64,834.20 | 3 | $77.93 |
| long | 20 Jul 2026 64,722.60 | 27 Jul 2026 65,400.00 | 7 | $677.45 |
| long | 31 Jul 2026 64,780.00 | 2 Aug 2026 62,823.70 | 2 | −$1,956.38 |
| long | 6 Aug 2026 64,665.20 | 14 Aug 2026 63,490.90 | 8 | −$1,174.38 |
| long | 19 Aug 2026 64,725.40 | 18 Oct 2026 81,491.00 | 60 | $16,765.60 |
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 |
|---|---|---|---|---|---|
| dEMA w- VWAP filter this page | — | v4 strategy | +9,247.0% | 31 | 425.2% |
| EMA Slope AyE by fajardoarelys | ema | v4 strategy | No trades on this market | ||
| ROoT by realisticDove62527 | ema | v5 strategy | −4.7% | 225 | 9.4% |
| sachin5986 by mohitesachin78 | ema | v4 strategy | +32.1% | 35 | 17.6% |
| sonu1997 by Sonu1997 | ema | v4 strategy | +960.7% | 2 | 1,103.8% |
| Moving Average Crossover by Muh4mm4d | ema | v4 strategy | +19,990.1% | 30 | 1,274.2% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 8 ms | With a workaround 1,000 bars in 25 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
Zeal Terminal's engine currently reads an order side written as true as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (line 9) so the engine trades the way the script says.
“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/// © shiner_trading//@version=4strategy("dEMA w/ VWAP filter", overlay=true, default_qty_type=strategy.cash, initial_capital=500)len = input(34, "EMA Length")ma = ema(close, len)longCondition = change(ma) > 0 and ma < vwapif (longCondition) strategy.entry("Buy", true, 1)shortCondition = (change(ma) < 0 and close > vwap) or (crossunder(ma, vwap) and change(ma) > 0)if (shortCondition) strategy.close("Buy")plot (vwap, color=color.fuchsia)plot (ma)