Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

[VJ] Mega Supertrend for Intraday

A Pine Script v4 strategy built on SMA (close, fast), EMA (close, ema150) and Supertrend (3, 7). 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 is one contract and pays no commission. 7 settings; defaults include Market session 0915-1455, Long Take Profit (%) 1 and Short Take Profit (%) 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 [VJ] Mega Supertrend for Intraday repaint?
No
No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
How did [VJ] Mega Supertrend for Intraday do on BTCUSDT 1D with default settings?
Not measured
It closed no trades there from 26 Jan 2024 to 21 Oct 2026 with the default settings, so there is no result to report. Its code limits trading to a session window, which can leave these candles out. On BTCUSDT 4h it did trade; that row of the markets table below has its figures. A backtest, not investment advice.
Can [VJ] Mega Supertrend for Intraday 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 [VJ] Mega Supertrend for Intraday use a stop loss?
Yes
strategy.exit sets a stop on line 100, 106.
Does [VJ] Mega Supertrend for Intraday run in Zeal Terminal?
Yes
It compiles in 13 ms and runs 1,000 bars in 40 ms, in the browser.

BTCUSDT · 1D · default settings

  • SMA
  • SMA
  • SMA
  • EMA
  • Supertrend up
  • Supertrend down
  • Supertrend up
  • Supertrend down
  • 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 (7)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$100,000$202,527Equity from $100,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. The script plots nothing itself; the lines and the lower pane are its own calculations, drawn for reference. 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.
Net profit
0.00%
$0.00
Buy and hold
+102.5%
same period
Closed trades
0
0 won · 0 lost
Profitable
0.0%
of closed trades
Profit factor
—
gross profit ÷ gross loss
Max drawdown
0.00%
$0.00

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

  • Note

    Uses an argument v6 removed

    when = on line 111. 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 sma → ta.sma, ema → ta.ema, supertrend → ta.supertrend.
  • 1 strategy call uses the when = argument (line 111). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Differs

Trades differ: 10 before, 14 after on BTCUSDT 4h, 1,000 bars, in Zeal Terminal's engine.

  • Line 3: //@version=4 → //@version=5
  • Line 11: input(type = input.session) → input.session()
  • Line 14: input(type = input.float) → input.float()
  • Line 16: input(type = input.float) → input.float()
  • Line 20: input(type = input.float) → input.float()
  • Line 22: input(type = input.float) → input.float()
11 more edits
  • Line 24: input(type = input.float) → input.float()
  • Line 26: input(type = input.integer) → input.int()
  • Line 41: sma → ta.sma
  • Line 42: sma → ta.sma
  • Line 43: sma → ta.sma
  • Line 45: ema → ta.ema
  • Line 62: supertrend → ta.supertrend
  • Line 92: vwap → ta.vwap
  • Line 92: vwap → ta.vwap
  • Line 93: vwap → ta.vwap
  • Line 93: vwap → ta.vwap
⋯// © vikris-//@version=4+//@version=5strategy("[VJ]Mega ST - Intra Strat", overlay=true, calc_on_every_tick = false)⋯// square-off time set by your broker-var i_marketSession = input(title="Market session", type=input.session, +var i_marketSession = input.session(title="Market session",      defval="0915-1455", confirm=true)// Make inputs that set the take profit % (optional)-longProfitPerc = input(title="Long Take Profit (%)",-     type=input.float, minval=0.0, step=0.1, defval=1) * 0.01+longProfitPerc = input.float(title="Long Take Profit (%)", minval=0.0, step=0.1, defval=1) * 0.01-shortProfitPerc = input(title="Short Take Profit (%)",-     type=input.float, minval=0.0, step=0.1, defval=1) * 0.01+shortProfitPerc = input.float(title="Short Take Profit (%)", minval=0.0, step=0.1, defval=1) * 0.01     // Set stop loss level with input options (optional)-longLossPerc = input(title="Long Stop Loss (%)",-     type=input.float, minval=0.0, step=0.1, defval=0.5) * 0.01+longLossPerc = input.float(title="Long Stop Loss (%)", minval=0.0, step=0.1, defval=0.5) * 0.01-shortLossPerc = input(title="Short Stop Loss (%)",-     type=input.float, minval=0.0, step=0.1, defval=0.5) * 0.01    +shortLossPerc = input.float(title="Short Stop Loss (%)", minval=0.0, step=0.1, defval=0.5) * 0.01    -var float i_multiplier = input(title = "ST Multiplier", type = input.float, +var float i_multiplier = input.float(title = "ST Multiplier",      defval = 3, step = 0.1, confirm=true)-var int i_atrPeriod = input(title = "ST ATR Period", type = input.integer, +var int i_atrPeriod = input.int(title = "ST ATR Period",      defval = 7, confirm=true)⋯fast = 20, slow = 50, ultraSlow = 200-fastMA = sma(close, fast)+fastMA = ta.sma(close, fast)-slowMA = sma(close, slow)+slowMA = ta.sma(close, slow)-ultraSlowMA = sma(close, ultraSlow)+ultraSlowMA = ta.sma(close, ultraSlow)ema150 = 200-ema150MA = ema(close, ema150)+ema150MA = ta.ema(close, ema150)// smooth = input(3, minval=1), K = input(14, minval=1), D=input(3,minval=1)⋯// Trade only if intraday session is active-[superTrend, dir] = supertrend(i_multiplier, i_atrPeriod)+[superTrend, dir] = ta.supertrend(i_multiplier, i_atrPeriod)colResistance = dir == 1 and dir == dir[1] ? color.new(color.red, 0) : color.new(color.red, 100)⋯//Final Long/Short Condition-longCondition = stlong and redCandle and vol and vwap > vwap[1]+longCondition = stlong and redCandle and vol and ta.vwap > ta.vwap[1]-shortCondition =stshort and greenCandle and vol and vwap < vwap[1]+shortCondition =stshort and greenCandle and vol and ta.vwap < ta.vwap[1] ⋯

Clean v5

Verified

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

  • Line 107: when = squareOff → if block
⋯squareOff = (not intradaySession) and (strategy.position_size != 0)-strategy.close_all(when = squareOff, comment = "Square-off")+if squareOff+    strategy.close_all(comment = "Square-off")// ********** Strategy - End **********

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: 14 before, 24 after on BTCUSDT 4h, 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.

⋯// © vikris-//@version=5+//@version=6strategy("[VJ]Mega ST - Intra Strat", overlay=true, 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
Market session0915-1455sessionintradaySession
Long Take Profit (%)1float · min 0.0 · step 0.1longExitPrice
Short Take Profit (%)1float · min 0.0 · step 0.1shortExitPrice
Long Stop Loss (%)0.5float · min 0.0 · step 0.1longStopPrice
Short Stop Loss (%)0.5float · min 0.0 · step 0.1shortStopPrice
ST Multiplier3float · step 0.1superTrend dir
ST ATR Period7int (written input.integer)superTrend dir

What it calculates

  • SMA (sma, ta.sma in v5)close, fastfastMA · line 41
  • SMA (sma, ta.sma in v5)close, slowslowMA · line 42
  • SMA (sma, ta.sma in v5)close, ultraSlowultraSlowMA · line 43
  • EMA (ema, ta.ema in v5)close, ema150ema150MA · line 45
  • Supertrend (supertrend, ta.supertrend in v5)ST Multiplier (3), ST ATR Period (7)superTrend · line 62
  • Supertrend (supertrend, ta.supertrend in v5)ST Multiplier (3), ST ATR Period (7)dir · line 62

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.

closecloseprice datahigh · low · closehigh · low · closeprice datai_multiplierST Multipliersetting · 3i_atrPeriodST ATR Periodsetting · 7i_marketSessionMarket sessionsetting · 0915-1455longProfitPercLong Take Profit (%)setting · 1shortProfitPercShort Take Profit (%)setting · 1longLossPercLong Stop Loss (%)setting · 0.5shortLossPercShort Stop Loss (%)setting · 0.5volumevolumeprice dataopenopenprice datafastMASMA→ fastMAslowMASMA→ slowMAultraSlowMASMA→ ultraSlowMAema150MAEMA→ ema150MAsuperTrendSupertrend→ superTrenddirSupertrend→ dirintradaySessionintradaySessionvaluelongExitPricelongExitPricevalueshortExitPriceshortExitPricevaluelongStopPricelongStopPricevalueshortStopPriceshortStopPricevaluestop_levelstop_levelvalueprofit_levelprofit_levelvaluelongConditionlongConditionconditionshortConditionshortConditionconditionsquareOffsquareOffconditionstlong, stshortstlong · stshort2 conditionsvolvolconditionbullishEC, bearishEC, greenCandle, redCandlebullishEC · bearishEC +24 conditionscolResistance, colSupportColourcolResistance · colSupportentry:My Long Entry IdOpen My Long Entry Idstrategy.entryexit:TP/SLexit TP/SLstrategy.exitentry:My Short Entry IdOpen My Short Entry Idstrategy.entryclose_all:close_all strategy.close_all

Order rules

OrderFires whenBy defaultLine
Open My Long Entry Id long(longCondition and intradaySession)On99
Exit TP/SL stop and limit(longCondition and intradaySession)On100
Open My Short Entry Id short(shortCondition and intradaySession)On105
Exit TP/SL stop and limit(shortCondition and intradaySession)On106
Close squareOff(not intradaySession) and (strategy.position_size != 0)On111

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.

Not measuredNo trades to compareThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, but neither the live nor the historical run produced any trades in them, so the replay says nothing either way.
  • 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 1D0.0%+102.5%00%—0.0%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−0.6%+5.5%1050%0.671.6%8 May 2026 – 21 Oct 2026
ETHUSDT 1D0.0%+9.8%00%—0.0%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−0.0%+8.4%743%0.240.1%8 May 2026 – 21 Oct 2026
SOLUSDT 1D0.0%+16.7%00%—0.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−0.0%+21.5%1250%0.820.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D0.0%+148.3%00%—0.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−0.0%+17.1%90%0.000.0%8 May 2026 – 21 Oct 2026

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

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
[VJ] Mega Supertrend for Intraday this page—v4 strategy0.0%00.0%
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%
5-10-20 Cross by aadilpatel07supertrend emav4 strategy+36.0%3551.2%

Where it runs

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

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. 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/// © vikris//@version=4strategy("[VJ]Mega ST - Intra Strat", overlay=true, calc_on_every_tick = false)// ********** Strategy inputs - Start **********// Used for intraday handling// Session value should be from market start to the time you want to square-off // your intraday strategy// Important: The end time should be at least 2 minutes before the intraday// square-off time set by your brokervar i_marketSession = input(title="Market session", type=input.session,      defval="0915-1455", confirm=true)// Make inputs that set the take profit % (optional)longProfitPerc = input(title="Long Take Profit (%)",     type=input.float, minval=0.0, step=0.1, defval=1) * 0.01shortProfitPerc = input(title="Short Take Profit (%)",     type=input.float, minval=0.0, step=0.1, defval=1) * 0.01     // Set stop loss level with input options (optional)longLossPerc = input(title="Long Stop Loss (%)",     type=input.float, minval=0.0, step=0.1, defval=0.5) * 0.01shortLossPerc = input(title="Short Stop Loss (%)",     type=input.float, minval=0.0, step=0.1, defval=0.5) * 0.01    var float i_multiplier = input(title = "ST Multiplier", type = input.float,      defval = 3, step = 0.1, confirm=true)var int i_atrPeriod = input(title = "ST ATR Period", type = input.integer,      defval = 7, confirm=true)     // rsiSource = input(title="RSI Source", type=input.source, defval=close)// rsiLength = input(title="RSI Length", type=input.integer, defval=14)// rsiOverbought = input(title="RSI Overbought Level", type=input.integer, defval=70)// rsiOversold = input(title="RSI Oversold Level", type=input.integer, defval=30)// // Get RSI value// rsiValue = rsi(rsiSource, rsiLength)// //rsi sell// rsisell = rsiValue >= rsiOverbought// //rsi buy// rsibuy = rsiValue <= rsiOversold  //Get Stochastic valuesfast = 20, slow = 50, ultraSlow = 200fastMA = sma(close, fast)slowMA = sma(close, slow)ultraSlowMA = sma(close, ultraSlow)ema150 = 200ema150MA = ema(close, ema150)// smooth = input(3, minval=1), K = input(14, minval=1), D=input(3,minval=1)// hh=highest(high,K)// ll=lowest(low,K)// k = sma((close-ll)/(hh-ll)*100, smooth)// d = sma(k, 3)// stochiasticHigh = 80// stochiasticLow = 20// ********** Strategy inputs - End **********// ********** Supporting functions - Start **********// A function to check whether the bar or period is in intraday sessionbarInSession(sess) => time(timeframe.period, sess) != 0// ********** Supporting functions - End **********// ********** Strategy - Start **********// See if intraday session is activebool intradaySession = barInSession(i_marketSession)// Trade only if intraday session is active[superTrend, dir] = supertrend(i_multiplier, i_atrPeriod)colResistance = dir == 1 and dir == dir[1] ? color.new(color.red, 0) : color.new(color.red, 100)colSupport = dir == -1 and dir == dir[1] ? color.new(color.green, 0) : color.new(color.green, 100)// plot(superTrend, color = colResistance, linewidth=2)// plot(superTrend, color = colSupport, linewidth=2)// Super Trend Long/short conditionstlong = close > superTrendstshort = close < superTrend//Vol Confirmationvol = volume > volume[1]//Engulfing candle confirmbullishEC = close > open[1] and close[1] < open[1]bearishEC = close < open[1] and close[1] > open[1]//Candles colorsgreenCandle = (close > open)redCandle = (close < open)// //Stochastic computation// selldata = close < ema150MA and k>stochiasticHigh and d>stochiasticHigh and close>open// // plotshape(selldata, style=shape.triangledown, location=location.belowbar, color=color.red)// buydata2 = close > ema150MA and k<stochiasticLow and d<stochiasticLow and close<open// // plotshape(buydata2, style=shape.triangleup, location=location.abovebar, color=color.green)// Figure out take profit pricelongExitPrice  = strategy.position_avg_price * (1 + longProfitPerc)shortExitPrice = strategy.position_avg_price * (1 - shortProfitPerc)// Determine stop loss pricelongStopPrice  = strategy.position_avg_price * (1 - longLossPerc)shortStopPrice = strategy.position_avg_price * (1 + shortLossPerc)  //Final Long/Short ConditionlongCondition = stlong and redCandle and vol and vwap > vwap[1]shortCondition =stshort and greenCandle and vol and vwap < vwap[1] //Long Strategy - buy condition and exits with Take profit and SLif (longCondition and intradaySession)    stop_level = longStopPrice    profit_level = longExitPrice    strategy.entry("My Long Entry Id", strategy.long)    strategy.exit("TP/SL", "My Long Entry Id", stop=stop_level, limit=profit_level)//Short Strategy - sell condition and exits with Take profit and SLif (shortCondition and intradaySession)    stop_level = shortStopPrice    profit_level = shortExitPrice    strategy.entry("My Short Entry Id", strategy.short)    strategy.exit("TP/SL", "My Short Entry Id", stop=stop_level, limit=profit_level)  // Square-off position (when session is over and position is open)squareOff = (not intradaySession) and (strategy.position_size != 0)strategy.close_all(when = squareOff, comment = "Square-off")// ********** Strategy - End **********