Enhanced Multi-Filter Supertrend Strategy

ATR RSI SMA EMA WMA supertrend TREND FOLLOWING risk management BREAKOUT CONFIRMATION
Created on: 2025-08-04 13:00:58 Modified on: 2025-08-04 13:00:58
Copy: 0 Number of hits: 325
avatar of ianzeng123 ianzeng123
2
Follow
319
Followers

 Enhanced Multi-Filter Supertrend Strategy  Enhanced Multi-Filter Supertrend Strategy

Overview

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.

Strategy Principles

The core of this strategy is an enhanced Supertrend indicator that works as follows:

  1. 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.

  2. Multiple Filtering Mechanisms:

    • RSI Filter: Optionally enabled to avoid counter-trend trading in overbought/oversold areas.
    • Moving Average Filter: Choice of SMA/EMA/WMA types to confirm if price aligns with the overall trend.
    • Trend Strength Analysis: Filters weak signals by requiring minimum trend duration.
    • Breakout Confirmation: Requires price to actually break through Supertrend levels for stronger trading signals.
  3. Intelligent Signal Generation:

    • Buy Signal: Triggered when Supertrend changes from bearish to bullish while satisfying all enabled filter conditions.
    • Sell Signal: Triggered when Supertrend changes from bullish to bearish while satisfying all enabled filter conditions.
  4. Risk Management System:

    • Dynamic stop-loss and take-profit levels based on ATR, automatically adjusting to market volatility.
    • Stop-loss and take-profit distances set as multiples of ATR, ensuring risk management adapts to market conditions.

Strategy Advantages

This strategy offers several significant advantages compared to traditional trend-following systems:

  1. Enhanced Adaptability: Support/resistance levels adjusted by ATR automatically adapt to changes in market volatility, suitable for different market environments.

  2. 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.

  3. Flexibility and Customizability:

    • The strategy provides rich parameter settings, allowing traders to adjust the strategy according to personal preferences and different markets.
    • Various filters can be selectively enabled/disabled, simplifying or complicating the strategy as needed.
  4. Built-in Risk Management: Automated stop-loss and take-profit functions based on market volatility provide an intelligent and dynamic approach to risk control.

  5. Comprehensive Visual Interface: Provides detailed chart markers, trend background coloring, and status tables, allowing traders to intuitively understand strategy status and market conditions.

  6. 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.

Strategy Risks

Despite its sophisticated design, the strategy still has the following risks and limitations:

  1. 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.

  2. 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.

  3. Parameter Sensitivity:

    • Strategy performance highly depends on parameter settings, and different market environments may require different parameter combinations.
    • Excessive parameter optimization may lead to overfitting risk, causing the strategy to perform poorly in live trading.
  4. Opportunity Cost of Multiple Filters: Strict multiple filtering conditions may cause the strategy to miss some profitable trading opportunities, especially in rapidly changing markets.

  5. 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.

Strategy Optimization Directions

This strategy can be optimized in the following directions:

  1. Adaptive Parameter System:

    • Implement automatic adjustment of ATR multipliers and filter parameters based on market volatility or trend strength.
    • This will enable the strategy to better adapt to different market environments, reducing the need for manual parameter adjustments.
  2. Market Environment Classification:

    • Add market environment analysis functionality to automatically identify trending, oscillating, or transitional markets.
    • Use different parameter sets or even completely different trading logic based on different market types.
  3. Optimize Entry and Exit Timing:

    • Introduce partial position management and staged entry/exit functionality to reduce the impact of single false signals.
    • Consider adding confirmation indicators based on volume-price relationships to further improve entry signal quality.
  4. Risk Management Enhancement:

    • Implement dynamic position size adjustment based on market volatility and current trend strength.
    • Add trailing stop-loss functionality to protect existing profits while allowing trends sufficient room to develop.
  5. Add Machine Learning Elements:

    • Consider using simple machine learning models to predict Supertrend reversal probability.
    • Optimize parameter selection based on historical data pattern recognition, reducing human intervention.

Summary

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.

Strategy source code
/*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)