Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

DEMA-EMA & VOLATILITY (VAMS)

A Pine Script v4 strategy built on EMA (close, 10), ATR (14) and Crossunder (dema1, ema1). It has 3 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 is 10000 contracts and pays no commission. 18 settings; defaults include DEMA LENGTH 10, Source close and EMA Length 25.

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-EMA & VOLATILITY (VAMS) repaint?
No
No repainting patterns were found in the source.
Can DEMA-EMA & VOLATILITY (VAMS) 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-EMA & VOLATILITY (VAMS) use a stop loss?
Yes
strategy.exit sets a stop on line 68.
Does DEMA-EMA & VOLATILITY (VAMS) run in Zeal Terminal?
Yes
It compiles in 14 ms and runs 1,000 bars in 71 ms, in the browser.

BTCUSDT · 1D · default settings

  • DEMA
  • 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 (18)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$283,340,000$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. Zeal Terminal's engine currently reads an order side written as long = strategy.long as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (line 61) so the engine trades the way the script says.
Net profit
+2,833,450.00%
$283,345,000.00
Buy and hold
+102.5%
same period
Closed trades
19
6 won · 13 lost
Profitable
31.6%
of closed trades
Profit factor
1.85
gross profit ÷ gross loss
Max drawdown
15,721.00%
−$223,600,000.00

One run with the author's default settings, $10,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

    7 settings do nothing

    “Show Moving Average?”, “From Month”, “From Day”, “From Year”, “To Month”, “To Day”, “To Year” are declared but never read.

  • 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 an argument v6 removed

    when = on line 61, 66. The upgraded version below moves each call inside an if block.

  • Note

    Uses long =, which v5 renamed line 61

    long = on line 61. v5 writes it as direction = strategy.long or strategy.short.

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, security → request.security, atr → ta.atr, sma → ta.sma, crossover → ta.crossover, crossunder → ta.crossunder, max → math.max.
  • 2 strategy calls use the when = argument (line 61, 66). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

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

  • Line 3: //@version=4 → //@version=5
  • Line 8: ema → ta.ema
  • Line 9: ema → ta.ema
  • Line 15: input(type = input.integer) → input.int()
  • Line 16: ema → ta.ema
  • Line 19: input(type = input.resolution) → input.timeframe()
13 more edits
  • Line 20: input(type = input.integer) → input.int()
  • Line 21: input(type = input.bool) → input.bool()
  • Line 26: input(type = input.float) → input.float()
  • Line 28: input(type = input.float) → input.float()
  • Line 38: security → request.security
  • Line 38: atr → ta.atr
  • Line 42: ema → ta.ema
  • Line 42: sma → ta.sma
  • Line 43: security → request.security
  • Line 45: crossover → ta.crossover
  • Line 47: crossunder → ta.crossunder
  • Line 55: max → math.max
  • Line 61: long = strategy.long → direction = strategy.long
⋯// © Qorbanjf-//@version=4+//@version=5strategy("ORIGIN DEMA/EMA & VOL LONG ONLY", shorttitle="ORIGIN DEMA/EMA & VOL LONG", overlay=true, initial_capital=10000, default_qty_value=10000)⋯src = input(close, title="Source")-e1 = ema(src, length)+e1 = ta.ema(src, length)-e2 = ema(e1, length)+e2 = ta.ema(e1, length)dema1 = 2 * e1 - e2⋯srb = input(close, title="Source")-offset = input(title="Offset", type=input.integer, defval=0, minval=-500, maxval=500)+offset = input.int(title="Offset", defval=0, minval=-500, maxval=500)-ema1 = ema(srb, len)+ema1 = ta.ema(srb, len)plot(ema1, title="EMA", color=color.blue, offset=offset)// Inputs-atrTimeFrame = input("D", title="ATR Timeframe", type=input.resolution)+atrTimeFrame = input.timeframe("D", title="ATR Timeframe")-atrLookback = input(defval=14,title="ATR Lookback Period",type=input.integer)+atrLookback = input.int(defval=14,title="ATR Lookback Period")-useMA = input(title = "Show Moving Average?", type = input.bool, defval = true)+useMA = input.bool(title = "Show Moving Average?", defval = true)maType = input(defval="EMA", options=["EMA", "SMA"], title = "Moving Average Type")⋯    // type=input.float, minval=0.0, step=0.1, defval=1) * 0.01-longTrailPerc = input(title="Trail stop loss (%)",-     type=input.float, minval=0.0, step=0.1, defval=50) * 0.01+longTrailPerc = input.float(title="Trail stop loss (%)", minval=0.0, step=0.1, defval=50) * 0.01-longProfitPerc = input(title="Long Take Profit (%)",-     type=input.float, minval=0.0, step=0.1, defval=3000) / 100+longProfitPerc = input.float(title="Long Take Profit (%)", minval=0.0, step=0.1, defval=3000) / 100// === INPUT BACKTEST RANGE ===⋯// ATR Logic // atrValue = atr(atrLookback) // atrp = (atrValue/close)*100 // plot(atrp, color=color.white, linewidth=2, transp = 30)-atrValue = security(syminfo.tickerid, atrTimeFrame, atr(atrLookback))+atrValue = request.security(syminfo.tickerid, atrTimeFrame, ta.atr(atrLookback))atrp = (atrValue/close)*100⋯ma(maType, src, length) =>-    maType == "EMA" ? ema(src, length) : sma(src, length) //Ternary Operator (if maType equals EMA, then do ema calc, else do sma calc)+    maType == "EMA" ? ta.ema(src, length) : ta.sma(src, length) //Ternary Operator (if maType equals EMA, then do ema calc, else do sma calc)-maFilter = security(syminfo.tickerid, atrTimeFrame, ma(maType, atrp, maLength))+maFilter = request.security(syminfo.tickerid, atrTimeFrame, ma(maType, atrp, maLength))// variables for enter position-enterLong = crossover(dema1, ema1) and atrp < maFilter+enterLong = ta.crossover(dema1, ema1) and atrp < maFilter// variables for exit position-sale = crossunder(dema1, ema1)+sale = ta.crossunder(dema1, ema1)// stop loss⋯    stopValue = close * (1 - longTrailPerc)-    max(stopValue, longStopTrail[1])+    math.max(stopValue, longStopTrail[1])else⋯strategy.entry(id="long",- long=strategy.long,+ direction = strategy.long, when=enterLong,⋯

Clean v5

VerifiedDownload the v5 script

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

  • Line 6: input() → input.int()
  • Line 7: input() → input.source()
  • Line 13: input() → input.int()
  • Line 14: input() → input.source()
  • Line 22: input() → input.string()
  • Line 23: input() → input.int()
8 more edits
  • Line 29: input() → input.int()
  • Line 30: input() → input.int()
  • Line 31: input() → input.int()
  • Line 32: input() → input.int()
  • Line 33: input() → input.int()
  • Line 34: input() → input.int()
  • Line 59: when = enterLong → if block
  • Line 64: when = sale → if block
⋯// DEMA-length = input(10, minval=1, title="DEMA LENGTH")+length = input.int(10, minval=1, title="DEMA LENGTH")-src = input(close, title="Source")+src = input.source(close, title="Source")e1 = ta.ema(src, length)⋯//EMA-len = input(25, minval=1, title="EMA Length")+len = input.int(25, minval=1, title="EMA Length")-srb = input(close, title="Source")+srb = input.source(close, title="Source")offset = input.int(title="Offset", defval=0, minval=-500, maxval=500)⋯useMA = input.bool(title = "Show Moving Average?", defval = true)-maType = input(defval="EMA", options=["EMA", "SMA"], title = "Moving Average Type")+maType = input.string(defval="EMA", options=["EMA", "SMA"], title = "Moving Average Type")-maLength = input(defval = 20, title = "Moving Average Period", minval = 1)+maLength = input.int(defval = 20, title = "Moving Average Period", minval = 1)//longLossPerc = input(title="Long Stop Loss (%)",⋯// === INPUT BACKTEST RANGE ===-FromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)+FromMonth = input.int(defval = 1, title = "From Month", minval = 1, maxval = 12)-FromDay   = input(defval = 1, title = "From Day", minval = 1, maxval = 31)+FromDay   = input.int(defval = 1, title = "From Day", minval = 1, maxval = 31)-FromYear  = input(defval = 2017, title = "From Year", minval = 2000)+FromYear  = input.int(defval = 2017, title = "From Year", minval = 2000)-ToMonth   = input(defval = 1, title = "To Month", minval = 1, maxval = 12)+ToMonth   = input.int(defval = 1, title = "To Month", minval = 1, maxval = 12)-ToDay     = input(defval = 1, title = "To Day", minval = 1, maxval = 31)+ToDay     = input.int(defval = 1, title = "To Day", minval = 1, maxval = 31)-ToYear    = input(defval = 9999, title = "To Year", minval = 2017)+ToYear    = input.int(defval = 9999, title = "To Year", minval = 2017)// ATR Logic // atrValue = atr(atrLookback) // atrp = (atrValue/close)*100 // plot(atrp, color=color.white, linewidth=2, transp = 30)⋯//Enter trades when conditions are met-strategy.entry(id="long",- direction = strategy.long,- when=enterLong,- comment="long")+if enterLong+    strategy.entry(id="long",+     direction = strategy.long,+     comment="long")//-strategy.close("long", when = sale, comment = "Sell")+if sale+    strategy.close("long", comment = "Sell")//place exit orders (only executed after trades are active)⋯

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: 19 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.

⋯// © Qorbanjf-//@version=5+//@version=6strategy("ORIGIN DEMA/EMA & VOL LONG ONLY", shorttitle="ORIGIN DEMA/EMA & VOL LONG", overlay=true, initial_capital=10000, default_qty_value=10000)⋯

Settings

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

SettingDefaultType and rangeFeeds
DEMA LENGTH10int · min 1e1 e2 line 42
Sourceclosesourcee1 line 42
EMA Length25int · min 1ema1
Sourceclosesourceema1
Offset0int (written input.integer) · min -500 · max 500EMA
ATR TimeframeDtimeframe (written input.resolution)atrValue maFilter
ATR Lookback Period14int (written input.integer)atrValue
Show Moving Average?trueboolunused
Moving Average TypeEMAstring · options ["EMA", "SMA"]maFilter line 42
Moving Average Period20int · min 1maFilter
Trail stop loss (%)50float · min 0.0 · step 0.1longStopTrail stopValue
Long Take Profit (%)3000float · min 0.0 · step 0.1longExitPrice
From Month1int · min 1 · max 12unused
From Day1int · min 1 · max 31unused
From Year2017int · min 2000unused
To Month1int · min 1 · max 12unused
To Day1int · min 1 · max 31unused
To Year9999int · min 2017unused

What it calculates

  • EMA (ema, ta.ema in v5)Source (close), DEMA LENGTH (10)e1 · line 8
  • EMA (ema, ta.ema in v5)e1, DEMA LENGTH (10)e2 · line 9
  • EMA (ema, ta.ema in v5)Source (close), EMA Length (25)ema1 · line 16
  • ATR (atr, ta.atr in v5)ATR Lookback Period (14)atrValue · line 38
  • Crossunder (crossunder, ta.crossunder in v5)dema1, ema1sale · line 47

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 datalengthDEMA LENGTHsetting · 10lenEMA Lengthsetting · 25high · low · closehigh · low · closeprice dataatrTimeFrameATR Timeframesetting · DatrLookbackATR Lookback Periodsetting · 14maTypeMoving Average Typesetting · EMAmaLengthMoving Average Periodsetting · 20longTrailPercTrail stop loss (%)setting · 50longProfitPercLong Take Profit (%)setting · 3000e1EMA→ e1e2EMA→ e2ema1EMA→ ema1atrValueATR→ atrValuesaleCrossunder→ saledema1dema1valueatrpatrpvaluemaFiltermaFiltervaluestopValuestopValuevaluelongExitPricelongExitPricevalueenterLongenterLongconditionlongStopTraillongStopTrailconditionentry:longOpen longstrategy.entryclose:longClose longstrategy.closeexit:sellexit sellstrategy.exitplot:11DEMAplotplot:17EMAplot

Order rules

OrderFires whenBy defaultLine
Open long longenterLongcrossover(dema1, ema1) and atrp < maFilterOn61
Close longsaleOn66
Exit sell stop and limitevery barOn68

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.

6/6trades 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.

The script reads request.security() at the chart's own timeframe, which Zeal Terminal's engine answers one bar late in live mode but not in history, so this replay cannot tell repainting from that engine issue.

  • ClearHigher-timeframe data2 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 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+2,833,450.0%+102.5%1932%1.8515,721.0%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+358,802.0%+5.5%2119%1.201,136,090.0%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−15,372.0%+9.8%1724%0.95190,007.0%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+7,898.0%+8.4%1926%1.1412,034.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−1,865.0%+16.7%1926%0.894,928.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+3,194.0%+21.5%1233%3.26846.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+39,227.0%+148.3%1828%2.5917,888.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+1,130.0%+17.1%2030%1.115,254.0%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 market633%−$65,737,800.00
Sideways market729%$190,012,000.00
Falling market633%$159,071,000.00

Rising and falling mean the market moved more than 15% over the 90 bars before entry.

How bad could the drawdown be?

796,021.0%

The 95th percentile of the worst drawdown when the same 19 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 434.2% to 796,021.0%; the tick is what actually happened, 577.7%. Order luck alone moves it this much.

0%915,424%
All 19 trades
SideEntryExitBarsP&L
long17 May 2024 65,235.2015 Jun 2024 66,044.0029$8,087,800.00
long24 Aug 2024 64,037.2030 Aug 2024 59,359.006−$46,782,400.00
long15 Sep 2024 59,993.0010 Oct 2024 60,636.0025$6,429,900.00
long13 Oct 2024 63,206.2024 Dec 2024 94,881.5072$316,752,000.00
long6 Jan 2025 98,363.6010 Jan 2025 92,552.504−$58,111,200.00
long16 Jan 2025 100,497.005 Feb 2025 97,763.1020−$27,342,100.00
long27 Mar 2025 86,909.2029 Mar 2025 84,424.402−$24,847,900.00
long16 Apr 2025 83,644.006 Jun 2025 101,509.0051$178,647,000.00
long9 Jun 2025 105,734.0019 Jun 2025 104,887.0010−$8,472,200.00
long27 Jun 2025 106,947.003 Aug 2025 112,546.0037$55,992,900.00
long10 Aug 2025 116,462.0020 Aug 2025 112,873.0010−$35,893,000.00
long12 Sep 2025 115,483.0025 Sep 2025 113,307.0013−$21,756,800.00
long2 Oct 2025 118,595.0013 Oct 2025 114,959.0011−$36,361,800.00
long4 Jan 2026 90,628.0022 Jan 2026 89,454.7018−$11,732,800.00
long13 Mar 2026 70,541.3023 Mar 2026 67,859.0010−$26,823,400.00
long25 Mar 2026 70,556.7027 Mar 2026 68,820.302−$17,364,300.00
long8 Apr 2026 71,924.2019 May 2026 77,001.9041$50,776,600.00
long10 Jul 2026 63,230.001 Aug 2026 62,887.9022−$3,421,300.00
long8 Aug 2026 64,923.2013 Aug 2026 63,480.005−$14,432,100.00

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
DEMA-EMA & VOLATILITY (VAMS) this page—v4 strategy+2,833,450.0%1915,721.0%
Trend Reversal - Potential pressure by BardiaB2atr emav4 strategy+133,960.0%51,504.8%
Simple Ema_ATR Strategy HulkTrading by TheHulkTradingema atrv4 strategy+2.2%1415.6%
Keltner Breakout Strategy by Zeal Terminalema atrv5 strategy+3.5%212.3%
[EKIN] ATR Exit Strategy by ekinbasarkomurema atrv5 strategy+781.7%302,960.8%
Super Z strategy - Thanks to Rafael Zioni by 03.freemanema atrv4 strategy−404,823.0%562,951,790.0%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 14 msWith a workaround 1,000 bars in 71 msNot measured
PineTSNo v5 and v6 only—Not measured

Zeal Terminal's engine currently reads an order side written as long = strategy.long as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (line 61) 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/// © Qorbanjf//@version=4strategy("ORIGIN DEMA/EMA & VOL LONG ONLY", shorttitle="ORIGIN DEMA/EMA & VOL LONG", overlay=true, initial_capital=10000, default_qty_value=10000)// DEMAlength = input(10, minval=1, title="DEMA LENGTH")src = input(close, title="Source")e1 = ema(src, length)e2 = ema(e1, length)dema1 = 2 * e1 - e2plot(dema1, "DEMA", color=color.yellow)//EMAlen = input(25, minval=1, title="EMA Length")srb = input(close, title="Source")offset = input(title="Offset", type=input.integer, defval=0, minval=-500, maxval=500)ema1 = ema(srb, len)plot(ema1, title="EMA", color=color.blue, offset=offset)// InputsatrTimeFrame = input("D", title="ATR Timeframe", type=input.resolution)atrLookback = input(defval=14,title="ATR Lookback Period",type=input.integer)useMA = input(title = "Show Moving Average?", type = input.bool, defval = true)maType = input(defval="EMA", options=["EMA", "SMA"], title = "Moving Average Type")maLength = input(defval = 20, title = "Moving Average Period", minval = 1)//longLossPerc = input(title="Long Stop Loss (%)",    // type=input.float, minval=0.0, step=0.1, defval=1) * 0.01longTrailPerc = input(title="Trail stop loss (%)",     type=input.float, minval=0.0, step=0.1, defval=50) * 0.01longProfitPerc = input(title="Long Take Profit (%)",     type=input.float, minval=0.0, step=0.1, defval=3000) / 100// === INPUT BACKTEST RANGE ===FromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)FromDay   = input(defval = 1, title = "From Day", minval = 1, maxval = 31)FromYear  = input(defval = 2017, title = "From Year", minval = 2000)ToMonth   = input(defval = 1, title = "To Month", minval = 1, maxval = 12)ToDay     = input(defval = 1, title = "To Day", minval = 1, maxval = 31)ToYear    = input(defval = 9999, title = "To Year", minval = 2017)// ATR Logic // atrValue = atr(atrLookback) // atrp = (atrValue/close)*100 // plot(atrp, color=color.white, linewidth=2, transp = 30)atrValue = security(syminfo.tickerid, atrTimeFrame, atr(atrLookback))atrp = (atrValue/close)*100// Moving Average Logicma(maType, src, length) =>    maType == "EMA" ? ema(src, length) : sma(src, length) //Ternary Operator (if maType equals EMA, then do ema calc, else do sma calc)maFilter = security(syminfo.tickerid, atrTimeFrame, ma(maType, atrp, maLength))// variables for enter positionenterLong = crossover(dema1, ema1) and atrp < maFilter// variables for exit positionsale = crossunder(dema1, ema1)// stop loss//longStopPrice  = strategy.position_avg_price * (1 - longLossPerc)// trail stop// Determine trail stop loss priceslongStopTrail = 0.0longStopTrail := if (strategy.position_size > 0)    stopValue = close * (1 - longTrailPerc)    max(stopValue, longStopTrail[1])else    0//Take profit PercentagelongExitPrice  = strategy.position_avg_price * (1 + longProfitPerc)//Enter trades when conditions are metstrategy.entry(id="long", long=strategy.long, when=enterLong, comment="long")//strategy.close("long", when = sale, comment = "Sell")//place exit orders (only executed after trades are active)strategy.exit(id="sell", limit = longExitPrice, stop = longStopTrail, comment = "SL/TP")