Multi-Timeframe Stochastic RSI Cross Confirmation Strategy with Volatility Filtering System

RSI ATR SRSI MTF
Created on: 2025-06-04 10:31:03 Modified on: 2025-06-04 10:31:03
Copy: 0 Number of hits: 274
avatar of ianzeng123 ianzeng123
2
Follow
319
Followers

 Multi-Timeframe Stochastic RSI Cross Confirmation Strategy with Volatility Filtering System  Multi-Timeframe Stochastic RSI Cross Confirmation Strategy with Volatility Filtering System

Overview

The Multi-Timeframe Stochastic RSI Cross Confirmation Strategy with Volatility Filtering System is a comprehensive trading system that cleverly combines the signal crossing characteristics of the Stochastic Relative Strength Index (Stochastic RSI) across different timeframes, supplemented with an Average True Range (ATR) filter to ensure sufficient market volatility. The core idea of this strategy is to capture initial signals through a short timeframe (5-minute) and then use a longer timeframe (15-minute) for confirmation, thereby improving the reliability and accuracy of trading signals. Additionally, the strategy incorporates a signal cooldown mechanism to prevent frequent trading within a short period, effectively reducing the risk of overtrading.

Strategy Principles

This strategy operates based on four core mechanisms: initial signal triggering, multi-timeframe confirmation, volatility filtering, and signal cooldown system.

  1. Initial Signal Triggering Mechanism:

    • On the 5-minute chart, when the Stochastic RSI %K line crosses above the %D line and the %K value at that time is below a preset oversold level (default: 30), the system enters a long signal waiting state.
    • When the Stochastic RSI %K line crosses below the %D line and the %K value at that time is above a preset overbought level (default: 70), the system enters a short signal waiting state.
  2. Multi-Timeframe Confirmation Mechanism:

    • Once the system is in a signal waiting state, it seeks confirmation from the 15-minute timeframe within a preset waiting window (default: 5 bars of 5-minute candles).
    • Long confirmation conditions: The 15-minute Stochastic RSI %K line value is greater than or equal to the %D line value, and the %K value is below a preset threshold (default: 40).
    • Short confirmation conditions: The 15-minute Stochastic RSI %K line value is less than or equal to the %D line value, and the %K value is above a preset threshold (default: 60).
  3. ATR Volatility Filtering Mechanism:

    • The system calculates the current ATR value and converts it to minimum tick points.
    • Trade signals are only executed when the current ATR value exceeds a user-defined minimum threshold (default: 10 tick points).
    • This mechanism ensures that trading only occurs when the market has sufficient volatility, avoiding false signals caused by minor price movements in low-volatility markets.
  4. Signal Cooldown System:

    • Once a trading signal is generated, the system forces a wait for a preset minimum number of candles (default: 18 candles) before allowing new signals in the same direction.
    • This mechanism effectively prevents the system from generating too many signals in the same direction within a short period, reducing the risk of overtrading.

The strategy manages positions through signal reversal, meaning that when a long signal appears, it will close any existing short position and establish a long position; when a short signal appears, it will close any existing long position and establish a short position.

Strategy Advantages

  1. Multi-Level Filtering System: By combining signal confirmation across different timeframes and ATR volatility filtering, the system significantly reduces false signals and improves trading quality. The multi-level verification mechanism ensures entry only under the most favorable market conditions, reducing unnecessary trading frequency.

  2. Strong Adaptability: The strategy parameters are highly customizable, including RSI period, stochastic indicator smoothing values, signal triggering thresholds, etc., allowing traders to optimize adjustments based on different market environments and personal risk preferences.

  3. Volatility Awareness: Through the ATR filter, the strategy can intelligently identify market volatility states and only trade under conditions of sufficient volatility, avoiding ineffective signals generated by minor fluctuations in ranging markets.

  4. Overtrading Protection: The signal cooldown mechanism is an innovative design that limits the frequency of trades in the same direction through mandatory waiting periods, effectively preventing the system from generating too many trades in a short time, reducing commission costs and slippage losses.

  5. Clear and Transparent Logic: Each component of the strategy has a clear function and purpose, with no complex black-box algorithms, allowing traders to fully understand how the system works, enhancing confidence in operations.

Strategy Risks

  1. Signal Lag: The multi-level confirmation mechanism, while improving signal quality, inevitably increases signal lag. Especially in rapidly changing markets, waiting for 15-minute timeframe confirmation may cause missing the optimal entry point or entering at unfavorable positions.

  2. Parameter Sensitivity: The effectiveness of this strategy is highly dependent on parameter settings, such as Stochastic RSI periods, overbought/oversold thresholds, confirmation waiting windows, etc. Inappropriate parameter settings may lead to missing valid signals or generating too many false signals.

  3. Lack of Explicit Stop-Loss Mechanism: The strategy primarily relies on reverse signals to manage risk, without explicit stop-loss strategies. In extreme market conditions, such as large gaps or rapid one-way moves, this may result in significant losses.

  4. Interperiod Influence: In multi-timeframe strategies, indicators of various time periods influence each other, sometimes forming complex relationships. For example, under certain market conditions, the 5-minute and 15-minute Stochastic RSI may maintain a consistent direction for extended periods, causing the system to miss reversal signals.

  5. ATR Threshold Setting Challenge: Setting the ATR filter threshold presents a dilemma: setting it too high will miss effective trading opportunities, while setting it too low will fail to effectively filter out false signals in low-volatility environments.

Strategy Optimization Directions

  1. Dynamic Stop-Loss and Take-Profit Mechanism:

    • Design dynamic stop-loss levels based on ATR or other volatility indicators, allowing risk control to adaptively adjust with market volatility.
    • Implementation method: Add strategy.exit() commands, setting stop-loss based on ATR multiples, such as strategy.exit("long_exit", "LE", stop=entry_price - current_atr_value * 2).
  2. Add Trend Filter:

    • Incorporate trend indicators from longer time periods (such as 1-hour or 4-hour), like moving averages or MACD, to ensure that trading direction aligns with the main trend.
    • Implementation method: Add code to obtain trend indicators from higher time levels, such as trend_direction = request.security(syminfo.tickerid, "240", ta.ema(close, 200) < ta.ema(close, 50) ? -1 : 1), and use it as a filtering condition for trading direction.
  3. Dynamic Parameter Optimization:

    • Automatically adjust strategy parameters based on market volatility or trading sessions, allowing the system to better adapt to different market states.
    • Implementation method: Write functions to dynamically adjust overbought/oversold thresholds based on current ATR value or market volatility state, such as dynamic_overbought = 70 + math.min(15, current_atr_value / 2).
  4. Enhanced Signal Confirmation Mechanism:

    • Introduce other indicators such as Bollinger Bands, volume, or price patterns as additional confirmation conditions beyond Stochastic RSI.
    • Implementation method: Add Bollinger Band deviation detection code, such as bb_condition = (close - ta.sma(close, 20)) / (ta.stdev(close, 20) * 2), to evaluate the degree of price deviation from the mean.
  5. Money Management Optimization:

    • Implement dynamic position management, adjusting risk exposure for each trade based on current trend strength, market volatility, and historical win rate.
    • Implementation method: Add code to calculate dynamic position size based on the win rate of recent N trades, such as position_size = strategy.initial_capital * 0.01 * (recent_win_rate * 2).

Conclusion

The Multi-Timeframe Stochastic RSI Cross Confirmation Strategy with Volatility Filtering System is an elegantly designed trading system that effectively improves trading quality and reduces the risk of false signals through multi-level signal confirmation and filtering mechanisms. This strategy is particularly suitable for markets with higher volatility, using the ATR filter to avoid generating too many ineffective signals in low-volatility markets, while the signal cooldown mechanism effectively controls the problem of overtrading.

The greatest advantage of this strategy lies in its clear logic, adjustable parameters, and strong adaptability, enabling it to adapt to different trading instruments and market environments. However, due to the lack of explicit stop-loss mechanisms and potential signal lag, traders should add additional risk management measures in practical applications and optimize parameters according to specific trading instruments and personal risk preferences.

By introducing the suggested optimization measures, such as dynamic stop-loss mechanisms, trend filters, and money management optimization, this strategy has the potential to further enhance its stability and profitability, becoming a more comprehensive and reliable trading system.

Strategy source code
/*backtest
start: 2025-05-04 00:00:00
end: 2025-06-03 00:00:00
period: 2h
basePeriod: 2h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Archertoria

//@version=6
strategy("System 0530 - Stoch RSI Strategy with ATR filter")
// --- 原始指标输入参数 ---
g_stoch = "Stochastic RSI 参数"
rsi_len = input.int(14, "RSI 周期", minval=1, group=g_stoch)
stoch_rsi_len = input.int(14, "Stochastic of RSI 周期 (K Period for Stoch)", minval=1, group=g_stoch)
stoch_k_smooth = input.int(3, "Stochastic %K 平滑 (D Period for Stoch)", minval=1, group=g_stoch)
stoch_d_smooth = input.int(3, "Stochastic %D 平滑 (Smoothing for final D)", minval=1, group=g_stoch)

g_signal = "信号触发与确认参数"
stoch_5min_k_long_trigger = input.float(30.0, "5分钟 Stoch K 做多触发水平 (K需 ≤ 此值)", minval=0, maxval=100, step=0.1, group=g_signal, tooltip="5分钟图上,K线向上交叉D线时,当时的K值必须小于或等于此设定值,才会启动做多信号等待。")
stoch_5min_k_short_trigger = input.float(70.0, "5分钟 Stoch K 做空触发水平 (K需 ≥ 此值)", minval=0, maxval=100, step=0.1, group=g_signal, tooltip="5分钟图上,K线向下交叉D线时,当时的K值必须大于或等于此设定值,才会启动做空信号等待。")
stoch_15min_long_entry_level = input.int(40, "15分钟 Stoch K 做多确认阈值 (K需低于此值)", minval=0, maxval=100, group=g_signal, tooltip="15分钟图上,最终确认做多时,15分钟K线值需低于此设定值。")
stoch_15min_short_entry_level = input.int(60, "15分钟 Stoch K 做空确认阈值 (K需高于此值)", minval=0, maxval=100, group=g_signal, tooltip="15分钟图上,最终确认做空时,15分钟K线值需高于此设定值。")
wait_window_5min_bars = input.int(5, "等待15分钟信号的K线数 (5分钟图)", minval=1, group=g_signal, tooltip="5分钟信号发出后,在接下来的N根5分钟K线内等待15分钟信号确认。")

g_repeat_filter = "重复信号过滤设置"
use_signal_cooldown_filter = input.bool(true, title="启用重复信号过滤器", group=g_repeat_filter, tooltip="过滤掉短时间内同向的重复信号。")
min_bars_between_signals = input.int(18, title="同向信号最小间隔K线数", minval=1, group=g_repeat_filter, tooltip="一个信号发出后,至少等待这么多根K线才会发出下一个同向信号。")

// --- 策略特定输入参数 ---
g_strategy = "策略参数"
leverage_multiplier = input.float(1.0, "杠杆倍数 (仅影响理论头寸大小)", minval=1.0, step=0.1, group=g_strategy, tooltip="注意:TradingView策略本身不直接模拟保证金账户的杠杆爆仓。此杠杆用于计算理论头寸大小。实际杠杆效果需在支持杠杆的经纪商处体现。")

// --- ATR波动率过滤器参数 --- (止盈止损参数组已删除)
g_volatility = "波动率过滤器参数 (ATR)"
use_atr_filter = input.bool(true, "启用ATR波动率过滤器", group=g_volatility, tooltip="勾选以启用ATR过滤器。")
atr_period = input.int(14, "ATR计算周期", minval=1, group=g_volatility)
min_atr_value_ticks = input.float(10, "ATR最小跳动点数阈值", minval=0, step=1, group=g_volatility, tooltip="ATR值(以合约最小跳动点数为单位)必须大于等于此阈值才允许开仓。例如,如果最小跳动点是0.1,这里填10,则要求ATR至少为1.0。0表示不基于此项过滤。")

// --- 函数: 计算 Stochastic RSI ---
getStochasticRSI(src, rsiLen, stochLen, kSmooth, dSmooth) =>
    rsi_val = ta.rsi(src, rsiLen)
    stoch_rsi_k_raw = ta.stoch(rsi_val, rsi_val, rsi_val, stochLen)
    stoch_rsi_k = ta.sma(stoch_rsi_k_raw, kSmooth)
    stoch_rsi_d = ta.sma(stoch_rsi_k, dSmooth)
    [stoch_rsi_k, stoch_rsi_d]

// --- 时间序列数据获取与Stochastic RSI计算 ---
[stoch_k_15min_val, stoch_d_15min_val] = request.security(syminfo.tickerid, "15", getStochasticRSI(close, rsi_len, stoch_rsi_len, stoch_k_smooth, stoch_d_smooth), lookahead=barmerge.lookahead_off)
[stoch_k_5min_val, stoch_d_5min_val] = getStochasticRSI(close, rsi_len, stoch_rsi_len, stoch_k_smooth, stoch_d_smooth)

// --- ATR 计算 ---
current_atr_value = ta.atr(atr_period)
atr_condition_met = not use_atr_filter or (min_atr_value_ticks == 0) or (current_atr_value / syminfo.mintick >= min_atr_value_ticks)

// --- 信号逻辑状态变量 ---
var bool waiting_for_15m_long_confirm = false
var bool waiting_for_15m_short_confirm = false
var int bars_elapsed_in_wait_state = 0
var int last_long_signal_bar_idx = -min_bars_between_signals
var int last_short_signal_bar_idx = -min_bars_between_signals

// --- 检测5分钟Stochastic RSI交叉事件 ---
bool stoch_5min_crossed_up_prev_bar = ta.crossover(stoch_k_5min_val[1], stoch_d_5min_val[1])
bool stoch_5min_crossed_down_prev_bar = ta.crossunder(stoch_k_5min_val[1], stoch_d_5min_val[1])
bool condition_5min_k_level_for_long_trigger = stoch_k_5min_val[1] <= stoch_5min_k_long_trigger
bool condition_5min_k_level_for_short_trigger = stoch_k_5min_val[1] >= stoch_5min_k_short_trigger

// --- 管理等待状态和容错期 ---
if (stoch_5min_crossed_up_prev_bar and condition_5min_k_level_for_long_trigger)
    can_trigger_new_long = not use_signal_cooldown_filter or (bar_index - last_long_signal_bar_idx >= min_bars_between_signals)
    if (can_trigger_new_long)
        waiting_for_15m_long_confirm := true
        waiting_for_15m_short_confirm := false
        bars_elapsed_in_wait_state := 1
    else 
        if (waiting_for_15m_long_confirm or waiting_for_15m_short_confirm) 
            bars_elapsed_in_wait_state := 1 
else if (stoch_5min_crossed_down_prev_bar and condition_5min_k_level_for_short_trigger)
    can_trigger_new_short = not use_signal_cooldown_filter or (bar_index - last_short_signal_bar_idx >= min_bars_between_signals)
    if (can_trigger_new_short)
        waiting_for_15m_short_confirm := true
        waiting_for_15m_long_confirm := false
        bars_elapsed_in_wait_state := 1
    else 
        if (waiting_for_15m_long_confirm or waiting_for_15m_short_confirm) 
            bars_elapsed_in_wait_state := 1
else if (waiting_for_15m_long_confirm or waiting_for_15m_short_confirm)
    bars_elapsed_in_wait_state += 1

if (bars_elapsed_in_wait_state > wait_window_5min_bars)
    waiting_for_15m_long_confirm := false
    waiting_for_15m_short_confirm := false
    // bars_elapsed_in_wait_state := 0 // Optional reset

// --- 15分钟Stochastic RSI确认条件 ---
bool confirm_15min_long_stoch_kd_cond = stoch_k_15min_val >= stoch_d_15min_val
bool confirm_15min_short_stoch_kd_cond = stoch_k_15min_val <= stoch_d_15min_val
bool filter_15min_stoch_level_long = stoch_k_15min_val < stoch_15min_long_entry_level
bool filter_15min_stoch_level_short = stoch_k_15min_val > stoch_15min_short_entry_level

// --- 主要信号判断 (用于策略逻辑) ---
entry_long_signal = false
entry_short_signal = false

if (waiting_for_15m_long_confirm and bars_elapsed_in_wait_state <= wait_window_5min_bars)
    if (confirm_15min_long_stoch_kd_cond and filter_15min_stoch_level_long)
        can_confirm_new_long = not use_signal_cooldown_filter or (bar_index - last_long_signal_bar_idx >= min_bars_between_signals)
        if (can_confirm_new_long)
            if (atr_condition_met) // ATR 过滤器检查
                entry_long_signal := true
                last_long_signal_bar_idx := bar_index
                waiting_for_15m_long_confirm := false
                bars_elapsed_in_wait_state := 0
        else 
            waiting_for_15m_long_confirm := false 
            bars_elapsed_in_wait_state := 0
if (waiting_for_15m_short_confirm and bars_elapsed_in_wait_state <= wait_window_5min_bars)
    if (confirm_15min_short_stoch_kd_cond and filter_15min_stoch_level_short)
        can_confirm_new_short = not use_signal_cooldown_filter or (bar_index - last_short_signal_bar_idx >= min_bars_between_signals)
        if (can_confirm_new_short)
            if (atr_condition_met) // ATR 过滤器检查
                entry_short_signal := true
                last_short_signal_bar_idx := bar_index
                waiting_for_15m_short_confirm := false
                bars_elapsed_in_wait_state := 0
        else 
            waiting_for_15m_short_confirm := false 
            bars_elapsed_in_wait_state := 0

// --- 策略执行逻辑 ---

if (entry_long_signal)
    strategy.entry("LE", strategy.long, comment="long entry")

if (entry_short_signal)
    strategy.entry("SE", strategy.short, comment="short entry")

// --- 绘图 ---
plotshape(entry_long_signal, title="做多信号点", location=location.belowbar, color=color.new(color.green,0), style=shape.triangleup, size=size.small)
plotshape(entry_short_signal, title="做空信号点", location=location.abovebar, color=color.new(color.red,0), style=shape.triangledown, size=size.small)