Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

ADX + RSI Strat

A Pine Script v4 strategy built on Lowest (20), Highest (20) and Valuewhen or ATR (bought, SwingLow). It has 5 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade commits 100% of equity and pays 0.04 commission. 12 settings; defaults include Strategy Direction 0, Swing Lo/Hi Lookback 20 and SL Expander 0.

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 + RSI Strat repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 2 of 2 trades.
How did ADX + RSI Strat do on BTCUSDT 1D with default settings?
−3.49%
From 26 Jan 2024 to 21 Oct 2026, over 6 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can ADX + RSI Strat 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 + RSI Strat use a stop loss?
Yes
strategy.exit sets a stop on line 60, 61.
Does ADX + RSI Strat run in Zeal Terminal?
Yes
It compiles in 25 ms and runs 1,000 bars in 56 ms, in the browser.

BTCUSDT · 1D · default settings

  • Bullish Setup
  • Bearish Setup
  • 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 (12)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$118$203Equity from $100
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
−3.49%
−$3.49
Buy and hold
+102.5%
same period
Closed trades
6
2 won · 4 lost
Profitable
33.3%
of closed trades
Profit factor
0.92
gross profit ÷ gross loss
Max drawdown
36.30%
−$46.60

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

    Every trade uses all the equity

    default_qty_value is 100% of equity.

  • Note

    3 settings have no label

    In the settings dialog OS (line 32), OB (line 33), adxlevel (line 51) show an empty name. The labels on this page come from the variable names.

  • 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 56, 57, 63. 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 lowest → ta.lowest, highest → ta.highest, valuewhen → ta.valuewhen, atr → ta.atr, rsi → ta.rsi, change → ta.change, rma → ta.rma, abs → math.abs.
  • 3 strategy calls use the when = argument (line 56, 57, 63). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

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

  • Line 7: //@version=4 → //@version=5
  • Line 9: input(type = input.integer) → input.int()
  • Line 19: lowest → ta.lowest
  • Line 20: highest → ta.highest
  • Line 22: valuewhen → ta.valuewhen
  • Line 22: valuewhen → ta.valuewhen
19 more edits
  • Line 22: atr → ta.atr
  • Line 23: valuewhen → ta.valuewhen
  • Line 23: valuewhen → ta.valuewhen
  • Line 23: atr → ta.atr
  • Line 24: valuewhen → ta.valuewhen
  • Line 24: valuewhen → ta.valuewhen
  • Line 24: atr → ta.atr
  • Line 25: valuewhen → ta.valuewhen
  • Line 25: valuewhen → ta.valuewhen
  • Line 25: atr → ta.atr
  • Line 31: rsi → ta.rsi
  • Line 38: change → ta.change
  • Line 39: change → ta.change
  • Line 42: rma → ta.rma
  • Line 42: tr → ta.tr
  • Line 43: rma → ta.rma
  • Line 44: rma → ta.rma
  • Line 49: rma → ta.rma
  • Line 49: abs → math.abs
⋯// and selling the OS) wihout stop loss.-//@version=4+//@version=5strategy("ADX + RSI Strat", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=100, commission_value=0.04, calc_on_every_tick=false)-direction = input(0, title = "Strategy Direction", type=input.integer, minval=-1, maxval=1)+direction = input.int(0, title = "Strategy Direction", minval=-1, maxval=1)strategy.risk.allow_entry_in(direction == 0 ? strategy.direction.all : (direction < 0 ? strategy.direction.short : strategy.direction.long))⋯//SL & TP Calculations-SwingLow=lowest(i_SwingLookback)+SwingLow=ta.lowest(i_SwingLookback)-SwingHigh=highest(i_SwingLookback)+SwingHigh=ta.highest(i_SwingLookback)bought=strategy.position_size != strategy.position_size[1]-LSL=valuewhen(bought, SwingLow, 0)-((valuewhen(bought, atr(14), 0))*i_SLExpander)+LSL=ta.valuewhen(bought, SwingLow, 0)-((ta.valuewhen(bought, ta.atr(14), 0))*i_SLExpander)-SSL=valuewhen(bought, SwingHigh, 0)+((valuewhen(bought, atr(14), 0))*i_SLExpander)+SSL=ta.valuewhen(bought, SwingHigh, 0)+((ta.valuewhen(bought, ta.atr(14), 0))*i_SLExpander)-lTP=strategy.position_avg_price + (strategy.position_avg_price-(valuewhen(bought, SwingLow, 0))+((valuewhen(bought, atr(14), 0))*i_TPExpander))+lTP=strategy.position_avg_price + (strategy.position_avg_price-(ta.valuewhen(bought, SwingLow, 0))+((ta.valuewhen(bought, ta.atr(14), 0))*i_TPExpander))-sTP=strategy.position_avg_price - (valuewhen(bought, SwingHigh, 0)-strategy.position_avg_price)-((valuewhen(bought, atr(14), 0))*i_TPExpander)+sTP=strategy.position_avg_price - (ta.valuewhen(bought, SwingHigh, 0)-strategy.position_avg_price)-((ta.valuewhen(bought, ta.atr(14), 0))*i_TPExpander)islong=strategy.position_size > 0⋯//RSI Calculations-RSI=rsi(close, 7)+RSI=ta.rsi(close, 7)OS=input(20, step=5)⋯dirmov(len) =>-    up = change(high)+    up = ta.change(high)-    down = -change(low)+    down = -ta.change(low)    plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)    minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)-    truerange = rma(tr, len)+    truerange = ta.rma(ta.tr, len)-    plus = fixnan(100 * rma(plusDM, len) / truerange)+    plus = fixnan(100 * ta.rma(plusDM, len) / truerange)-    minus = fixnan(100 * rma(minusDM, len) / truerange)+    minus = fixnan(100 * ta.rma(minusDM, len) / truerange)    [plus, minus]⋯    sum = plus + minus-    adx = 100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)+    adx = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)sig = adx(dilen, adxlen)⋯

Clean v5

VerifiedDownload the v5 script

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

  • Line 12: input() → input.bool()
  • Line 13: input() → input.int()
  • Line 14: input() → input.int()
  • Line 15: input() → input.int()
  • Line 16: input() → input.bool()
  • Line 17: input() → input.bool()
8 more edits
  • Line 32: input() → input.int()
  • Line 33: input() → input.int()
  • Line 35: input() → input.int()
  • Line 36: input() → input.int()
  • Line 51: input() → input.int()
  • Line 56: when = i_reverse?SELL:BUY → if block
  • Line 57: when = not i_reverse?SELL:BUY → if block
  • Line 63: when = sig > adxlevel → if block
⋯//SL & TP Inputs-i_SL=input(false, title="Use Swing Lo/Hi Stop Loss & Take Profit")+i_SL=input.bool(false, title="Use Swing Lo/Hi Stop Loss & Take Profit")-i_SwingLookback=input(20, title="Swing Lo/Hi Lookback")+i_SwingLookback=input.int(20, title="Swing Lo/Hi Lookback")-i_SLExpander=input(defval=0, step=.2, title="SL Expander")+i_SLExpander=input.int(defval=0, step=.2, title="SL Expander")-i_TPExpander=input(defval=0, step=.2, title="TP Expander")+i_TPExpander=input.int(defval=0, step=.2, title="TP Expander")-i_reverse=input(true, title="Reverse Trades")+i_reverse=input.bool(true, title="Reverse Trades")-i_ADXClose=input(true, title="ADX Close")+i_ADXClose=input.bool(true, title="ADX Close")//SL & TP Calculations⋯RSI=ta.rsi(close, 7)-OS=input(20, step=5)+OS=input.int(20, step=5)-OB=input(80, step=5)+OB=input.int(80, step=5)//ADX Calculations-adxlen = input(14, title="ADX Smoothing")+adxlen = input.int(14, title="ADX Smoothing")-dilen = input(200, title="DI Length")+dilen = input.int(200, title="DI Length")dirmov(len) =>⋯sig = adx(dilen, adxlen)-adxlevel=input(20, step=5)+adxlevel=input.int(20, step=5)//Entry Logic⋯//Entries-strategy.entry("long", strategy.long, when=i_reverse?SELL:BUY)+if i_reverse?SELL:BUY+    strategy.entry("long", strategy.long)-strategy.entry("short", strategy.short, when=not i_reverse?SELL:BUY)+if not i_reverse?SELL:BUY+    strategy.entry("short", strategy.short)//Exits⋯if i_ADXClose-    strategy.close_all(when=sig > adxlevel)+    if sig > adxlevel+        strategy.close_all()//Plotss⋯

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: 6 before, 19 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.

⋯// and selling the OS) wihout stop loss.-//@version=5+//@version=6strategy("ADX + RSI Strat", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=100, commission_value=0.04, calc_on_every_tick=false)⋯

Settings

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

SettingDefaultType and rangeFeeds
Strategy Direction0int (written input.integer) · min -1 · max 1line 10
Use Swing Lo/Hi Stop Loss & Take Profitfalseboolexit longexit exit shortexit line 59 SL TP
Swing Lo/Hi Lookback20intSwingLow SwingHigh
SL Expander0int · step .2LSL SSL
TP Expander0int · step .2lTP sTP
Reverse Tradestrueboolentry long entry short
ADX Closetrueboolclose_all line 62
OS (no label in the script)20int · step 5BUY
OB (no label in the script)80int · step 5SELL
ADX Smoothing14intadx sig
DI Length200intplus minus sig
Adxlevel (no label in the script)20int · step 5BUY SELL close_all

What it calculates

  • Lowest (lowest, ta.lowest in v5)Swing Lo/Hi Lookback (20)SwingLow · line 19
  • Highest (highest, ta.highest in v5)Swing Lo/Hi Lookback (20)SwingHigh · line 20
  • Valuewhen / ATR (valuewhen, ta.valuewhen in v5)bought, SwingLow, 0LSL · line 22
  • Valuewhen / ATR (valuewhen, ta.valuewhen in v5)bought, SwingHigh, 0SSL · line 23
  • Valuewhen / ATR (valuewhen, ta.valuewhen in v5)bought, SwingLow, 0lTP · line 24
  • Valuewhen / ATR (valuewhen, ta.valuewhen in v5)bought, SwingHigh, 0sTP · line 25
  • RSI (rsi, ta.rsi in v5)close, 7RSI · line 31
  • Change (change, ta.change in v5)highup · line 38
  • Change (change, ta.change in v5)lowdown · line 39
  • RMA (rma, ta.rma in v5)tr, lentruerange · line 42
  • RMA (rma, ta.rma in v5)abs(plus - minus) / (sum == 0 ? 1 : sum), ADX Smoothing (14)adx · line 49

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.

i_SwingLookbackSwing Lo/Hi Lookbacksetting · 20i_SLExpanderSL Expandersetting · 0i_TPExpanderTP Expandersetting · 0closecloseprice datahighhighprice datalowlowprice dataadxlenADX Smoothingsetting · 14dilenDI Lengthsetting · 200adxlevelAdxlevelsetting · 20OSOSsetting · 20OBOBsetting · 80SwingLowLowest→ SwingLowSwingHighHighest→ SwingHighLSLValuewhen / ATR→ LSLSSLValuewhen / ATR→ SSLlTPValuewhen / ATR→ lTPsTPValuewhen / ATR→ sTPRSIRSI→ RSIupChange→ updownChange→ downtruerangeRMA→ truerangeadxRMA→ adxSLSLvalueTPTPvalueplusDM, minusDMplusDM · minusDM2 valuesplus, minusplus · minus2 valuessumsumvaluesigsigvaluebought, islong, isshortbought · islong +13 conditionsBUYBUYconditionSELLSELLconditionentry:longOpen longstrategy.entryentry:shortOpen shortstrategy.entryexit:longexitexit longexitstrategy.exitexit:shortexitexit shortexitstrategy.exitclose_all:close_all strategy.close_allplot:65SLplotplot:66TPplotplotshape:67Bullish Setupplotshapeplotshape:68Bearish Setupplotshape

Order rules

OrderFires whenBy defaultLine
Open long longi_reverse?SELL:BUYOn56
Open short shortnot i_reverse?SELL:BUYOn57
Exit longexit stop and limiti_SLOff “Use Swing Lo/Hi Stop Loss & Take Profit”60
Exit shortexit stop and limiti_SLOff “Use Swing Lo/Hi Stop Loss & Take Profit”61
Close sig > adxlevelOn “ADX Close”63

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.

2/2trades 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−3.5%+102.5%633%0.9236.3%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+14.7%+5.5%450%2.786.3%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−77.3%+9.8%1040%0.1578.3%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+33.9%+8.4%475%3.8814.6%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−78.8%+16.7%1242%0.1879.7%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−9.9%+21.5%825%0.7739.6%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−17.5%+148.3%838%0.6538.8%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+11.7%+17.1%850%1.6413.5%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 market0—$0.00
Sideways market333%$12.43
Falling market333%−$15.88

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

How bad could the drawdown be?

32.8%

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

0%38%
All 6 trades
SideEntryExitBarsP&L
long21 Oct 2024 69,032.0026 Feb 2025 88,680.40128$28.36
short26 Feb 2025 88,680.4023 Apr 2025 93,443.0056−$7.00
long23 Apr 2025 93,443.0021 Nov 2025 86,637.20212−$8.93
short21 Nov 2025 86,637.206 Jan 2026 93,859.7046−$9.47
long6 Jan 2026 93,859.701 Feb 2026 78,741.1026−$16.66
short1 Feb 2026 78,741.1020 Aug 2026 69,334.80200$10.24

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 + RSI Strat this page—v4 strategy−3.5%636.3%
Delayed RSI Strategy by tweakerIDlowest highest valuewhen atr rsiv4 strategy−40.4%742.2%
R19 STRATEGY by SenatorVonShaftatr rma highest lowest rsiv4 strategyNo trades on this market
Double Bollinger Strategy by tweakerIDlowest highest valuewhen atr rsiv4 strategy−29.6%6150.1%
HiLo Extension by Saravanan_Ragavanvaluewhen lowest highest rmav4 strategyNo trades on this market
Positive Bars - Strategy by tweakerIDlowest highest valuewhen atrv4 strategy−40.3%754.7%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 25 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/// © tweakerID// This is a strategy that uses the 7 Period RSI to buy when the indicator is shown as oversold (OS) and sells when // the index marks overbought (OB). It also uses the ADX to determine whether the trend is ranging or trending// and filters out the trending trades. Seems to work better for automated trading when the logic is inversed (buying OB // and selling the OS) wihout stop loss.//@version=4strategy("ADX + RSI Strat", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=100, commission_value=0.04, calc_on_every_tick=false)direction = input(0, title = "Strategy Direction", type=input.integer, minval=-1, maxval=1)strategy.risk.allow_entry_in(direction == 0 ? strategy.direction.all : (direction < 0 ? strategy.direction.short : strategy.direction.long))//SL & TP Inputsi_SL=input(false, title="Use Swing Lo/Hi Stop Loss & Take Profit")i_SwingLookback=input(20, title="Swing Lo/Hi Lookback")i_SLExpander=input(defval=0, step=.2, title="SL Expander")i_TPExpander=input(defval=0, step=.2, title="TP Expander")i_reverse=input(true, title="Reverse Trades")i_ADXClose=input(true, title="ADX Close")//SL & TP CalculationsSwingLow=lowest(i_SwingLookback)SwingHigh=highest(i_SwingLookback)bought=strategy.position_size != strategy.position_size[1]LSL=valuewhen(bought, SwingLow, 0)-((valuewhen(bought, atr(14), 0))*i_SLExpander)SSL=valuewhen(bought, SwingHigh, 0)+((valuewhen(bought, atr(14), 0))*i_SLExpander)lTP=strategy.position_avg_price + (strategy.position_avg_price-(valuewhen(bought, SwingLow, 0))+((valuewhen(bought, atr(14), 0))*i_TPExpander))sTP=strategy.position_avg_price - (valuewhen(bought, SwingHigh, 0)-strategy.position_avg_price)-((valuewhen(bought, atr(14), 0))*i_TPExpander)islong=strategy.position_size > 0isshort=strategy.position_size < 0SL= islong ? LSL : isshort ? SSL : naTP= islong ? lTP : isshort ? sTP : na//RSI CalculationsRSI=rsi(close, 7)OS=input(20, step=5)OB=input(80, step=5)//ADX Calculationsadxlen = input(14, title="ADX Smoothing")dilen = input(200, title="DI Length")dirmov(len) =>    up = change(high)    down = -change(low)    plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)    minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)    truerange = rma(tr, len)    plus = fixnan(100 * rma(plusDM, len) / truerange)    minus = fixnan(100 * rma(minusDM, len) / truerange)    [plus, minus]adx(dilen, adxlen) =>    [plus, minus] = dirmov(dilen)    sum = plus + minus    adx = 100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)sig = adx(dilen, adxlen)adxlevel=input(20, step=5)//Entry LogicBUY = sig < adxlevel and (RSI < OS) SELL = sig < adxlevel and (RSI > OB) //Entriesstrategy.entry("long", strategy.long, when=i_reverse?SELL:BUY)strategy.entry("short", strategy.short, when=not i_reverse?SELL:BUY)//Exitsif i_SL    strategy.exit("longexit", "long", stop=SL, limit=TP)    strategy.exit("shortexit", "short", stop=SL, limit=TP)if i_ADXClose    strategy.close_all(when=sig > adxlevel)//Plotssplot(i_SL ? SL : na, color=color.red, style=plot.style_cross, title="SL")plot(i_SL ? TP : na, color=color.green, style=plot.style_cross, title="TP")plotshape(BUY ? 1 : na, style=shape.triangleup, location=location.belowbar, color=color.green, title="Bullish Setup")plotshape(SELL ? 1 : na, style=shape.triangledown, location=location.abovebar, color=color.red, title="Bearish Setup")