Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

SuperTREX strategy

A Pine Script v4 strategy built on RSI (p, 14), Crossover (vrsi, 35) and Crossunder (vrsi, 70). It has 6 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 25% of equity and pays 0.075% commission. 15 settings; defaults include Strategy Direction long, Length 14 and Over Sold 35.

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 SuperTREX strategy 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 SuperTREX strategy do on BTCUSDT 1D with default settings?
−3.82%
From 26 Jan 2024 to 21 Oct 2026, over 3 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can SuperTREX strategy be converted to Pine Script v5?
No
The automatic step from v4 to v5 changes the results, so no v5 download is offered; the edits are shown below.
Does SuperTREX strategy use a stop loss?
Yes
strategy.exit sets a stop on line 71, 72, 73, 74.
Does SuperTREX strategy run in Zeal Terminal?
Yes
It compiles in 19 ms and runs 1,000 bars in 62 ms, in the browser.

BTCUSDT · 1D · default settings

  • Plot
  • buy
  • sell
  • 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 (15)
0.0050,000100,000AprJulOct2025AprJulOct2026AprJulOct$9,987$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
−3.82%
−$381.78
Buy and hold
+102.5%
same period
Closed trades
3
2 won · 1 lost
Profitable
66.7%
of closed trades
Profit factor
0.31
gross profit ÷ gross loss
Max drawdown
6.11%
−$610.52

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.

  • Note

    4 settings have no label

    In the settings dialog length (line 8), overSold (line 9), overBought (line 10), HTF (line 11) show an empty name. The labels on this page come from the variable names.

  • Note

    Uses transp =, which v5 removed line 50

    transp = on line 50, 51. 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 change → ta.change, rsi → ta.rsi, crossover → ta.crossover, crossunder → ta.crossunder, atr → ta.atr, max → math.max, min → math.min, round → math.round.

v4 → v5

Differs

Trades differ: 3 before, 10 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 3: //@version=4 → //@version=5
  • Line 11: input(type = input.resolution) → input.timeframe()
  • Line 12: change → ta.change
  • Line 14: rsi → ta.rsi
  • Line 18: crossover → ta.crossover
  • Line 19: crossunder → ta.crossunder
9 more edits
  • Line 31: atr → ta.atr
  • Line 32: atr → ta.atr
  • Line 34: max → math.max
  • Line 36: min → math.min
  • Line 43: crossover → ta.crossover
  • Line 44: crossunder → ta.crossunder
  • Line 50: transp = 0 → color.new(color.green, 0)
  • Line 51: transp = 0 → color.new(color.red, 0)
  • Line 61: round → math.round
⋯// © RafaelZioni-//@version=4+//@version=5strategy(title = "SuperTREX strategy", overlay = true, pyramiding=1,initial_capital = 10000, default_qty_type= strategy.percent_of_equity, default_qty_value = 25, calc_on_order_fills=false, slippage=0,commission_type=strategy.commission.percent,commission_value=0.075)⋯overBought = input( 70 )-HTF = input("W", type=input.resolution)+HTF = input.timeframe("W")-ti = change( time(HTF) ) != 0+ti = ta.change( time(HTF) ) != 0p = fixnan( ti ? close : na )-vrsi = rsi(p, length)+vrsi = ta.rsi(p, length)price = close⋯var bool short = na-long :=crossover(vrsi,overSold) +long :=ta.crossover(vrsi,overSold) -short := crossunder(vrsi,overBought)+short := ta.crossunder(vrsi,overBought)var float last_open_long = na⋯// CALCULATIONS //-up_lev =xy - (st_mult * atr(st_period))+up_lev =xy - (st_mult * ta.atr(st_period))-dn_lev =xy + (st_mult * atr(st_period))+dn_lev =xy + (st_mult * ta.atr(st_period))up_trend   = 0.0-up_trend   := entry_value[1] > up_trend[1]   ? max(up_lev, up_trend[1])   : up_lev+up_trend   := entry_value[1] > up_trend[1]   ? math.max(up_lev, up_trend[1])   : up_levdown_trend = 0.0-down_trend := entry_value1[1] < down_trend[1] ? min(dn_lev, down_trend[1]) : dn_lev+down_trend := entry_value1[1] < down_trend[1] ? math.min(dn_lev, down_trend[1]) : dn_lev// Calculate trend var⋯plot(xy,color = trend == 1 ? color.green : color.red)-buy=crossover( close, st_line) +buy=ta.crossover( close, st_line) -sell1=crossunder(close, st_line) +sell1=ta.crossunder(close, st_line)  ⋯// STRATEGY-plotshape(buy , title="buy", text="Buy", color=color.green, style=shape.labelup, location=location.belowbar, size=size.small, textcolor=color.white, transp=0)  //plot for buy icon+plotshape(buy , title="buy", text="Buy", color=color.new(color.green, 0), style=shape.labelup, location=location.belowbar, size=size.small, textcolor=color.white)  //plot for buy icon-plotshape(sell, title="sell", text="Sell", color=color.red, style=shape.labeldown, location=location.abovebar, size=size.small, textcolor=color.white, transp=0)  //plot for sell icon+plotshape(sell, title="sell", text="Sell", color=color.new(color.red, 0), style=shape.labeldown, location=location.abovebar, size=size.small, textcolor=color.white)  //plot for sell icon// Take profit⋯per(pcnt) =>-    strategy.position_size != 0 ? round(pcnt / 100 * strategy.position_avg_price / syminfo.mintick) : float(na)+    strategy.position_size != 0 ? math.round(pcnt / 100 * strategy.position_avg_price / syminfo.mintick) : float(na)stoploss=input(title=" stop loss", defval=25, minval=0.01)⋯

Clean v5

Verified

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

  • Line 5: input() → input.string()
  • Line 8: input() → input.int()
  • Line 9: input() → input.int()
  • Line 10: input() → input.int()
  • Line 28: input() → input.int()
  • Line 29: input() → input.int()
8 more edits
  • Line 62: input() → input.int()
  • Line 64: input() → input.int()
  • Line 65: input() → input.int()
  • Line 66: input() → input.int()
  • Line 67: input() → input.int()
  • Line 68: input() → input.int()
  • Line 69: input() → input.int()
  • Line 70: input() → input.int()
⋯strategy(title = "SuperTREX strategy", overlay = true, pyramiding=1,initial_capital = 10000, default_qty_type= strategy.percent_of_equity, default_qty_value = 25, calc_on_order_fills=false, slippage=0,commission_type=strategy.commission.percent,commission_value=0.075)-strat_dir_input = input(title="Strategy Direction", defval="long", options=["long", "short", "all"])+strat_dir_input = input.string(title="Strategy Direction", defval="long", options=["long", "short", "all"])strat_dir_value = strat_dir_input == "long" ? strategy.direction.long : strat_dir_input == "short" ? strategy.direction.short : strategy.direction.allstrategy.risk.allow_entry_in(strat_dir_value)-length = input( 14 )+length = input.int( 14 )-overSold = input( 35 )+overSold = input.int( 35 )-overBought = input( 70 )+overBought = input.int( 70 )HTF = input.timeframe("W")⋯// INPUTS //-st_mult   = input(4,   title = 'SuperTrend Multiplier', minval = 0, maxval = 100, step = 0.01)+st_mult   = input.int(4,   title = 'SuperTrend Multiplier', minval = 0, maxval = 100, step = 0.01)-st_period = input(10, title = 'SuperTrend Period',     minval = 1)+st_period = input.int(10, title = 'SuperTrend Period',     minval = 1)// CALCULATIONS //⋯    strategy.position_size != 0 ? math.round(pcnt / 100 * strategy.position_avg_price / syminfo.mintick) : float(na)-stoploss=input(title=" stop loss", defval=25, minval=0.01)+stoploss=input.int(title=" stop loss", defval=25, minval=0.01)los = per(stoploss)-q1=input(title=" qty_percent1", defval=25, minval=1)+q1=input.int(title=" qty_percent1", defval=25, minval=1)-q2=input(title=" qty_percent2", defval=25, minval=1)+q2=input.int(title=" qty_percent2", defval=25, minval=1)-q3=input(title=" qty_percent3", defval=25, minval=1)+q3=input.int(title=" qty_percent3", defval=25, minval=1)-tp1=input(title=" Take profit1", defval=10, minval=0.01)+tp1=input.int(title=" Take profit1", defval=10, minval=0.01)-tp2=input(title=" Take profit2", defval=20, minval=0.01)+tp2=input.int(title=" Take profit2", defval=20, minval=0.01)-tp3=input(title=" Take profit3", defval=50, minval=0.01)+tp3=input.int(title=" Take profit3", defval=50, minval=0.01)-tp4=input(title=" Take profit4", defval=100, minval=0.01)+tp4=input.int(title=" Take profit4", defval=100, minval=0.01)strategy.exit("x1", qty_percent = q1, profit = per(tp1), loss = los)⋯

Does it run in Pine Script v6?

No

The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L16:C0: a 'bool' cannot be 'na' in Pine Script v6 — declare it as true or false. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.

⋯// © RafaelZioni-//@version=5+//@version=6strategy(title = "SuperTREX strategy", overlay = true, pyramiding=1,initial_capital = 10000, default_qty_type= strategy.percent_of_equity, default_qty_value = 25, calc_on_order_fills=false, slippage=0,commission_type=strategy.commission.percent,commission_value=0.075)⋯

Settings

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

SettingDefaultType and rangeFeeds
Strategy Directionlongstring · options ["long", "short", "all"]strat_dir_value
Length (no label in the script)14intvrsi
Over Sold (no label in the script)35intlong
Over Bought (no label in the script)70intshort
HTF (no label in the script)Wtimeframe (written input.resolution)ti
SuperTrend Multiplier4int · min 0 · max 100 · step 0.01up_lev dn_lev
SuperTrend Period10int · min 1up_lev dn_lev
stop loss25int · min 0.01los
qty_percent125int · min 1exit x1
qty_percent225int · min 1exit x2
qty_percent325int · min 1exit x3
Take profit110int · min 0.01exit x1
Take profit220int · min 0.01exit x2
Take profit350int · min 0.01exit x3
Take profit4100int · min 0.01exit x4

What it calculates

  • RSI (rsi, ta.rsi in v5)p, Length (14)vrsi · line 14
  • Crossover (crossover, ta.crossover in v5)vrsi, Over Sold (35)long · line 18
  • Crossunder (crossunder, ta.crossunder in v5)vrsi, Over Bought (70)short · line 19
  • ATR (atr, ta.atr in v5)SuperTrend Period (10)up_lev · line 31
  • ATR (atr, ta.atr in v5)SuperTrend Period (10)dn_lev · line 32
  • Crossover (crossover, ta.crossover in v5)close, st_linebuy · line 43
  • Crossunder (crossunder, ta.crossunder in v5)close, st_linesell1 · line 44

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.

lengthLengthsetting · 14overSoldOver Soldsetting · 35overBoughtOver Boughtsetting · 70high · low · closehigh · low · closeprice datast_multSuperTrend Multipliersetting · 4st_periodSuperTrend Periodsetting · 10closecloseprice datastrat_dir_inputStrategy Directionsetting · longstoploss stop losssetting · 25HTFHTFsetting · WvrsiRSI→ vrsilongCrossover→ longshortCrossunder→ shortup_levATR→ up_levdn_levATR→ dn_levbuyCrossover→ buysell1Crossunder→ sell1strat_dir_valuestrat_dir_valuevalueppvaluepricepricevaluelast_open_longlast_open_longvaluelast_open_shortlast_open_shortvalueentry_valueentry_valuevalueentry_value1entry_value1valuexyxyvalueup_trendup_trendvaluedown_trenddown_trendvaluetrendtrendvaluest_linest_linevaluebuy1, lbuy1 · l2 valuessellsellvalues1s1valueloslosvaluetiticonditionentry:buyOpen buystrategy.entryentry:sellOpen sellstrategy.entryexit:x1exit x1strategy.exitexit:x2exit x2strategy.exitexit:x3exit x3strategy.exitexit:x4exit x4strategy.exitplot:42plotplotplotshape:50buyplotshapeplotshape:51sellplotshape

Order rules

OrderFires whenBy defaultLine
Open buy longlOn57
Open sell shorts1On59
Exit x1 stop and limitevery barOn71
Exit x2 stop and limitevery barOn72
Exit x3 stop and limitevery barOn73
Exit x4 stop and limitevery barOn74

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−3.8%+102.5%367%0.316.1%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+0.1%+5.5%367%1.092.0%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+4.8%+9.8%1457%1.487.3%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+4.6%+8.4%580%2.893.1%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+10.1%+16.7%786%103.811.7%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+8.5%+21.5%6100%—2.6%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−0.4%+148.3%475%0.863.1%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+2.8%+17.1%475%2.203.2%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 market10%−$555.94
Falling market2100%$175.04

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

How bad could the drawdown be?

5.6%

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

0%6%
All 3 trades
SideEntryExitBarsP&L
long23 Apr 2026 78,178.207 Jun 2026 60,884.6045−$555.94
long18 Aug 2026 64,532.1020 Aug 2026 70,985.302$58.05
long18 Aug 2026 64,532.1021 Aug 2026 77,438.503$116.99

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
SuperTREX strategy this page—v4 strategy−3.8%36.1%
[KL] RSI 14 + 10 Strategy by DojiEmojiatr rsiv4 strategy+4.2%2739.7%
MA cross strategy by Glenn234rsi atrv5 strategy−606.2%35656.0%
VWMA_withATRstops_strategy by ediks123rsi atrv4 strategyNo trades on this market
Mathias & Christer Timeframe RSI by mattehalenrsi atrv4 strategy−0.7%180.7%
Estrategia Larry Connors [JoseMetal] by JoseMetalrsi atrv5 strategy+2.7%242.4%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 19 msYes 1,000 bars in 62 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/// © RafaelZioni//@version=4strategy(title = "SuperTREX strategy", overlay = true, pyramiding=1,initial_capital = 10000, default_qty_type= strategy.percent_of_equity, default_qty_value = 25, calc_on_order_fills=false, slippage=0,commission_type=strategy.commission.percent,commission_value=0.075)strat_dir_input = input(title="Strategy Direction", defval="long", options=["long", "short", "all"])strat_dir_value = strat_dir_input == "long" ? strategy.direction.long : strat_dir_input == "short" ? strategy.direction.short : strategy.direction.allstrategy.risk.allow_entry_in(strat_dir_value)length = input( 14 )overSold = input( 35 )overBought = input( 70 )HTF = input("W", type=input.resolution)ti = change( time(HTF) ) != 0p = fixnan( ti ? close : na )vrsi = rsi(p, length)price = closevar bool long = navar bool short = nalong :=crossover(vrsi,overSold) short := crossunder(vrsi,overBought)var float last_open_long = navar float last_open_short = nalast_open_long := long ? close : nz(last_open_long[1])last_open_short := short ? close : nz(last_open_short[1])entry_value =last_open_longentry_value1=last_open_shortxy=(entry_value+entry_value)/2// INPUTS //st_mult   = input(4,   title = 'SuperTrend Multiplier', minval = 0, maxval = 100, step = 0.01)st_period = input(10, title = 'SuperTrend Period',     minval = 1)// CALCULATIONS //up_lev =xy - (st_mult * atr(st_period))dn_lev =xy + (st_mult * atr(st_period))up_trend   = 0.0up_trend   := entry_value[1] > up_trend[1]   ? max(up_lev, up_trend[1])   : up_levdown_trend = 0.0down_trend := entry_value1[1] < down_trend[1] ? min(dn_lev, down_trend[1]) : dn_lev// Calculate trend vartrend = 0trend := close > down_trend[1] ? 1: close < up_trend[1] ? -1 : nz(trend[1], 1)// Calculate SuperTrend Linest_line = trend ==1 ? up_trend : down_trendplot(xy,color = trend == 1 ? color.green : color.red)buy=crossover( close, st_line) sell1=crossunder(close, st_line)  buy1=buy//sell=sell1// STRATEGYplotshape(buy , title="buy", text="Buy", color=color.green, style=shape.labelup, location=location.belowbar, size=size.small, textcolor=color.white, transp=0)  //plot for buy iconplotshape(sell, title="sell", text="Sell", color=color.red, style=shape.labeldown, location=location.abovebar, size=size.small, textcolor=color.white, transp=0)  //plot for sell icon// Take profit//l = buy s1=sell if l     strategy.entry("buy", strategy.long)if s1     strategy.entry("sell", strategy.short)per(pcnt) =>    strategy.position_size != 0 ? round(pcnt / 100 * strategy.position_avg_price / syminfo.mintick) : float(na)stoploss=input(title=" stop loss", defval=25, minval=0.01)los = per(stoploss)q1=input(title=" qty_percent1", defval=25, minval=1)q2=input(title=" qty_percent2", defval=25, minval=1)q3=input(title=" qty_percent3", defval=25, minval=1)tp1=input(title=" Take profit1", defval=10, minval=0.01)tp2=input(title=" Take profit2", defval=20, minval=0.01)tp3=input(title=" Take profit3", defval=50, minval=0.01)tp4=input(title=" Take profit4", defval=100, minval=0.01)strategy.exit("x1", qty_percent = q1, profit = per(tp1), loss = los)strategy.exit("x2", qty_percent = q2, profit = per(tp2), loss = los)strategy.exit("x3", qty_percent = q3, profit = per(tp3), loss = los)strategy.exit("x4", profit = per(tp4), loss = los)