Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

ADX strategy (considering ADX and +DI only )

A Pine Script v4 strategy built on SMA (DX, 11) and EMA (close, 13). It has 4 order rules, 2 entries among them, and trades long only with the default settings. Exits wait for a signal; there is no stop loss. Each trade is 3 contracts and pays no commission. 5 settings; defaults include ADX Length 11, threshold 30 and Fast EMA 13.

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 ADX strategy (considering ADX and +DI only ) repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 3 of 3 trades.
How did ADX strategy (considering ADX and +DI only ) do on BTCUSDT 1D with default settings?
+678.85%
From 26 Jan 2024 to 21 Oct 2026, over 13 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can ADX strategy (considering ADX and +DI only ) 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 ADX strategy (considering ADX and +DI only ) use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does ADX strategy (considering ADX and +DI only ) run in Zeal Terminal?
Yes
It compiles in 28 ms and runs 1,000 bars in 47 ms, in the browser.

BTCUSDT · 1D · default settings

  • DI+
  • ADX
  • HLine
  • 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 (5)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOctDI+$87,137$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 = true as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 33, 37) so the engine trades the way the script says.
Net profit
+678.85%
$67,884.60
Buy and hold
+102.5%
same period
Closed trades
13
7 won · 6 lost
Profitable
53.8%
of closed trades
Profit factor
1.45
gross profit ÷ gross loss
Max drawdown
693.46%
−$117,728.00

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.

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

  • Note

    Uses an argument v6 removed

    when = on line 33, 37, 40, 43. The upgraded version below moves each call inside an if block.

  • Note

    Uses long =, which v5 renamed line 33

    long = on line 33, 37. 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 max → math.max, abs → math.abs, sma → ta.sma, ema → ta.ema, crossover → ta.crossover, crossunder → ta.crossunder.
  • 4 strategy calls use the when = argument (line 33, 37, 40, 43). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

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

  • Line 3: //@version=4 → //@version=5
  • Line 14: max → math.max
  • Line 14: max → math.max
  • Line 14: abs → math.abs
  • Line 14: abs → math.abs
  • Line 15: max → math.max
10 more edits
  • Line 16: max → math.max
  • Line 22: abs → math.abs
  • Line 23: sma → ta.sma
  • Line 28: ema → ta.ema
  • Line 29: ema → ta.ema
  • Line 31: crossover → ta.crossover
  • Line 33: long = true → direction = strategy.long
  • Line 37: long = true → direction = strategy.long
  • Line 37: crossover → ta.crossover
  • Line 42: crossunder → ta.crossunder
⋯// © mohanee-//@version=4+//@version=5//ADX strategy⋯stopLoss =input(8, title="Stop Loss",minval=1)   //-TrueRange = max(max(high-low, abs(high-nz(close[1]))), abs(low-nz(close[1])))+TrueRange = math.max(math.max(high-low, math.abs(high-nz(close[1]))), math.abs(low-nz(close[1])))-DirectionalMovementPlus = high-nz(high[1]) > nz(low[1])-low ? max(high-nz(high[1]), 0): 0+DirectionalMovementPlus = high-nz(high[1]) > nz(low[1])-low ? math.max(high-nz(high[1]), 0): 0-DirectionalMovementMinus = nz(low[1])-low > high-nz(high[1]) ? max(nz(low[1])-low, 0): 0+DirectionalMovementMinus = nz(low[1])-low > high-nz(high[1]) ? math.max(nz(low[1])-low, 0): 0SmoothedTrueRange:= nz(SmoothedTrueRange[1]) - (nz(SmoothedTrueRange[1])/len) + TrueRange⋯DIMinus = SmoothedDirectionalMovementMinus / SmoothedTrueRange * 100-DX = abs(DIPlus-DIMinus) / (DIPlus+DIMinus)*100+DX = math.abs(DIPlus-DIMinus) / (DIPlus+DIMinus)*100-ADX = sma(DX, len)+ADX = ta.sma(DX, len)plot(DIPlus, color=color.green, title="DI+")⋯hline(threshold, color=color.black, linestyle=hline.style_dashed)-fastEmaVal=ema(close,fastEma)+fastEmaVal=ta.ema(close,fastEma)-slowEmaVal=ema(close,slowEma)+slowEmaVal=ta.ema(close,slowEma)//long condition-longCondition=  ADX < threshold  and crossover(DIPlus,ADX)  and fastEmaVal > slowEmaVal+longCondition=  ADX < threshold  and ta.crossover(DIPlus,ADX)  and fastEmaVal > slowEmaValbarcolor(longCondition ? color.yellow: na)-strategy.entry(id="ADXLE", long=true,  when= longCondition  and strategy.position_size<1) +strategy.entry(id="ADXLE", direction = strategy.long,  when= longCondition  and strategy.position_size<1) barcolor(strategy.position_size>1 ? color.blue: na)⋯//Add-strategy.entry(id="ADXLE", comment="Add", long=true,  when= strategy.position_size>1 and close<strategy.position_avg_price and crossover(DIPlus,ADX) ) +strategy.entry(id="ADXLE", comment="Add", direction = strategy.long,  when= strategy.position_size>1 and close<strategy.position_avg_price and ta.crossover(DIPlus,ADX) ) //calculate stop Loss⋯//exit condition-exitCondition=  ADX > threshold  and crossunder(DIPlus,ADX) // and fastEmaVal > slowEmaVal+exitCondition=  ADX > threshold  and ta.crossunder(DIPlus,ADX) // and fastEmaVal > slowEmaValstrategy.close(id="ADXLE",comment="TPExitAll",    qty=strategy.position_size ,   when= exitCondition)   //close all

Clean v5

VerifiedDownload the v5 script

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

  • Line 9: input() → input.int()
  • Line 10: input() → input.int()
  • Line 11: input() → input.int()
  • Line 12: input() → input.int()
  • Line 13: input() → input.int()
  • Line 33: when = longCondition and strategy.position_size<1 → if block
3 more edits
  • Line 37: when = strategy.position_size>1 and close<strategy.position_avg_price and ta.crossover(DIPlus,ADX) → if block
  • Line 40: when = close<stopLossVal → if block
  • Line 43: when = exitCondition → if block
⋯strategy(title="ADX strategy", overlay=false,pyramiding=3, default_qty_type=strategy.fixed, default_qty_value=3,    initial_capital=10000, currency=currency.USD)-len = input(11, title="ADX Length", minval=1)+len = input.int(11, title="ADX Length", minval=1)-threshold = input(30, title="threshold", minval=5)+threshold = input.int(30, title="threshold", minval=5)-fastEma=input(13, title="Fast EMA",minval=1, maxval=50)+fastEma=input.int(13, title="Fast EMA",minval=1, maxval=50)-slowEma=input(55, title="Slow EMA",minval=10, maxval=200)+slowEma=input.int(55, title="Slow EMA",minval=10, maxval=200)-stopLoss =input(8, title="Stop Loss",minval=1)   //+stopLoss =input.int(8, title="Stop Loss",minval=1)   //TrueRange = math.max(math.max(high-low, math.abs(high-nz(close[1]))), math.abs(low-nz(close[1])))⋯barcolor(longCondition ? color.yellow: na)-strategy.entry(id="ADXLE", direction = strategy.long,  when= longCondition  and strategy.position_size<1) +if longCondition  and strategy.position_size<1+    strategy.entry(id="ADXLE", direction = strategy.long) barcolor(strategy.position_size>1 ? color.blue: na)⋯//Add-strategy.entry(id="ADXLE", comment="Add", direction = strategy.long,  when= strategy.position_size>1 and close<strategy.position_avg_price and ta.crossover(DIPlus,ADX) ) +if strategy.position_size>1 and close<strategy.position_avg_price and ta.crossover(DIPlus,ADX)+    strategy.entry(id="ADXLE", comment="Add", direction = strategy.long ) //calculate stop LossstopLossVal =  strategy.position_avg_price -  (strategy.position_avg_price*stopLoss*0.01)-strategy.close(id="ADXLE",comment="SL Exit",    when=close<stopLossVal)   //close all on stop loss+if close<stopLossVal+    strategy.close(id="ADXLE",comment="SL Exit")   //close all on stop loss//exit conditionexitCondition=  ADX > threshold  and ta.crossunder(DIPlus,ADX) // and fastEmaVal > slowEmaVal-strategy.close(id="ADXLE",comment="TPExitAll",    qty=strategy.position_size ,   when= exitCondition)   //close all+if exitCondition+    strategy.close(id="ADXLE",comment="TPExitAll",    qty=strategy.position_size )   //close all

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

⋯// © mohanee-//@version=5+//@version=6//ADX strategy⋯

Settings

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

SettingDefaultType and rangeFeeds
ADX Length11int · min 1SmoothedTrueRange SmoothedDirectionalMovementPlus SmoothedDirectionalMovementMinus ADX
threshold30int · min 5longCondition exitCondition hline
Fast EMA13int · min 1 · max 50fastEmaVal
Slow EMA55int · min 10 · max 200slowEmaVal
Stop Loss8int · min 1stopLossVal

What it calculates

  • SMA (sma, ta.sma in v5)DX, ADX Length (11)ADX · line 23
  • EMA (ema, ta.ema in v5)close, Fast EMA (13)fastEmaVal · line 28
  • EMA (ema, ta.ema in v5)close, Slow EMA (55)slowEmaVal · line 29

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.

lenADX Lengthsetting · 11closecloseprice datafastEmaFast EMAsetting · 13slowEmaSlow EMAsetting · 55lowlowprice datahighhighprice datastopLossStop Losssetting · 8thresholdthresholdsetting · 30ADXSMA→ ADXfastEmaValEMA→ fastEmaValslowEmaValEMA→ slowEmaValSmoothedTrueRangeSmoothedTrueRangevalueSmoothedDirectionalMovementPlusSmoothedDirectionalMove…valueSmoothedDirectionalMovementMinusSmoothedDirectionalMove…valueTrueRangeTrueRangevalueDirectionalMovementPlus, DirectionalMovementMinusDirectionalMovementPlus…2 valuesDIPlusDIPlusvalueDIMinusDIMinusvalueDXDXvaluestopLossValstopLossValvalueexitConditionexitConditionconditionlongConditionlongConditionconditionentry:ADXLEOpen ADXLEstrategy.entryclose:ADXLEClose ADXLEstrategy.closeplot:24DI+plotplot:26ADXplothline:27hlinehlinebarcolor:32barcolorbarcolorbarcolor:34barcolorbarcolorbgcolor:35bgcolorbgcolor

Order rules

OrderFires whenBy defaultLine
Open ADXLE longlongCondition and strategy.position_size<1On33
Open ADXLE longstrategy.position_size>1 and close<strategy.position_avg_price and crossover(DIPlus,ADX)On37
Close ADXLEclose<stopLossValOn40
Close ADXLEexitConditionADX > threshold and crossunder(DIPlus,ADX)On43

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.

3/3trades 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+678.8%+102.5%1354%1.45693.5%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+401.4%+5.5%1173%2.14450.9%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−59.3%+9.8%1323%0.4799.9%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+37.5%+8.4%1479%2.6214.8%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+2.7%+16.7%1354%1.562.5%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+1.3%+21.5%1573%2.500.7%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+3.3%+148.3%1560%1.279.2%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+9.5%+17.1%17100%—1.8%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 market560%$46,311.10
Sideways market743%$18,017.10
Falling market1100%$3,556.41

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

How bad could the drawdown be?

1,255.6%

The 95th percentile of the worst drawdown when the same 13 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 152.1% to 1,255.6%; the tick is what actually happened, 595.1%. Order luck alone moves it this much.

0%1,444%
All 13 trades
SideEntryExitBarsP&L
long26 Mar 2024 69,880.0014 Apr 2024 63,924.5019−$17,866.40
long3 Jun 2024 67,765.6025 Jun 2024 60,293.3022−$22,417.00
long27 Jul 2024 67,908.003 Aug 2024 61,498.307−$19,229.00
long8 Oct 2024 62,224.0015 Nov 2024 87,325.6038$75,304.70
long4 Jan 2025 98,174.2026 Feb 2025 88,680.4053−$28,481.30
long23 May 2025 111,696.0017 Jul 2025 118,630.0055$20,802.70
long3 Jun 2025 105,858.0017 Jul 2025 118,630.0044$38,317.30
long17 Jun 2025 106,795.0017 Jul 2025 118,630.0030$35,507.70
long5 Aug 2025 115,055.008 Oct 2025 121,333.0064$18,833.80
long9 Sep 2025 112,065.008 Oct 2025 121,333.0029$27,803.20
long18 Apr 2026 77,072.0024 Apr 2026 78,257.506$3,556.41
long22 May 2026 77,615.503 Jun 2026 66,760.8012−$32,564.00
long26 May 2026 77,322.003 Jun 2026 66,760.808−$31,683.50

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
ADX strategy (considering ADX and +DI only ) this page—v4 strategy+678.8%13693.5%
MACD Long Strat by TheGrindTodayema smav4 strategy+24.0%7920.1%
Stock trending strategy by exlux99ema smav4 strategy+35.3%2114.7%
4-Hour Stochastic EMA Trend by slymnturkogluema smav4 strategyNo trades on this market
4X EMA and volume strategy by SoftKill21ema smav4 strategy+1.8%325.8%
Simple Momentum Strategy Based on SMA, EMA and Volume by slip_streamsma emav4 strategy+7.4%1827.4%

Where it runs

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

Zeal Terminal's engine currently reads an order side written as long = true as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 33, 37) 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/// © mohanee//@version=4//ADX strategySmoothedTrueRange=0.00SmoothedDirectionalMovementPlus=0.00SmoothedDirectionalMovementMinus=0.00strategy(title="ADX strategy", overlay=false,pyramiding=3, default_qty_type=strategy.fixed, default_qty_value=3,    initial_capital=10000, currency=currency.USD)len = input(11, title="ADX Length", minval=1)threshold = input(30, title="threshold", minval=5)fastEma=input(13, title="Fast EMA",minval=1, maxval=50)slowEma=input(55, title="Slow EMA",minval=10, maxval=200)stopLoss =input(8, title="Stop Loss",minval=1)   //TrueRange = max(max(high-low, abs(high-nz(close[1]))), abs(low-nz(close[1])))DirectionalMovementPlus = high-nz(high[1]) > nz(low[1])-low ? max(high-nz(high[1]), 0): 0DirectionalMovementMinus = nz(low[1])-low > high-nz(high[1]) ? max(nz(low[1])-low, 0): 0SmoothedTrueRange:= nz(SmoothedTrueRange[1]) - (nz(SmoothedTrueRange[1])/len) + TrueRangeSmoothedDirectionalMovementPlus := nz(SmoothedDirectionalMovementPlus[1]) - (nz(SmoothedDirectionalMovementPlus[1])/len) + DirectionalMovementPlusSmoothedDirectionalMovementMinus:= nz(SmoothedDirectionalMovementMinus[1]) - (nz(SmoothedDirectionalMovementMinus[1])/len) + DirectionalMovementMinusDIPlus = SmoothedDirectionalMovementPlus / SmoothedTrueRange * 100DIMinus = SmoothedDirectionalMovementMinus / SmoothedTrueRange * 100DX = abs(DIPlus-DIMinus) / (DIPlus+DIMinus)*100ADX = sma(DX, len)plot(DIPlus, color=color.green, title="DI+")//plot(DIMinus, color=color.red, title="DI-")plot(ADX, color=color.black, title="ADX")hline(threshold, color=color.black, linestyle=hline.style_dashed)fastEmaVal=ema(close,fastEma)slowEmaVal=ema(close,slowEma)//long conditionlongCondition=  ADX < threshold  and crossover(DIPlus,ADX)  and fastEmaVal > slowEmaValbarcolor(longCondition ? color.yellow: na)strategy.entry(id="ADXLE", long=true,  when= longCondition  and strategy.position_size<1) barcolor(strategy.position_size>1 ? color.blue: na)bgcolor(strategy.position_size>1 ? color.blue: na)//Addstrategy.entry(id="ADXLE", comment="Add", long=true,  when= strategy.position_size>1 and close<strategy.position_avg_price and crossover(DIPlus,ADX) ) //calculate stop LossstopLossVal =  strategy.position_avg_price -  (strategy.position_avg_price*stopLoss*0.01)strategy.close(id="ADXLE",comment="SL Exit",    when=close<stopLossVal)   //close all on stop loss//exit conditionexitCondition=  ADX > threshold  and crossunder(DIPlus,ADX) // and fastEmaVal > slowEmaValstrategy.close(id="ADXLE",comment="TPExitAll",    qty=strategy.position_size ,   when= exitCondition)   //close all