Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

ADX - DMI Trend Strategy

A Pine Script v4 strategy built on SMA (volume, 20), ATR (14) and SAR (0.02, 0.02). It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. Each trade commits 100% of equity and pays 0.04% commission. 29 settings; defaults include From Year 2019, From Month 1 and From Day 1.

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 - DMI Trend Strategy repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 4 of 4 trades.
How did ADX - DMI Trend Strategy do on BTCUSDT 1D with default settings?
−0.83%
From 26 Jan 2024 to 21 Oct 2026, over 9 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can ADX - DMI Trend Strategy 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.
What alerts does ADX - DMI Trend Strategy have?
4
ADX | DMI Long; ADX | DMI Short; ADX | DMI Sell; ADX | DMI Cover.
Does ADX - DMI Trend Strategy use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.

BTCUSDT · 1D · default settings

  • Trend Filter MA
  • Plot
  • Plot
  • ParabolicSAR
  • 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 (29)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$9,917$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.83%
−$82.87
Buy and hold
+102.5%
same period
Closed trades
9
4 won · 5 lost
Profitable
44.4%
of closed trades
Profit factor
0.97
gross profit ÷ gross loss
Max drawdown
17.22%
−$1,722.30

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

    No stop loss

    Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.

  • Check

    Every trade uses all the equity

    default_qty_value is 100% of equity.

  • 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 112, 113, 114, 115. The upgraded version below moves each call inside an if block.

  • Note

    Uses transp =, which v5 removed line 53

    transp = on line 53. v5 folds the transparency into the colour with color.new(c, transp).

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 sma → ta.sma, ema → ta.ema, atr → ta.atr, sar → ta.sar, dmi → ta.dmi.
  • 4 strategy calls use the when = argument (line 112, 113, 114, 115). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

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

  • Line 1: //@version=4 → //@version=5
  • Line 21: input(type = input.bool) → input.bool()
  • Line 30: input(type = input.bool) → input.bool()
  • Line 36: sma → ta.sma
  • Line 46: input(type = input.bool) → input.bool()
  • Line 51: ema → ta.ema
9 more edits
  • Line 51: sma → ta.sma
  • Line 53: transp = 50 → color.new(color.green, 50)
  • Line 62: input(type = input.bool) → input.bool()
  • Line 63: input(type = input.integer) → input.int()
  • Line 64: input(type = input.float) → input.float()
  • Line 68: atr → ta.atr
  • Line 96: input(type = input.bool) → input.bool()
  • Line 100: sar → ta.sar
  • Line 106: dmi → ta.dmi
-//@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/⋯// == INPUTS ==-shortTrades = input(title = "Allow short trades?", type = input.bool, defval = true)+shortTrades = input.bool(title = "Allow short trades?", defval = true)// ADX Info⋯// Inputs-volFilter = input(title = "Use Volume as Entry Filter?", type = input.bool, defval = true)+volFilter = input.bool(title = "Use Volume as Entry Filter?", defval = true)volType = input(defval="Multiplier * Average", options=["Multiplier * Average", "Manual", "Multiplier * Average AND Manual"], title = "Volume Filtering Method")⋯// Check that volume is high before entering trade-xVol = sma(volume, volSMA)+xVol = ta.sma(volume, volSMA)xVolMult = xVol * volMult⋯// Inputs-useMaFilter = input(title = "Use MA for Entry Filtering?", type = input.bool, defval = true)+useMaFilter = input.bool(title = "Use MA for Entry Filtering?", defval = true)maType = input(defval="EMA", options=["EMA", "SMA"], title = "MA Type For Filtering")⋯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 = ma(maType, close, maLength)-plot(maFilter, title = "Trend Filter MA", color = color.green, linewidth = 3, style = plot.style_line, transp = 50)+plot(maFilter, title = "Trend Filter MA", color = color.new(color.green, 50), linewidth = 3, style = plot.style_line)// Check to see if the useMaFilter check box is checked, this then inputs this conditional "maFilterCheck" variable into the strategy entry ⋯// Inputs-useATR = input(title = "Use ATR for Trailing Stop?", type = input.bool, defval = true)+useATR = input.bool(title = "Use ATR for Trailing Stop?", defval = true)-atrLookback = input(defval=14,title="ATR Lookback Period",type=input.integer)+atrLookback = input.int(defval=14,title="ATR Lookback Period")-multiplier = input(defval=2,title="ATR Multiplier",type=input.float, step=0.1, minval=0.5, maxval=4)+multiplier = input.float(defval=2,title="ATR Multiplier", step=0.1, minval=0.5, maxval=4)trigInput = input(title = "Execute Trades On...", defval = "Wick", options=["Wick","Close"]) // Useful for comparing standing stop orders vs. waiting for candle closes prior to action⋯// Calculate the trailing ATR-atrValue = atr(atrLookback)+atrValue = ta.atr(atrLookback)atrMultiplied = atrValue * multiplier⋯// == LOOK AT PARABOLIC SAR AS AN EXIT OPTION ==-useSAR = input(title = "Use SAR for Trailing Stop?", type = input.bool, defval = true)+useSAR = input.bool(title = "Use SAR for Trailing Stop?", defval = true)sarStart = input(0.02, "Start")⋯sarMaximum = input(0.2, "Max Value")-sarOut = useSAR ? sar(sarStart, sarIncrement, sarMaximum) : na+sarOut = useSAR ? ta.sar(sarStart, sarIncrement, sarMaximum) : naplot(sarOut, "ParabolicSAR", style=plot.style_cross, color=#3A6CA8)⋯// == USE BUILT-IN DMI FUNCTION TO DETERMINE ADX AND BULL/BEAR STRENGTH-[diplus, diminus, adx] = dmi(dilen, adxlen)+[diplus, diminus, adx] = ta.dmi(dilen, adxlen)buySignal = (adx[0]-adx[adxLookbackEntry] > 0) and adx > keyLevel and diplus > diminus and time > Start and time < Finish and close >= maFilterCheck and volume > volCheck⋯

Clean v5

VerifiedDownload the v5 script

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

  • Line 12: input() → input.int()
  • Line 13: input() → input.int()
  • Line 14: input() → input.int()
  • Line 15: input() → input.int()
  • Line 16: input() → input.int()
  • Line 17: input() → input.int()
20 more edits
  • Line 23: input() → input.int()
  • Line 24: input() → input.int()
  • Line 25: input() → input.int()
  • Line 26: input() → input.int()
  • Line 27: input() → input.int()
  • Line 31: input() → input.string()
  • Line 32: input() → input.int()
  • Line 33: input() → input.int()
  • Line 34: input() → input.int()
  • Line 47: input() → input.string()
  • Line 48: input() → input.int()
  • Line 65: input() → input.string()
  • Line 66: input() → input.string()
  • Line 97: input() → input.float()
  • Line 98: input() → input.float()
  • Line 99: input() → input.float()
  • Line 112: when = buySignal → if block
  • Line 113: when = sellSignal → if block
  • Line 114: when = shortSignal → if block
  • Line 115: when = coverSignal → if block
⋯// === BACKTEST RANGE ===-From_Year  = input(defval = 2019, title = "From Year")+From_Year  = input.int(defval = 2019, title = "From Year")-From_Month = input(defval = 1, title = "From Month", minval = 1, maxval = 12)+From_Month = input.int(defval = 1, title = "From Month", minval = 1, maxval = 12)-From_Day   = input(defval = 1, title = "From Day", minval = 1, maxval = 31)+From_Day   = input.int(defval = 1, title = "From Day", minval = 1, maxval = 31)-To_Year    = input(defval = 9999, title = "To Year")+To_Year    = input.int(defval = 9999, title = "To Year")-To_Month   = input(defval = 1, title = "To Month", minval = 1, maxval = 12)+To_Month   = input.int(defval = 1, title = "To Month", minval = 1, maxval = 12)-To_Day     = input(defval = 1, title = "To Day", minval = 1, maxval = 31)+To_Day     = input.int(defval = 1, title = "To Day", minval = 1, maxval = 31)Start  = timestamp(From_Year, From_Month, From_Day, 00, 00)  // backtest start window⋯// ADX Info-adxlen = input(14, title="ADX Smoothing")+adxlen = input.int(14, title="ADX Smoothing")-dilen = input(14, title="DI Period")+dilen = input.int(14, title="DI Period")-keyLevel = input(23, title="Keylevel for ADX")+keyLevel = input.int(23, title="Keylevel for ADX")-adxLookbackEntry = input(3, title="Lookback Period for Slope (Entry)")+adxLookbackEntry = input.int(3, title="Lookback Period for Slope (Entry)")-adxLookbackExit = input(1, title="Lookback Period for Slope (Exit)")+adxLookbackExit = input.int(1, title="Lookback Period for Slope (Exit)")// == VOLUME FILTERING ==⋯volFilter = input.bool(title = "Use Volume as Entry Filter?", defval = true)-volType = input(defval="Multiplier * Average", options=["Multiplier * Average", "Manual", "Multiplier * Average AND Manual"], title = "Volume Filtering Method")+volType = input.string(defval="Multiplier * Average", options=["Multiplier * Average", "Manual", "Multiplier * Average AND Manual"], title = "Volume Filtering Method")-volMult = input(title = "Volume Trigger Multiplier", defval = 2, step = 0.1)+volMult = input.int(title = "Volume Trigger Multiplier", defval = 2, step = 0.1)-volSMA = input(title = "Volume Trigger Average Bars Back", defval = 20, step = 1)+volSMA = input.int(title = "Volume Trigger Average Bars Back", defval = 20, step = 1)-volManual = input(20000, title="Manual Volume Value", step = 1000)+volManual = input.int(20000, title="Manual Volume Value", step = 1000)// Check that volume is high before entering trade⋯useMaFilter = input.bool(title = "Use MA for Entry Filtering?", defval = true)-maType = input(defval="EMA", options=["EMA", "SMA"], title = "MA Type For Filtering")+maType = input.string(defval="EMA", options=["EMA", "SMA"], title = "MA Type For Filtering")-maLength   = input(defval = 200, title = "MA Period for Filtering", minval = 1)+maLength   = input.int(defval = 200, title = "MA Period for Filtering", minval = 1)// Declare function to be able to swap out EMA/SMA⋯multiplier = input.float(defval=2,title="ATR Multiplier", step=0.1, minval=0.5, maxval=4)-trigInput = input(title = "Execute Trades On...", defval = "Wick", options=["Wick","Close"]) // Useful for comparing standing stop orders vs. waiting for candle closes prior to action+trigInput = input.string(title = "Execute Trades On...", defval = "Wick", options=["Wick","Close"]) // Useful for comparing standing stop orders vs. waiting for candle closes prior to action-showInput = input(title="Show Trailing ATR", defval="Both", options=["Support","Resistance","Both"]) +showInput = input.string(title="Show Trailing ATR", defval="Both", options=["Support","Resistance","Both"]) // Calculate the trailing ATR⋯useSAR = input.bool(title = "Use SAR for Trailing Stop?", defval = true)-sarStart = input(0.02, "Start")+sarStart = input.float(0.02, "Start")-sarIncrement = input(0.02, "Increment")+sarIncrement = input.float(0.02, "Increment")-sarMaximum = input(0.2, "Max Value")+sarMaximum = input.float(0.2, "Max Value")sarOut = useSAR ? ta.sar(sarStart, sarIncrement, sarMaximum) : na⋯// == STRATEGY ENTRIES/EXITS == -strategy.entry("Long", strategy.long, when = buySignal)+if buySignal+    strategy.entry("Long", strategy.long)-strategy.close("Long", when = sellSignal)+if sellSignal+    strategy.close("Long")-strategy.entry("Short", strategy.short, when = shortSignal)+if shortSignal+    strategy.entry("Short", strategy.short)-strategy.close("Short", when = coverSignal)+if coverSignal+    strategy.close("Short")    ⋯

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: 9 before, 17 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.

-//@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
From Year2019intStart
From Month1int · min 1 · max 12Start
From Day1int · min 1 · max 31Start
To Year9999intFinish
To Month1int · min 1 · max 12Finish
To Day1int · min 1 · max 31Finish
Allow short trades?trueboolshortSignal
ADX Smoothing14intdiplus diminus adx
DI Period14intdiplus diminus adx
Keylevel for ADX23intbuySignal shortSignal
Lookback Period for Slope (Entry)3intbuySignal shortSignal
Lookback Period for Slope (Exit)1intsellSignal coverSignal
Use Volume as Entry Filter?trueboolvolCheck
Volume Filtering MethodMultiplier * Averagestring · options ["Multiplier * Average", "Manual", "Multiplier * Average AND Manual"]volCheck
Volume Trigger Multiplier2int · step 0.1xVolMult
Volume Trigger Average Bars Back20int · step 1xVol
Manual Volume Value20000int · step 1000manualCompare xVolManual volCheck
Use MA for Entry Filtering?trueboolmaFilterCheck
MA Type For FilteringEMAstring · options ["EMA", "SMA"]maFilter line 51
MA Period for Filtering200int · min 1maFilter
Use ATR for Trailing Stop?trueboolatrResistanceHit atrSupportHit plotLow plotHigh
ATR Lookback Period14int (written input.integer)atrValue
ATR Multiplier2float · min 0.5 · max 4 · step 0.1atrMultiplied
Execute Trades On...Wickstring · options ["Wick","Close"]trigResistance trigSupport
Show Trailing ATRBothstring · options ["Support","Resistance","Both"]plotLow plotHigh
Use SAR for Trailing Stop?trueboolsarOut sarResistanceHit sarSupportHit
Start0.02floatsarOut
Increment0.02floatsarOut
Max Value0.2floatsarOut

What it calculates

  • SMA (sma, ta.sma in v5)volume, Volume Trigger Average Bars Back (20)xVol · line 36
  • ATR (atr, ta.atr in v5)ATR Lookback Period (14)atrValue · line 68
  • SAR (sar, ta.sar in v5)Start (0.02), Increment (0.02), Max Value (0.2)sarOut · line 100
  • DMI (dmi, ta.dmi in v5)DI Period (14), ADX Smoothing (14)diplus · line 106
  • DMI (dmi, ta.dmi in v5)DI Period (14), ADX Smoothing (14)diminus · line 106
  • DMI (dmi, ta.dmi in v5)DI Period (14), ADX Smoothing (14)adx · line 106

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.

The script has 73 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.

Order rules

OrderFires whenBy defaultLine
Open Long longbuySignal(adx[0]-adx[adxLookbackEntry] > 0) and adx > keyLevel and diplus > diminus and time > Start and time < Finish and close >= maFilterCheck and volume > volCheckOn112
Close LongsellSignal(adx[0]-adx[adxLookbackExit] < 0) or atrSupportHit or sarSupportHitOn113
Open Short shortshortSignal(adx[0]-adx[adxLookbackEntry] > 0) and adx > keyLevel and diplus < diminus and time > Start and time < Finish and close <= maFilterCheck and shortTrades and volume > volCheckOn114
Close ShortcoverSignal(adx[0]-adx[adxLookbackExit] < 0) or atrResistanceHit or sarResistanceHitOn115

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

Alerts

AlertCallMessageLine
ADX | DMI LongalertconditionADX | DMI Long118
ADX | DMI ShortalertconditionADX | DMI Short119
ADX | DMI SellalertconditionADX | DMI Sell120
ADX | DMI CoveralertconditionADX | DMI Cover121

Does it repaint?

No

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

4/4trades 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−0.8%+102.5%944%0.9717.2%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−0.6%+5.5%1127%0.968.6%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−1.9%+9.8%1242%0.9625.5%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−3.7%+8.4%1429%0.8111.6%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+21.5%+16.7%1050%1.6022.3%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−5.4%+21.5%1323%0.689.8%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+6.2%+148.3%1155%1.3327.7%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+3.1%+17.1%1233%1.297.0%8 May 2026 – 21 Oct 2026

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

Settings heatmap

Two settings that feed the entry signal, moved around their defaults. The best in-sample pair (ADX Smoothing 24, DI Period 20) made −10.1% before 26 Dec 2025 and −14.3% after it, worse than the defaults' +14.5% after. Tuning on the past did not carry forward. 0% of the 64 combinations made money in-sample and 84% out-of-sample.

Before 26 Dec 2025 · in-sample
DI Period ↓ · ADX Smoothing →78101214172024
7−28%−28%−20%−20%−20%−21%−27%−27%
8−29%−21%−21%−21%−23%−27%−27%−27%
10−18%−18%−21%−25%−25%−28%−28%−21%
12−19%−20%−25%−25%−24%−24%−24%−20%
14−16%−17%−18%−17%−15%−19%−21%−21%
17−13%−13%−10%−12%−12%−12%−12%−12%
20−15%−13%−12%−12%−12%−12%−12%−10%
24−13%−12%−12%−12%−12%−10%−13%−12%
From 26 Dec 2025 · out-of-sample
DI Period ↓ · ADX Smoothing →78101214172024
7+19%+19%+21%+21%+21%+21%+19%+19%
8+19%+21%+21%+21%+20%+19%+19%+19%
10+22%+22%+21%+20%+19%+18%+19%+20%
12+22%+21%+19%+19%+13%+13%+13%+14%
14+22%+21%+14%+14%+15%+14%+14%+14%
17+17%+10%+10%+10%+10%+10%+10%+9%
20+10%+10%+10%+6%+6%−14%−14%−14%
24+6%−13%−13%−12%−16%−17%−13%−3%

Net P&L of trades opened in each period, as a share of starting capital. marks the defaults and the best in-sample cell. Hover a cell for its trade count. Backtests are simulations on historical data and are not investment advice.

The trades

By market direction

At entry, last 90 barsTradesWonP&L
Rising market367%$193.27
Sideways market333%−$854.13
Falling market333%$578.00

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

How bad could the drawdown be?

22.4%

The 95th percentile of the worst drawdown when the same 9 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 12.0% to 22.4%; the tick is what actually happened, 15.4%. Order luck alone moves it this much.

0%26%
All 9 trades
SideEntryExitBarsP&L
short7 Sep 2024 53,963.0010 Sep 2024 57,042.003−$578.58
long12 Nov 2024 88,648.0026 Nov 2024 93,010.0014$455.69
short27 Feb 2025 84,250.103 Mar 2025 94,270.004−$1,182.59
long16 Jul 2025 117,758.0019 Jul 2025 117,925.003$5.35
short22 Nov 2025 85,129.4026 Nov 2025 87,370.004−$235.93
short31 Jan 2026 84,260.509 Feb 2026 70,330.409$1,392.51
short3 Jun 2026 66,760.8012 Jun 2026 63,626.009$454.94
long22 Aug 2026 78,338.002 Sep 2026 77,439.0011−$126.49
long22 Sep 2026 86,620.0025 Sep 2026 84,410.203−$267.76

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 - DMI Trend Strategy this page—v4 strategy−0.8%917.2%
I11L - Better Buy Low Volatility or High Volatility- by I11Latr smav5 strategy+19.2%8337.4%
Vortex Cross w-MA Confirmation by DraftVentureatr smav5 strategy+2.4%524.7%
Configurable Multi MA Crossover Voting System by levieuxsma atrv5 strategy+28.5%539.4%
Swing Trend Strategy by Inkedlausma atrv5 strategy+11.2%516.2%
SSL Backtester With ATR SL TP and Money Management by JBTrippinsma atrv4 strategy+8.5%553.9%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 29 msYes 1,000 bars in 151 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.

//@version=4// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © millerrh with inspiration from @9e52f12edd034d28bdd5544e7ff92e //The intent behind this study is to look at ADX when it has an increasing slope and is above a user-defined key level (23 default). //This is to identify when it is trending.//It then looks at the DMI levels.  If D+ is above D- and the ADX is sloping upwards and above the key level, it triggers a buy condition.  Opposite for short.//Can use a user-defined moving average to filter long/short if desried.// NOTE: THIS IS MEANT TO BE USED IN CONJUNCTION WITH MY "ATX TRIGGER" INDICATOR FOR VISUALIZATION. MAKE SURE SETTINGS ARE THE SAME FOR BOTH.strategy("ADX | DMI Trend", overlay=true, initial_capital=10000, currency='USD',    default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.04)// === BACKTEST RANGE ===From_Year  = input(defval = 2019, title = "From Year")From_Month = input(defval = 1, title = "From Month", minval = 1, maxval = 12)From_Day   = input(defval = 1, title = "From Day", minval = 1, maxval = 31)To_Year    = input(defval = 9999, title = "To Year")To_Month   = input(defval = 1, title = "To Month", minval = 1, maxval = 12)To_Day     = input(defval = 1, title = "To Day", minval = 1, maxval = 31)Start  = timestamp(From_Year, From_Month, From_Day, 00, 00)  // backtest start windowFinish = timestamp(To_Year, To_Month, To_Day, 23, 59)        // backtest finish window// == INPUTS ==shortTrades = input(title = "Allow short trades?", type = input.bool, defval = true)// ADX Infoadxlen = input(14, title="ADX Smoothing")dilen = input(14, title="DI Period")keyLevel = input(23, title="Keylevel for ADX")adxLookbackEntry = input(3, title="Lookback Period for Slope (Entry)")adxLookbackExit = input(1, title="Lookback Period for Slope (Exit)")// == VOLUME FILTERING ==// InputsvolFilter = input(title = "Use Volume as Entry Filter?", type = input.bool, defval = true)volType = input(defval="Multiplier * Average", options=["Multiplier * Average", "Manual", "Multiplier * Average AND Manual"], title = "Volume Filtering Method")volMult = input(title = "Volume Trigger Multiplier", defval = 2, step = 0.1)volSMA = input(title = "Volume Trigger Average Bars Back", defval = 20, step = 1)volManual = input(20000, title="Manual Volume Value", step = 1000)// Check that volume is high before entering tradexVol = sma(volume, volSMA)xVolMult = xVol * volMultmanualCompare = volManual > xVolMultxVolManual = manualCompare == true ? volManual : xVolMultvolCheck = (volFilter == true and volType == "Multiplier * Average") ? xVolMult : (volFilter == true and volType == "Manual") ? volManual : (volFilter == true and volType == "Multiplier * Average AND Manual") ? xVolManual : 0//     xVol * volMult// else//     0// == MOVING AVERAGE FILTERING ==// InputsuseMaFilter = input(title = "Use MA for Entry Filtering?", type = input.bool, defval = true)maType = input(defval="EMA", options=["EMA", "SMA"], title = "MA Type For Filtering")maLength   = input(defval = 200, title = "MA Period for Filtering", minval = 1)// Declare function to be able to swap out EMA/SMAma(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 = ma(maType, close, maLength)plot(maFilter, title = "Trend Filter MA", color = color.green, linewidth = 3, style = plot.style_line, transp = 50)// Check to see if the useMaFilter check box is checked, this then inputs this conditional "maFilterCheck" variable into the strategy entry maFilterCheck = if useMaFilter == true    maFilterelse    close    // == ATR TRAILING STOPS ==// InputsuseATR = input(title = "Use ATR for Trailing Stop?", type = input.bool, defval = true)atrLookback = input(defval=14,title="ATR Lookback Period",type=input.integer)multiplier = input(defval=2,title="ATR Multiplier",type=input.float, step=0.1, minval=0.5, maxval=4)trigInput = input(title = "Execute Trades On...", defval = "Wick", options=["Wick","Close"]) // Useful for comparing standing stop orders vs. waiting for candle closes prior to actionshowInput = input(title="Show Trailing ATR", defval="Both", options=["Support","Resistance","Both"]) // Calculate the trailing ATRatrValue = atr(atrLookback)atrMultiplied = atrValue * multiplier// Plot the price plus or minus the ATRatrLow = low - atrMultipliedatrHigh = high + atrMultiplied// Calculate both the low and high trailing ATRs every time. The low one never goes down, and the high one never goes up// Set them to something to start withtrailAtrLow = atrLowtrailAtrHigh = atrHigh// If the ATR Low has gone up AND it has gone above the trail, the low trailing ATR should also go up. If the ATR Low has gone up or down, but not below the trail, the ATR trail stays where it istrailAtrLow := na(trailAtrLow[1]) ? trailAtrLow : atrLow >= trailAtrLow[1] ? atrLow : trailAtrLow[1]// Same for the HightrailAtrHigh := na(trailAtrHigh[1]) ? trailAtrHigh : atrHigh <= trailAtrHigh[1] ? atrHigh : trailAtrHigh[1]// Trigger stop based on candle close or High/LowtrigResistance = trigInput == "Close" ? close : trigInput == "Wick" ? high : natrigSupport = trigInput == "Close" ? close : trigInput == "Wick" ? low : na// Determine if price is above resistance or below supportatrResistanceHit = trigResistance >= trailAtrHigh and useATR == trueatrSupportHit = trigSupport <= trailAtrLow and useATR == true// If price is above resistance or below support, reset the trailing ATRtrailAtrLow := atrSupportHit ? atrLow : trailAtrLowtrailAtrHigh := atrResistanceHit ? atrHigh : trailAtrHigh// Plot ATR LinesplotLow = useATR == true and showInput == "Support" ? trailAtrLow : useATR == true and showInput == "Both" ? trailAtrLow : naplotHigh = useATR == true and showInput == "Resistance" ? trailAtrHigh : useATR == true and showInput == "Both" ? trailAtrHigh : naplot(plotLow, color=color.gray, style=plot.style_linebr, linewidth=1)plot(plotHigh, color=color.gray, style=plot.style_linebr, linewidth=1)// == LOOK AT PARABOLIC SAR AS AN EXIT OPTION ==useSAR = input(title = "Use SAR for Trailing Stop?", type = input.bool, defval = true)sarStart = input(0.02, "Start")sarIncrement = input(0.02, "Increment")sarMaximum = input(0.2, "Max Value")sarOut = useSAR ? sar(sarStart, sarIncrement, sarMaximum) : naplot(sarOut, "ParabolicSAR", style=plot.style_cross, color=#3A6CA8)// Determine if price is above resistance or below supportsarResistanceHit = trigResistance >= sarOut and useSAR == truesarSupportHit = trigSupport <= sarOut and useSAR == true// == USE BUILT-IN DMI FUNCTION TO DETERMINE ADX AND BULL/BEAR STRENGTH[diplus, diminus, adx] = dmi(dilen, adxlen)buySignal = (adx[0]-adx[adxLookbackEntry] > 0) and adx > keyLevel and diplus > diminus and time > Start and time < Finish and close >= maFilterCheck and volume > volCheckshortSignal = (adx[0]-adx[adxLookbackEntry] > 0) and adx > keyLevel and diplus < diminus and time > Start and time < Finish and close <= maFilterCheck and shortTrades and volume > volChecksellSignal = (adx[0]-adx[adxLookbackExit] < 0) or atrSupportHit or sarSupportHitcoverSignal = (adx[0]-adx[adxLookbackExit] < 0) or atrResistanceHit or sarResistanceHit// == STRATEGY ENTRIES/EXITS == strategy.entry("Long", strategy.long, when = buySignal)strategy.close("Long", when = sellSignal)strategy.entry("Short", strategy.short, when = shortSignal)strategy.close("Short", when = coverSignal)    // == ALERTS == alertcondition(buySignal, title='ADX | DMI Long', message='ADX | DMI Long')alertcondition(shortSignal, title='ADX | DMI Short', message='ADX | DMI Short')alertcondition(sellSignal, title='ADX | DMI Sell', message='ADX | DMI Sell')alertcondition(coverSignal, title='ADX | DMI Cover', message='ADX | DMI Cover')