Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

DEMA-EMA & VOL (Short strategy)

A Pine Script v4 strategy built on EMA (close, 10), ATR (14) and Highest (high, 4). It has 2 order rules, 1 entry among them, and trades short only with the default settings. Exits use a stop loss and a profit target. Each trade is 10000 contracts and pays no commission. 13 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 & VOL (Short strategy) repaint?
No
No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
How did DEMA-EMA & VOL (Short strategy) do on BTCUSDT 1D with default settings?
Not measured
It closed no trades there from 26 Jan 2024 to 21 Oct 2026 with the default settings; it opened a short position that was still open on the last bar, so there is no result to report. It closed no trades on the other markets either. A backtest, not investment advice.
Can DEMA-EMA & VOL (Short strategy) be converted to Pine Script v5?
Not tested
The steps are shown below, but neither version placed a trade on any market tested, so there was nothing to compare and no download is offered.
Does DEMA-EMA & VOL (Short strategy) use a stop loss?
Yes
strategy.exit sets a stop on line 79.
Does DEMA-EMA & VOL (Short strategy) run in Zeal Terminal?
Yes
It compiles in 12 ms and runs 1,000 bars in 56 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 (13)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$-207,841,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.
Net profit
0.00%
$0.00
Buy and hold
+102.5%
same period
Closed trades
0
0 won · 0 lost
Profitable
0.0%
of closed trades
Profit factor
—
gross profit ÷ gross loss
Max drawdown
6,227,510.00%
−$622,751,000.00

One run with the author's default settings, $10,000 starting capital, commission as the script sets it. A short 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.

  • Likely bug

    atr(14) ignores the settings line 22

    Line 22 hard-codes 14 where line 37 uses “ATR Lookback Period”. Changing those settings moves one band but not this one.

    atr(14)atr(atrLookback)
  • Check

    1 setting does nothing

    “Show Moving Average?” is 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 77, 79. The upgraded version below moves each call inside an if block.

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

v4 → v5

Not verified

Neither version placed a trade on any of the 8 markets, so there was nothing to compare.

  • Line 3: //@version=4 → //@version=5
  • Line 11: ema → ta.ema
  • Line 12: ema → ta.ema
  • Line 18: input(type = input.integer) → input.int()
  • Line 19: ema → ta.ema
  • Line 22: atr → ta.atr
14 more edits
  • Line 25: input(type = input.resolution) → input.timeframe()
  • Line 26: input(type = input.integer) → input.int()
  • Line 27: input(type = input.bool) → input.bool()
  • Line 30: input(type = input.float) → input.float()
  • Line 31: input(type = input.float) → input.float()
  • Line 32: input(type = input.float) → input.float()
  • Line 37: security → request.security
  • Line 37: atr → ta.atr
  • Line 41: ema → ta.ema
  • Line 41: sma → ta.sma
  • Line 42: security → request.security
  • Line 49: crossunder → ta.crossunder
  • Line 50: crossover → ta.crossover
  • Line 63: highest → ta.highest
⋯// © Qorbanjf-//@version=4+//@version=5// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/⋯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)// get ATR VALUE-atr = atr(14)+atr = ta.atr(14)//ATRP (Average True Price in precentage)// 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")maLength = input(defval = 20, title = "Moving Average Period", minval = 1)-slType = input(title="Stop Loss ATR / %", type=input.float, defval=5.0, step=0.1)+slType = input.float(title="Stop Loss ATR / %", defval=5.0, step=0.1)-slMulti = input(title="SL Multiplier", type=input.float, defval=1.0, step=0.1)+slMulti = input.float(title="SL Multiplier", defval=1.0, step=0.1)-minimumProfitPercent = input(title="Minimum profit %", type=input.float, defval=20.00)+minimumProfitPercent = input.float(title="Minimum profit %", defval=20.00)// ATR Logic⋯// 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))// Determine percentage of open profit⋯profitSignal = minimumProfitPercent == 0.0 or distanceProfitPercent >= minimumProfitPercent-shortSignal = crossunder(dema1, ema1) and atrp > maFilter and strategy.position_size == 0 and not na(atr)+shortSignal = ta.crossunder(dema1, ema1) and atrp > maFilter and strategy.position_size == 0 and not na(atr)-exitSignal = profitSignal and strategy.position_size !=0 and  crossover(dema1, ema1)+exitSignal = profitSignal and strategy.position_size !=0 and  ta.crossover(dema1, ema1)// === INPUT BACKTEST RANGE ===⋯// Get stop loss (in pips AND percentage distance)-shortStop = highest(high, 4) - (atr * slMulti)+shortStop = ta.highest(high, 4) - (atr * slMulti)shortStopPercent = close - (close * slMulti)⋯

Clean v5

Not verified

Neither version placed a trade on any of the 8 markets, so there was nothing to compare.

  • Line 9: input() → input.int()
  • Line 10: input() → input.source()
  • Line 16: input() → input.int()
  • Line 17: input() → input.source()
  • Line 28: input() → input.string()
  • Line 29: input() → input.int()
  • Line 77: when = enterShort → if block
  • Line 79: when = strategy.position_size > 0 → 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)slType = input.float(title="Stop Loss ATR / %", defval=5.0, step=0.1)⋯//Enter trades when conditions are met-strategy.entry("short", strategy.short, when=enterShort, comment="SHORT")+if enterShort+    strategy.entry("short", strategy.short, comment="SHORT")//place exit orders (only executed after trades are active)-strategy.exit(id="Short exit",- from_entry="short",- limit=exitSignal ? close : na,- stop=shortStopSaved,- when=strategy.position_size > 0,- comment="end short")+if strategy.position_size > 0+    strategy.exit(id="Short exit",+     from_entry="short",+     limit=exitSignal ? close : na,+     stop=shortStopSaved,+     comment="end short") ⋯

Does it run in Pine Script v6?

No

The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L70:C22: 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.

⋯// © Qorbanjf-//@version=5+//@version=6// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/⋯

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 41
Sourceclosesourcee1 line 41
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 41
Moving Average Period20int · min 1maFilter
Stop Loss ATR / %5.0float · step 0.1shortStopSaved
SL Multiplier1.0float · step 0.1shortStop shortStopPercent
Minimum profit %20.00floatprofitSignal

What it calculates

  • EMA (ema, ta.ema in v5)Source (close), DEMA LENGTH (10)e1 · line 11
  • EMA (ema, ta.ema in v5)e1, DEMA LENGTH (10)e2 · line 12
  • EMA (ema, ta.ema in v5)Source (close), EMA Length (25)ema1 · line 19
  • ATR (atr, ta.atr in v5)14atr · line 22
  • ATR (atr, ta.atr in v5)ATR Lookback Period (14)atrValue · line 37
  • Highest (highest, ta.highest in v5)high, 4shortStop · line 63

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 · 14highhighprice dataslMultiSL Multipliersetting · 1.0maTypeMoving Average Typesetting · EMAmaLengthMoving Average Periodsetting · 20lowlowprice dataslTypeStop Loss ATR / %setting · 5.0minimumProfitPercentMinimum profit %setting · 20.00e1EMA→ e1e2EMA→ e2ema1EMA→ ema1atrATR→ atratrValueATR→ atrValueshortStopHighest→ shortStopdema1dema1valueatrpatrpvaluemaFiltermaFiltervalueentryentryvaluedistanceProfitdistanceProfitvaluedistanceProfitPercentdistanceProfitPercentvalueshortStopPercentshortStopPercentvalueshortStopSavedshortStopSavedvalueprofitSignalprofitSignalconditionshortSignalshortSignalconditionexitSignalexitSignalconditionentry:shortOpen shortstrategy.entryexit:Short exitexit Short exitstrategy.exitplot:14DEMAplotplot:20EMAplot

Order rules

OrderFires whenBy defaultLine
Open short shortenterShortOn77
Exit Short exit stop and limitstrategy.position_size > 0On79

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.

Not measuredNo trades to compareThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, but neither the live nor the historical run produced any trades in them, so the replay says nothing either way.
  • 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 1D0.0%+102.5%00%—6,227,510.0%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h0.0%+5.5%00%—824,541.0%8 May 2026 – 21 Oct 2026
ETHUSDT 1D0.0%+9.8%00%—146,394.0%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h0.0%+8.4%00%—71,173.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D0.0%+16.7%00%—15,499.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h0.0%+21.5%00%—3,452.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D0.0%+148.3%00%—83,761.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h0.0%+17.1%00%—14,931.0%8 May 2026 – 21 Oct 2026

Backtests are simulations on historical data and are not investment advice.

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 & VOL (Short strategy) this page—v4 strategy0.0%06,227,510.0%
Richard's Strategy by Deepak8369highest atr emav4 strategy+34.6%7026.3%
Classic Long Term Trend Following System by Robrecht99ema highest atrv5 strategy+2.9%51.1%
Strategy Myth-Busting #1 - UT Bot+STC+Hull [MYN] by myncryptoatr ema highestv5 strategy−30.7%1063.5%
Strategy for UT Bot Alerts indicator by StrategiesForEveryoneema atr highestv5 strategy−4.5%4215.7%
Simple and Profitable Scalping Strategy (ForexSignals TV) by kevinmck100ema atr highestv5 strategyNo trades on this market

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 12 msYes 1,000 bars in 56 msNot measured
PineTSNo v5 and v6 only—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. 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=4// 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("Qorban: DEMA/EMA & VOL Short ONLY", shorttitle="DEMA/EMA & VOL SHORT", 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)// get ATR VALUEatr = atr(14)//ATRP (Average True Price in precentage)// 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)slType = input(title="Stop Loss ATR / %", type=input.float, defval=5.0, step=0.1)slMulti = input(title="SL Multiplier", type=input.float, defval=1.0, step=0.1)minimumProfitPercent = input(title="Minimum profit %", type=input.float, defval=20.00)// 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))// Determine percentage of open profitvar entry = 0.0distanceProfit = low - entrydistanceProfitPercent = distanceProfit / entry//Determin if we have a long entry signal OR a sell position signalprofitSignal = minimumProfitPercent == 0.0 or distanceProfitPercent >= minimumProfitPercentshortSignal = crossunder(dema1, ema1) and atrp > maFilter and strategy.position_size == 0 and not na(atr)exitSignal = profitSignal and strategy.position_size !=0 and  crossover(dema1, ema1)// === 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)//Invert trade direction & flipping //tradInvert = input(defval = false, title = "invert trade direction")//MOM_MR = input(defval=1, title = "MOM = 1 / MR = -1", minval=-1, maxval=1)//plots=input(false, title="Show plots?")// Get stop loss (in pips AND percentage distance)shortStop = highest(high, 4) - (atr * slMulti)shortStopPercent = close - (close * slMulti)// Save long stop & target prices (used for drawing data to the chart & deetermining profit)var shortStopSaved = 0.0var shortTargetSaved = 0.0enterShort = falseif shortSignal    shortStopSaved := slType ? shortStop : shortStopPercent    enterShort:= true    entry := close// long conditions //enterLong = crossover(dema1, ema1) and atrp < maFilter//exitSignal => crossunder(dema1, ema1)//Enter trades when conditions are metstrategy.entry("short", strategy.short, when=enterShort, comment="SHORT")//place exit orders (only executed after trades are active)strategy.exit(id="Short exit", from_entry="short", limit=exitSignal ? close : na, stop=shortStopSaved, when=strategy.position_size > 0, comment="end short") //short strategy//goShort() => crossunder(dema1, ema1) and atrp > maFilter//KillShort() => crossover(dema1, ema1) //strategy.entry("SHORT", strategy.short, when = goShort())//strategy.close("COVER", when = KillShort())