
The Enhanced Multi-Filter Supertrend Strategy is an advanced quantitative trading strategy based on an enhanced version of the traditional Supertrend indicator, combined with multiple technical filters, risk management systems, and advanced signal confirmation mechanisms. Implemented in Pine Script v5, this strategy is designed for automated trading on the TradingView platform. The core of the strategy utilizes ATR (Average True Range) to dynamically adjust support and resistance levels, while integrating RSI (Relative Strength Index) and moving averages for signal filtering, significantly improving the reliability of trading signals through multiple confirmation mechanisms.
The core of this strategy is an enhanced Supertrend indicator that works as follows:
Supertrend Calculation: Uses ATR multiplied by a user-defined multiplier to calculate volatility range, then determines upper and lower channels based on price position. Trend direction is determined by the relationship between price and these channels.
Multiple Filtering Mechanisms:
Intelligent Signal Generation:
Risk Management System:
This strategy offers several significant advantages compared to traditional trend-following systems:
Enhanced Adaptability: Support/resistance levels adjusted by ATR automatically adapt to changes in market volatility, suitable for different market environments.
Multi-layered Confirmation Mechanism: By integrating multiple filtering conditions such as RSI, moving averages, trend strength, and breakout confirmation, significantly reduces false signals and improves strategy reliability.
Flexibility and Customizability:
Built-in Risk Management: Automated stop-loss and take-profit functions based on market volatility provide an intelligent and dynamic approach to risk control.
Comprehensive Visual Interface: Provides detailed chart markers, trend background coloring, and status tables, allowing traders to intuitively understand strategy status and market conditions.
Backtesting and Performance Analysis: Built-in comprehensive backtesting functionality, including consideration of trading commissions, providing key metrics such as win rate, profit factor, Sharpe ratio, etc.
Despite its sophisticated design, the strategy still has the following risks and limitations:
Poor Performance in Oscillating Markets: As a trend-following strategy, it may generate multiple false signals in sideways, oscillating markets, leading to frequent trading and losses.
Lag Risk: Both Supertrend and moving averages are lagging indicators, which may result in late entry or exit during trend reversals, missing some profits or increasing potential losses.
Parameter Sensitivity:
Opportunity Cost of Multiple Filters: Strict multiple filtering conditions may cause the strategy to miss some profitable trading opportunities, especially in rapidly changing markets.
Stop-Loss Trigger Risk: In highly volatile markets, ATR-based stop-losses may be easily triggered, causing the strategy to exit prematurely in what would otherwise be the correct trend direction.
Solutions: - Avoid using this strategy in low-volatility or obviously oscillating market environments. - Consider adding an adaptive parameter adjustment mechanism based on market volatility assessment. - Regularly backtest and adjust parameters based on market conditions, avoiding excessive reliance on a single parameter combination. - Consider adding time filters to trade only during periods when market trends are strong.
This strategy can be optimized in the following directions:
Adaptive Parameter System:
Market Environment Classification:
Optimize Entry and Exit Timing:
Risk Management Enhancement:
Add Machine Learning Elements:
The Enhanced Multi-Filter Supertrend Strategy is a comprehensive trend-following system that provides a powerful trading framework through an enhanced Supertrend indicator, multiple technical filters, and advanced risk management features. The strategy’s greatest strengths lie in its adaptability and multi-layered confirmation mechanism, allowing it to adjust behavior in different market environments and filter out low-quality signals.
However, the strategy also faces challenges such as poor performance in oscillating markets and parameter sensitivity. By introducing adaptive parameter systems, market environment classification, and optimized risk management functions, the robustness and performance of the strategy can be further enhanced.
For traders looking to leverage the advantages of trend following while controlling risk, this strategy provides an excellent starting point that can be further customized and optimized according to individual needs and market characteristics. Ultimately, the effectiveness of the strategy will depend on the trader’s careful selection of parameters, accurate assessment of market conditions, and strict risk management discipline.
/*backtest
start: 2024-08-04 00:00:00
end: 2025-08-02 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"DOGE_USDT"}]
*/
//@version=5
strategy("Advanced Supertrend Strategy", shorttitle="AdvST", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.1)
// === INPUT PARAMETERS ===
// Supertrend Settings
atr_length = input.int(6, title="ATR Length", minval=1, tooltip="Length for ATR calculation in Supertrend", group="Supertrend Settings")
multiplier = input.float(3.0, title="Supertrend Multiplier", minval=0.1, step=0.1, tooltip="Multiplier for ATR in Supertrend calculation", group="Supertrend Settings")
// RSI Filter
use_rsi_filter = input.bool(false, title="Enable RSI Filter", tooltip="Use RSI to filter signals", group="RSI Filter")
rsi_length = input.int(14, title="RSI Length", minval=1, tooltip="Length for RSI calculation", group="RSI Filter")
rsi_overbought = input.int(70, title="RSI Overbought", minval=50, maxval=100, tooltip="RSI overbought level", group="RSI Filter")
rsi_oversold = input.int(30, title="RSI Oversold", minval=0, maxval=50, tooltip="RSI oversold level", group="RSI Filter")
// Moving Average Filter
use_ma_filter = input.bool(true, title="Enable MA Filter", tooltip="Use Moving Average trend filter", group="MA Filter")
ma_length = input.int(50, title="MA Length", minval=1, tooltip="Length for Moving Average", group="MA Filter")
ma_type = input.string("WMA", title="MA Type", options=["SMA", "EMA", "WMA"], tooltip="Type of Moving Average", group="MA Filter")
// Risk Management
use_stop_loss = input.bool(true, title="Enable Stop Loss", tooltip="Use stop loss based on ATR", group="Risk Management")
sl_multiplier = input.float(3.0, title="Stop Loss ATR Multiplier", minval=0.1, step=0.1, tooltip="Stop loss distance in ATR multiples", group="Risk Management")
use_take_profit = input.bool(true, title="Enable Take Profit", tooltip="Use take profit based on ATR", group="Risk Management")
tp_multiplier = input.float(9.0, title="Take Profit ATR Multiplier", minval=0.1, step=0.1, tooltip="Take profit distance in ATR multiples", group="Risk Management")
// Advanced Features
use_trend_strength = input.bool(false, title="Enable Trend Strength Filter", tooltip="Filter weak trends", group="Advanced Features")
min_trend_bars = input.int(2, title="Minimum Trend Bars", minval=1, tooltip="Minimum bars in trend direction", group="Advanced Features")
use_breakout_confirmation = input.bool(true, title="Enable Breakout Confirmation", tooltip="Wait for price to break supertrend level", group="Advanced Features")
// Date Range for Backtesting
in_date_range = true
// === TECHNICAL INDICATORS ===
// Supertrend Calculation
atr = ta.atr(atr_length)
hl2_val = hl2
up = hl2_val - (multiplier * atr)
down = hl2_val + (multiplier * atr)
var float trend_up = na
var float trend_down = na
var int trend = 1
trend_up := close[1] > trend_up[1] ? math.max(up, trend_up[1]) : up
trend_down := close[1] < trend_down[1] ? math.min(down, trend_down[1]) : down
trend := close <= trend_down[1] ? -1 : close >= trend_up[1] ? 1 : nz(trend[1], 1)
supertrend = trend == 1 ? trend_up : trend_down
supertrend_color = trend == 1 ? color.green : color.red
// RSI Calculation
rsi = ta.rsi(close, rsi_length)
// Moving Average Calculation
ma = ma_type == "SMA" ? ta.sma(close, ma_length) : ma_type == "EMA" ? ta.ema(close, ma_length) : ta.wma(close, ma_length)
// Trend Strength Analysis
var int trend_strength = 0
if trend != trend[1]
trend_strength := 1
else
trend_strength := trend_strength[1] + 1
// === SIGNAL GENERATION ===
// Basic Supertrend Signals
supertrend_bullish = trend == 1 and trend[1] == -1 // Supertrend changes from bearish to bullish
supertrend_bearish = trend == -1 and trend[1] == 1 // Supertrend changes from bullish to bearish
// Advanced Signal Filters
rsi_buy_condition = not use_rsi_filter or (rsi > rsi_oversold and rsi < rsi_overbought)
rsi_sell_condition = not use_rsi_filter or (rsi < rsi_overbought and rsi > rsi_oversold)
ma_buy_condition = not use_ma_filter or close > ma
ma_sell_condition = not use_ma_filter or close < ma
trend_strength_condition = not use_trend_strength or trend_strength >= min_trend_bars
breakout_buy_condition = not use_breakout_confirmation or close > supertrend[1]
breakout_sell_condition = not use_breakout_confirmation or close < supertrend[1]
// Final Signal Logic
buy_signal = supertrend_bullish and rsi_buy_condition and ma_buy_condition and trend_strength_condition and breakout_buy_condition and in_date_range
sell_signal = supertrend_bearish and rsi_sell_condition and ma_sell_condition and trend_strength_condition and breakout_sell_condition and in_date_range
// === STRATEGY EXECUTION ===
// Entry Logic
if buy_signal and strategy.position_size <= 0
entry_price = close
stop_loss_price = use_stop_loss ? entry_price - (atr * sl_multiplier) : na
take_profit_price = use_take_profit ? entry_price + (atr * tp_multiplier) : na
strategy.entry("Long", strategy.long, alert_message="Advanced Supertrend BUY Signal")
if use_stop_loss
strategy.exit("Long SL/TP", "Long", stop=stop_loss_price, limit=take_profit_price)
if sell_signal and strategy.position_size >= 0
entry_price = close
stop_loss_price = use_stop_loss ? entry_price + (atr * sl_multiplier) : na
take_profit_price = use_take_profit ? entry_price - (atr * tp_multiplier) : na
strategy.entry("Short", strategy.short, alert_message="Advanced Supertrend SELL Signal")
if use_stop_loss
strategy.exit("Short SL/TP", "Short", stop=stop_loss_price, limit=take_profit_price)