
The Advanced Dynamic Trend Range Filtering Quantitative Trading Strategy is a trend-following system based on dynamic price volatility ranges. Its core concept involves constructing an adaptive price filtering mechanism through dual timeframe smoothed range calculations to effectively identify market trend changes and generate trading signals. The strategy utilizes exponential moving averages (EMAs) from fast and slow time periods to calculate price volatility ranges and creates trend range boundaries through a unique range filtering algorithm. When prices break through these boundaries, the system automatically generates buy or sell signals, helping traders capture trend reversal points while filtering out market noise. The strategy also provides intuitive chart visualization features, enabling traders to clearly identify trend direction, strength, and potential trading opportunities.
The core principle of this strategy is to establish a dynamic trend filter by calculating smoothed ranges of price volatility, implemented through the following steps:
Dual Range Calculation: The strategy uses two time periods (fast and slow) to calculate price volatility ranges. It first computes the absolute price change, then applies exponential moving averages (EMA) for smoothing, and finally adjusts the range size through custom multipliers.
Range Filter Application: The calculated smoothed range is applied to the price through the apply_range_filter function, which ensures that the new filtered price doesn’t deviate too far from the previous filtered price, thereby reducing false signals.
Trend Identification: The strategy tracks consecutive increases or decreases in the filtered price to quantify trend strength and persistence.
Range Boundary Construction: Based on the filtered price and average smoothed range, the strategy calculates upper and lower boundaries. These boundaries dynamically adjust according to historical price behavior, forming the trend range filter.
Signal Generation: Buy signals are generated when the closing price crosses above the trend range filter, and sell signals when it crosses below. These signals directly inform the entry and exit decisions of the trading strategy.
From the code implementation, the strategy uses multi-layered nested conditional logic to determine the value of the trend range filter, enabling the filter to adapt to different market conditions and improve signal reliability. The trend range filter essentially functions as an adaptive dynamic support and resistance line that automatically adjusts its sensitivity based on market volatility.
A deep analysis of the strategy’s code implementation reveals the following significant advantages:
Strong Adaptability: Through dual timeframe (fast and slow period) range calculations, the filter can automatically adapt to volatility changes under different market conditions. This adaptive characteristic allows the strategy to maintain relatively stable performance across various market environments.
Noise Filtering Capability: Through smoothed range calculations and conditional filtering mechanisms, the strategy effectively reduces the impact of market noise on trading decisions, lowering the frequency of false signals.
Trend Strength Quantification: By tracking consecutive increases or decreases in the filtered price, the strategy provides traders with quantitative indicators of trend strength, helping to assess the reliability of current trends.
Visual Intuitiveness: The strategy marks buy and sell signals on the chart and fills different trend areas with colors, greatly improving the visual identification efficiency of trading opportunities.
Parameter Adjustability: The strategy offers multiple adjustable input parameters (such as fast/slow periods, range multipliers, etc.), allowing traders to optimize strategy performance for different trading instruments and timeframes.
Structured Code Design: The strategy adopts a modular design, encapsulating core calculation logic through custom functions, making the code easier to understand and maintain while facilitating subsequent expansion and optimization.
Despite its many advantages, the strategy also has potential risks and limitations:
Parameter Sensitivity: Strategy performance is highly dependent on the choice of input parameters. Different time period and multiplier settings may lead to completely different trading results. Traders need to conduct thorough backtesting and optimization to find the optimal parameter combination for specific markets.
Lag Risk: As the strategy uses EMAs for smoothing, it inevitably introduces a certain degree of lag, especially in cases of violent market fluctuations or rapid reversals, potentially causing delayed entry or exit signals.
False Breakout Risk: In range-bound or low-volatility markets, prices may frequently cross the trend range filter, generating multiple false signals, leading to frequent trading and increased transaction costs.
Lack of Stop-Loss Mechanism: The current strategy implementation lacks an explicit stop-loss mechanism, potentially facing significant losses in cases of sudden trend reversals. Traders are advised to supplement with appropriate risk management measures.
Single Signal Source: The strategy relies solely on price crosses with the trend range filter to generate signals, lacking auxiliary verification from other confirmation indicators, which may result in insufficient signal reliability.
To mitigate these risks, traders should consider adding additional filtering conditions, such as combining other technical indicators (like RSI, MACD, etc.) for signal confirmation, while implementing strict money management and stop-loss strategies.
Through in-depth analysis of the code implementation, the following potential optimization directions can be proposed:
Multiple Confirmation Mechanisms: Introduce additional technical indicators or conditions as signal confirmation, such as combining volume, momentum indicators, or market structure analysis to improve signal reliability. This can reduce false signals by executing trades only when multiple conditions are simultaneously satisfied.
Dynamic Parameter Adjustment: Implement automatic optimization mechanisms for parameters, enabling the strategy to automatically adjust fast/slow periods and multiplier values based on changing market conditions. For example, range multipliers could be dynamically adjusted based on market volatility indicators such as ATR.
Enhanced Risk Management: Add stop-loss and profit-taking mechanisms, such as setting dynamic stop-losses based on ATR, or using reverse crosses of the trend range filter as exit signals. Comprehensive risk management can significantly improve the strategy’s risk-reward ratio.
Time Filtering: Add trading time window filters to avoid high-volatility periods such as market opening, closing, or important economic data releases, reducing false signals caused by abnormal fluctuations.
Trend Strength Filtering: Utilize the already calculated upward/downward trend counts to set minimum trend strength thresholds, generating trading signals only when trends are strong enough, avoiding excessive trading in weak trend or range-bound markets.
Machine Learning Optimization: Consider introducing machine learning algorithms to train models through historical data, optimizing parameter selection or improving signal identification accuracy. For example, random forests or support vector machines could be used to predict signal reliability.
Implementing these optimization directions can significantly enhance the strategy’s stability and profitability, enabling it to maintain good performance across different market environments.
The Advanced Dynamic Trend Range Filtering Quantitative Trading Strategy is a trend-following system based on dynamic price ranges, constructing a flexible trend identification mechanism through dual timeframe adaptive range calculations. The core advantages of this strategy lie in its powerful adaptability and noise filtering capabilities, effectively identifying trend changes and generating trading signals under various market conditions.
The strategy establishes dynamic trend range boundaries by calculating smoothed ranges for fast and slow time periods, combined with a unique range filtering algorithm. When prices cross these boundaries, the system automatically generates buy or sell signals, helping traders capture trend reversal points. Meanwhile, the strategy’s chart visualization features allow traders to intuitively identify market trends and potential trading opportunities.
Despite its many advantages, the strategy also faces risks such as parameter sensitivity, lag, and false breakouts. By introducing multiple confirmation mechanisms, dynamic parameter adjustments, enhanced risk management, and other optimization measures, the strategy’s stability and profitability can be further improved.
Overall, this is a well-designed and thoroughly implemented quantitative trading strategy, suitable for experienced traders to apply in actual trading after comprehensive backtesting and parameter optimization. For traders pursuing trend following and dynamic adaptation to market changes, this strategy represents a worthy consideration.
/*backtest
start: 2025-01-01 00:00:00
end: 2025-06-12 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"ETH_USDT"}]
*/
//@version=5
strategy("L3 Twin Range Filter Pro Strategy", overlay=true)
// 输入参数
price_source = input(defval=close, title='Price Source')
show_trade_signals = input(title='Show Buy/Sell Signals ?', defval=true)
fast_period = input.int(defval=9, minval=1, title='Fast period')
fast_range_multiplier = input.float(defval=1.6, minval=0.1, title='Fast range multiplier')
slow_period = input.int(defval=34, minval=1, title='Slow period')
slow_range_multiplier = input.float(defval=2, minval=0.1, title='Slow range multiplier')
// 自定义函数
calculate_smooth_range(price, period, multiplier) =>
window_period = period * 2 - 1
average_range = ta.ema(math.abs(price - price[1]), period)
smooth_range = ta.ema(average_range, window_period) * multiplier
smooth_range
apply_range_filter(price, range_value) =>
range_filtered_price = price
range_filtered_price := price > nz(range_filtered_price[1]) ? price - range_value < nz(range_filtered_price[1]) ? nz(range_filtered_price[1]) : price - range_value : price + range_value > nz(range_filtered_price[1]) ? nz(range_filtered_price[1]) : price + range_value
range_filtered_price
// 计算过程
fast_smooth_range = calculate_smooth_range(price_source, fast_period, fast_range_multiplier)
slow_smooth_range = calculate_smooth_range(price_source, slow_period, slow_range_multiplier)
average_smooth_range = (fast_smooth_range + slow_smooth_range) / 2
filtered_price = apply_range_filter(price_source, average_smooth_range)
upward_trend = 0.0
upward_trend := filtered_price > filtered_price[1] ? nz(upward_trend[1]) + 1 : filtered_price < filtered_price[1] ? 0 : nz(upward_trend[1])
downward_trend = 0.0
downward_trend := filtered_price < filtered_price[1] ? nz(downward_trend[1]) + 1 : filtered_price > filtered_price[1] ? 0 : nz(downward_trend[1])
upper_range_boundary = filtered_price + average_smooth_range
lower_range_boundary = filtered_price - average_smooth_range
upper_bound = 0.0
upper_bound := upper_range_boundary < nz(upper_bound[1]) or close[1] > nz(upper_bound[1]) ? upper_range_boundary : nz(upper_bound[1])
lower_bound = 0.0
lower_bound := lower_range_boundary > nz(lower_bound[1]) or close[1] < nz(lower_bound[1]) ? lower_range_boundary : nz(lower_bound[1])
trend_range_filter = 0.0
trend_range_filter := nz(trend_range_filter[1]) == upper_bound[1] and close <= upper_bound ? upper_bound : nz(trend_range_filter[1]) == upper_bound[1] and close >= upper_bound ? lower_bound : nz(trend_range_filter[1]) == lower_bound[1] and close >= lower_bound ? lower_bound : nz(trend_range_filter[1]) == lower_bound[1] and close <= lower_bound ? upper_bound : upper_bound
// 定义交易信号
buy_signal = ta.crossover(close, trend_range_filter)
sell_signal = ta.crossunder(close, trend_range_filter)
// 执行交易
if (buy_signal)
strategy.entry("Buy", strategy.long)
if (sell_signal)
strategy.entry("Sell", strategy.short)
// 绘制标签
if (show_trade_signals and buy_signal)
label.new(bar_index, trend_range_filter, "BUY", color=color.new(color.green, 0), style=label.style_label_up)
if (show_trade_signals and sell_signal)
label.new(bar_index, trend_range_filter, "SELL", color=color.new(color.red, 0), style=label.style_label_down)
// 绘制图表元素
trend_range_filter_plot = plot(trend_range_filter, color=close > trend_range_filter ? color.new(color.lime, 10) : close < trend_range_filter ? color.new(color.red, 10) : na, title="Trend Range Filter")
price_plot = plot(ohlc4, title='', style=plot.style_circles, linewidth=0)
up_trend_color = close > trend_range_filter ? color.new(color.lime, 80) : na
down_trend_color = close < trend_range_filter ? color.new(color.red, 80) : na
fill(price_plot, trend_range_filter_plot, title='UpTrend Highlighter', color=up_trend_color, transp=90)
fill(price_plot, trend_range_filter_plot, title='DownTrend Highlighter', color=down_trend_color, transp=90)