Pine Script v5 · Strategy
JS-TechTrading- Supertrend-Strategy_Basic version
A Pine Script v5 strategy built on Supertrend (3.0, 10), EMA (close, 200) and RSI (close, 14). It has 4 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 1% of equity and pays no commission. 16 settings; defaults include Type Of Strategy Pullback, ATR Length 10 and Factor 3.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 JS-TechTrading- Supertrend-Strategy_Basic version repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 1 of 1 trades.
- How did JS-TechTrading- Supertrend-Strategy_Basic version do on BTCUSDT 1D with default settings?
- +0.08%
- From 26 Jan 2024 to 21 Oct 2026, over 2 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does JS-TechTrading- Supertrend-Strategy_Basic version 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: 2 before, 2 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download.
- Does JS-TechTrading- Supertrend-Strategy_Basic version use a stop loss?
- Yes
- strategy.exit sets a stop on line 78, 80.
- Does JS-TechTrading- Supertrend-Strategy_Basic version run in Zeal Terminal?
- Yes
- It compiles in 28 ms and runs 1,000 bars in 71 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- Up Trend
- Down Trend
- Long Fixed SL
- Long Take Profit
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +0.08%
- $833.89
- Buy and hold
- +102.5%
- same period
- Closed trades
- 2
- 2 won · 0 lost
- Profitable
- 100.0%
- of closed trades
- Profit factor
- —
- gross profit ÷ gross loss
- Max drawdown
- 0.00%
- −$8.44
One run with the author's default settings, $1,000,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 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.
Settings
Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Type Of Strategy | Pullback | string · options ['Pullback','Simple'] | buy_cond sell_cond |
| Supertrend Settings | |||
| ATR Length | 10 | int | supertrend direction |
| Factor | 3.0 | float · step 0.01 | supertrend direction |
| Ema Settings | |||
| Ema Condition On/Off | true | bool | ma_buy ma_sell |
| Ema Length | 200 | int · min 1 | ma_out |
| Ema Source | close | source | ma_out |
| Rsi Settings | |||
| Rsi Condition On/Off | true | bool | rsi_buy rsi_sell |
| RSI Source | close | source | rsiValue |
| RSI Length | 14 | int | rsiValue |
| RSI BUY Level | 50 | int | rsi_buy |
| RSI SELL Level | 50 | int | rsi_sell |
| Backtest Period | |||
| Start calculations from | timestamp('2005-01-01') | time | time_cond |
| End calculations | timestamp('2045-03-01') | time | time_cond |
| Trade Direction | |||
| Trade Direction | Both | string · options ['Long', 'Short', 'Both'] | longOK shortOK |
| Sl/Tp Settings | |||
| Stop Loss % | 1.0 | float · step 0.10 | longStop shortStop |
| Take Profit % | 1.0 | float · step 0.10 | shortTake longTake |
What it calculates
- SupertrendFactor (3.0), ATR Length (10)
supertrend · line 19 - SupertrendFactor (3.0), ATR Length (10)
direction · line 19 - EMAEma Source (close), Ema Length (200)
ma_out · line 37 - RSIRSI Source (close), RSI Length (14)
rsiValue · line 48
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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open long long | buy_cond and longOK and time_cond and strategy.position_size==0 | On | 65 |
| Open short short | sell_cond and shortOK and time_cond and strategy.position_size==0 | On | 67 |
| Exit Close Long stop and limit | strategy.position_size > 0 | On | 78 |
| Exit Close Short stop and limit | strategy.position_size < 0 | On | 80 |
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.
- 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.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | +0.1% | +102.5% | 2 | 100% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +0.0% | +5.5% | 6 | 67% | 1.39 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +0.1% | +9.8% | 1 | 100% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +0.0% | +8.4% | 1 | 100% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −0.0% | +16.7% | 1 | 0% | 0.00 | 0.1% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.0% | +21.5% | 4 | 75% | 2.97 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −0.1% | +148.3% | 3 | 0% | 0.00 | 0.1% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +0.0% | +17.1% | 3 | 67% | 2.77 | 0.0% | 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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 0 | — | $0.00 |
| Sideways market | 2 | 100% | $833.89 |
| Falling market | 0 | — | $0.00 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
0.0%
The 95th percentile of the worst drawdown when the same 2 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 0.0% to 0.0%; the tick is what actually happened, 0.0%. Order luck alone moves it this much.
All 2 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 12 Oct 2024 62,540.00 | 13 Oct 2024 63,206.20 | 1 | $106.53 |
| long | 21 Aug 2026 73,027.00 | 22 Aug 2026 78,338.00 | 1 | $727.36 |
Similar scripts
Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| JS-TechTrading- Supertrend-Strategy_Basic version this page | — | v5 strategy | +0.1% | 2 | 0.0% |
| RSI Cross [xaurr] by livetrend | rsi ema | v4 strategy | +24.4% | 53 | 35.3% |
| Supertrend + RSI Strategy [Alose] by alorse | supertrend rsi | v5 strategy | −6.1% | 14 | 8.6% |
| Bitpanda Coinrule Template by joshuajcoop01 | rsi ema | v5 strategy | −2.8% | 4 | 4.6% |
| RSI with Slow and Fast MA Crossing Strategy (by Coinrule) by Coinrule | rsi ema | v5 strategy | −2.8% | 4 | 4.6% |
| RSI of VWAP by mohanee | rsi ema | v4 strategy | No trades on this market | ||
Upgrade and export
Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.
- 5 settings use the untyped input() (line 17, 43, 44, 45, 46). It still compiles in v6; input.int, input.float or input.source state the type.
- No v6-only features. v6 is not needed to run this script.
Same 2 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 17: input() → input.int()
- Line 43: input() → input.source()
- Line 44: input() → input.int()
- Line 45: input() → input.int()
- Line 46: input() → input.int()
⋯//atr period input supertrend -atrPeriod = input(10, "ATR Length",group = group_text0)+atrPeriod = input.int(10, "ATR Length",group = group_text0)factor = input.float(3.0, "Factor", step = 0.01,group=group_text0)⋯en_rsi = input.bool(true,"Rsi Condition On/Off",group = group_text00)-rsiSource = input(title='RSI Source', defval=close,group = group_text00)+rsiSource = input.source(title='RSI Source', defval=close,group = group_text00)-rsiLength = input(title='RSI Length', defval=14,group = group_text00)+rsiLength = input.int(title='RSI Length', defval=14,group = group_text00)-rsiOverbought = input(title='RSI BUY Level', defval=50,group = group_text00)+rsiOverbought = input.int(title='RSI BUY Level', defval=50,group = group_text00)-rsiOversold = input(title='RSI SELL Level', defval=50,group = group_text00)+rsiOversold = input.int(title='RSI SELL Level', defval=50,group = group_text00)// Get RSI value⋯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: 2 before, 2 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.
⋯// © JS_TechTrading-//@version=5+//@version=6strategy("Supertrend", overlay=true,default_qty_type =strategy.percent_of_equity,default_qty_value = 1,process_orders_on_close = false)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 28 ms | With a workaround 1,000 bars in 71 ms | Not measured |
| PineTS | Not tested | Not tested | Not measured |
Zeal Terminal's engine currently reads an order side written as direction = strategy.long, direction = strategy.short as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 65, 67) so the engine trades the way the script says. The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.
“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.
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/// © JS_TechTrading//@version=5strategy("Supertrend", overlay=true,default_qty_type =strategy.percent_of_equity,default_qty_value = 1,process_orders_on_close = false)// group string////var string group_text000="Choose Strategy"var string group_text0="Supertrend Settings"var string group_text0000="Ema Settings"var string group_text00="Rsi Settings"var string group_text1="Backtest Period"var string group_text2="Trade Direction"// var string group_text3="Quantity Settings"var string group_text4="Sl/Tp Settings"////////////////////option_ch=input.string('Pullback',title = "Type Of Strategy",options =['Pullback','Simple'])//atr period input supertrend atrPeriod = input(10, "ATR Length",group = group_text0)factor = input.float(3.0, "Factor", step = 0.01,group=group_text0)[supertrend, direction] = ta.supertrend(factor, atrPeriod)bodyMiddle = plot((open + close) / 2, display=display.none)upTrend = plot(direction < 0 ? supertrend : na, "Up Trend", color = color.green, style=plot.style_linebr)downTrend = plot(direction < 0? na : supertrend, "Down Trend", color = color.red, style=plot.style_linebr)fill(bodyMiddle, upTrend, color.new(color.green, 90), fillgaps=false)fill(bodyMiddle, downTrend, color.new(color.red, 90), fillgaps=false)long=direction < 0 ? supertrend : nashort=direction < 0? na : supertrendlongpos=falseshortpos=falselongpos :=long?true :short?false:longpos[1]shortpos:=short?true:long?false:shortpos[1]fin_pullbuy= (ta.crossunder(low[1],long) and long and high>high[1])fin_pullsell=(ta.crossover(high[1],short) and short and low<low[1]) //Ema 1on_ma=input.bool(true,"Ema Condition On/Off",group=group_text0000)ma_len= input.int(200, minval=1, title="Ema Length",group = group_text0000)ma_src = input.source(close, title="Ema Source",group = group_text0000)ma_out = ta.ema(ma_src, ma_len)ma_buy=on_ma?close>ma_out?true:false:truema_sell=on_ma?close<ma_out?true:false:true// rsi indicator and condition// Get user inputen_rsi = input.bool(true,"Rsi Condition On/Off",group = group_text00)rsiSource = input(title='RSI Source', defval=close,group = group_text00)rsiLength = input(title='RSI Length', defval=14,group = group_text00)rsiOverbought = input(title='RSI BUY Level', defval=50,group = group_text00)rsiOversold = input(title='RSI SELL Level', defval=50,group = group_text00)// Get RSI valuersiValue = ta.rsi(rsiSource, rsiLength)rsi_buy=en_rsi?rsiValue>=rsiOverbought ?true:false:truersi_sell=en_rsi?rsiValue<=rsiOversold?true:false:true// final conditionbuy_cond=option_ch=='Simple'?long and not(longpos[1]) and rsi_buy and ma_buy:option_ch=='Pullback'?fin_pullbuy and rsi_buy and ma_buy:nasell_cond=option_ch=='Simple'?short and not(shortpos[1]) and rsi_sell and ma_sell:option_ch=='Pullback'?fin_pullsell and rsi_sell and ma_sell:na//backtest enginestart = input.time(timestamp('2005-01-01'), title='Start calculations from',group=group_text1)end=input.time(timestamp('2045-03-01'), title='End calculations',group=group_text1)time_cond = time >= start and time<=end// Make input option to configure trade directiontradeDirection = input.string(title='Trade Direction', options=['Long', 'Short', 'Both'], defval='Both',group = group_text2)// Translate input into trading conditionslongOK = (tradeDirection == "Long") or (tradeDirection == "Both")shortOK = (tradeDirection == "Short") or (tradeDirection == "Both")// strategy startif buy_cond and longOK and time_cond and strategy.position_size==0 strategy.entry('long',direction = strategy.long)if sell_cond and shortOK and time_cond and strategy.position_size==0 strategy.entry('short',direction =strategy.short)// fixed percentage based stop loss and take profit // User Options to Change Inputs (%)stopPer = input.float(1.0,step=0.10, title='Stop Loss %',group =group_text4) / 100takePer = input.float(1.0,step =0.10, title='Take Profit %',group =group_text4) / 100// Determine where you've entered and in what directionlongStop = strategy.position_avg_price * (1 - stopPer)shortStop = strategy.position_avg_price * (1 + stopPer)shortTake = strategy.position_avg_price * (1 - takePer)longTake = strategy.position_avg_price * (1 + takePer)if strategy.position_size > 0 strategy.exit(id='Close Long',stop=longStop, limit=longTake)if strategy.position_size < 0 strategy.exit(id='Close Short',stop=shortStop, limit=shortTake)//PLOT FIXED SLTP LINEplot(strategy.position_size > 0 ? longStop : na, style=plot.style_linebr, color=color.new(color.red, 0), linewidth=1, title='Long Fixed SL')plot(strategy.position_size < 0 ? shortStop :na, style=plot.style_linebr, color=color.new(color.red, 0), linewidth=1, title='Short Fixed SL')plot(strategy.position_size > 0 ? longTake : na, style=plot.style_linebr, color=color.new(color.green, 0), linewidth=1, title='Long Take Profit')plot(strategy.position_size < 0 ? shortTake : na, style=plot.style_linebr, color=color.new(color.green, 0), linewidth=1, title='Short Take Profit')//