Supertrend Pro Strategy [WyseTrade] V6
Based on the popular WyseTrade strategy, this script enhances the standard Supertrend with multi-timeframe (MTF) filtering and two distinct entry modes.
Strategy Logic
The strategy offers two modes of operation:
- Trend Reversal: Enters when the Supertrend flips color (Breakout).
- Band Touch: Enters when price pulls back to touch the Supertrend line and rejects it (Pullback).
It also includes a Higher Timeframe Filter to ensure you are only trading in the direction of the major trend.
Pine Script V6 Code
Copy the code below and paste it into your TradingView Pine Editor.
//@version=5
strategy("Supertrend Pro Strategy [WyseTrade]", overlay=true, initial_capital=1000, default_qty_type=strategy.percent_of_equity, default_qty_value=10, currency=currency.USD)
// ==========================================
// ─── USER INPUTS ───
// ==========================================
// Group: Supertrend Settings
grp_st = "Supertrend Settings"
st_factor = input.float(3.0, "ATR Factor", minval=1.0, step=0.1, group=grp_st, tooltip="Video suggests 2.5 to 3.0 depending on asset")
st_atr_len = input.int(10, "ATR Length", minval=1, group=grp_st)
// Group: Strategy Logic
grp_strat = "Strategy Logic"
entry_mode = input.string("Trend Reversal", "Entry Mode", options=["Trend Reversal", "Band Touch"], group=grp_strat, tooltip="'Trend Reversal' enters on color flip. 'Band Touch' enters when price wicks off the trend line.")
use_mtf = input.bool(true, "Use Higher Timeframe Filter?", group=grp_strat, tooltip="Strategy #5: Only trade in direction of HTF Trend")
htf_tf = input.timeframe("60", "Higher Timeframe", group=grp_strat)
// Group: Risk Management
grp_risk = "Risk Management"
use_rr = input.bool(true, "Use Risk:Reward Target?", group=grp_risk)
rr_ratio = input.float(1.5, "Risk:Reward Ratio", step=0.1, group=grp_risk)
// Group: Backtesting Range
grp_time = "Time Range"
start_date = input.time(timestamp("2023-01-01 00:00"), "Start Date", group=grp_time)
end_date = input.time(timestamp("2099-12-31 00:00"), "End Date", group=grp_time)
// ==========================================
// ─── CALCULATIONS ───
// ==========================================
// --- Current Timeframe Supertrend ---
[st_value, st_dir] = ta.supertrend(st_factor, st_atr_len)
// st_dir: -1 is Up (Green), 1 is Down (Red)
// --- Higher Timeframe Supertrend (MTF) ---
// We use a tuple to request both value and direction to ensure data consistency
// lookahead=barmerge.lookahead_off prevents future leak (repainting)
[htf_st_val, htf_st_dir] = request.security(syminfo.tickerid, htf_tf, ta.supertrend(st_factor, st_atr_len), lookahead=barmerge.lookahead_off)
// ==========================================
// ─── LOGIC & CONDITIONS ───
// ==========================================
// Check Time Range
in_date_range = true
// 1. Directional Logic
is_uptrend = st_dir < 0
is_downtrend = st_dir > 0
// 2. MTF Filter Logic
// If MTF is disabled, we force the condition to true
mtf_bullish = use_mtf ? (htf_st_dir < 0) : true
mtf_bearish = use_mtf ? (htf_st_dir > 0) : true
// 3. Entry Signals
// -- Strategy A: Trend Reversal (Breakout) --
// Enter Long when trend switches from Down to Up
bull_reversal = ta.change(st_dir) < 0
// Enter Short when trend switches from Up to Down
bear_reversal = ta.change(st_dir) > 0
// -- Strategy B: Band Touch (Pullback) --
// Enter Long if we are in an uptrend, Low touched the line, but closed above (Wick rejection)
bull_touch = is_uptrend and low <= st_value and close > st_value
// Enter Short if we are in a downtrend, High touched the line, but closed below
bear_touch = is_downtrend and high >= st_value and close < st_value
// Consolidate Entry Conditions based on User Input
long_condition = false
short_condition = false
if entry_mode == "Trend Reversal"
long_condition := bull_reversal and mtf_bullish and in_date_range
short_condition := bear_reversal and mtf_bearish and in_date_range
else if entry_mode == "Band Touch"
long_condition := bull_touch and mtf_bullish and in_date_range
short_condition := bear_touch and mtf_bearish and in_date_range
// ==========================================
// ─── EXECUTION ───
// ==========================================
// Entry
if long_condition
strategy.entry("Long", strategy.long)
if short_condition
strategy.entry("Short", strategy.short)
// Exit Strategy #2: Trailing Stop using Supertrend Line
// If we are Long, the ST Value is below price. If we are Short, ST Value is above price.
// We also implement the RR Target if enabled.
// Calculate TP prices based on entry price and stop distance (ATR based via Supertrend)
// We check if opentrades > 0 to avoid error when accessing strategy.opentrades.entry_price
if strategy.opentrades > 0
float entry_price = strategy.opentrades.entry_price(strategy.opentrades - 1)
if strategy.position_size > 0
// Long Exit
// Stop Loss is dynamic (the Supertrend line itself)
// Take Profit is fixed R:R based on the distance between Entry and Initial ST
// Note: For trailing stop simulation, we use the CURRENT st_value
float risk = math.abs(entry_price - st_value) // Simplified risk calc for dynamic updates or use fixed entry risk
// To strictly follow video "Limit Risk", we calculate TP based on entry.
// But since SL moves, calculating exact initial risk is tricky post-entry without variables.
// Here we use current distance for dynamic or standard ATR distance.
// Let's use a simpler ATR based distance for TP target stability:
float atr_val = ta.atr(st_atr_len)
float dynamic_risk = atr_val * st_factor
float tp = use_rr ? entry_price + (dynamic_risk * rr_ratio) : na
strategy.exit("Exit Long", "Long", stop = st_value, limit = tp, comment_loss = "Trail SL", comment_profit = "TP Hit")
if strategy.position_size < 0
// Short Exit
float entry_price_short = strategy.opentrades.entry_price(strategy.opentrades - 1)
float atr_val = ta.atr(st_atr_len)
float dynamic_risk = atr_val * st_factor
float tp = use_rr ? entry_price_short - (dynamic_risk * rr_ratio) : na
strategy.exit("Exit Short", "Short", stop = st_value, limit = tp, comment_loss = "Trail SL", comment_profit = "TP Hit")
// ==========================================
// ─── VISUALIZATION ───
// ==========================================
// Plot Supertrend Line
plot_color = is_uptrend ? color.green : color.red
plot(st_value, "Supertrend", color = plot_color, linewidth = 2)
// Plot Background Signal (Green/Red Zones)
bgcolor(is_uptrend ? color.new(color.green, 90) : color.new(color.red, 90), title="Trend Background")
// Plot Buy/Sell Shapes for visual verification
plotshape(long_condition, title="Buy Signal", style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small)
plotshape(short_condition, title="Sell Signal", style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small)
// Force Close if Trend flips against us (Hard exit backup)
if strategy.position_size > 0 and is_downtrend
strategy.close("Long", comment="Trend Flip")
if strategy.position_size < 0 and is_uptrend
strategy.close("Short", comment="Trend Flip")
How to Optimize This Strategy
Raw strategies often fail due to slippage and lack of dynamic risk management. To make this strategy production-ready:
- Add Commission Logic: Most backtests ignore fees.
- Implement Dynamic Stops: Use ATR-based trailing stops.
- Filter Choppy Markets: Add an ADX or Volume filter.
You can do all of this automatically using our AI Co-pilot.