多重平滑均线动态交叉趋势跟踪与多重确认量化交易策略

MA EMA RSI ATR SMA RMA WMA SL TP
创建日期: 2025-01-17 15:53:16 最后修改: 2025-01-17 15:53:16
复制: 1 点击次数: 171
avatar of ChaoZhang ChaoZhang
1
关注
1259
关注者

多重平滑均线动态交叉趋势跟踪与多重确认量化交易策略

概述

该策略是一个基于多重平滑移动平均线的趋势跟踪系统,通过三重平滑处理来过滤市场噪音,同时结合RSI动量指标、ATR波动率指标和200周期EMA趋势过滤器来确认交易信号。策略采用1小时时间周期,这个时间框架能够有效平衡交易频率和趋势可靠性,同时与机构交易行为相匹配。

策略原理

策略的核心是通过对价格进行三次平滑处理来构建主要趋势线,并使用较短周期的信号线与之交叉产生交易信号。交易信号需要同时满足以下条件才会执行: 1. 价格位置与200EMA的关系确认主趋势方向 2. RSI指标位置确认动量 3. ATR指标确认足够的波动性 4. 信号线与三重平滑均线的交叉确认具体入场点 止损采用基于ATR的动态止损,止盈采用2倍ATR设置,确保良好的风险收益比。

策略优势

  1. 三重平滑处理显著降低了虚假信号,提高了趋势判断的可靠性
  2. 多重确认机制确保交易方向与主要趋势保持一致
  3. 动态的止损和止盈设置适应不同的市场波动环境
  4. 策略在1小时周期上运行,能够有效避免更低时间周期的震荡
  5. 无重绘特性保证了回测结果的可靠性

策略风险

  1. 在横盘市场可能产生连续的小幅亏损
  2. 多重确认机制可能导致错过一些交易机会
  3. 信号滞后性可能影响入场点位的优化程度
  4. 需要足够的波动率才能产生有效信号
  5. 在极端市场环境下动态止损可能不够及时

策略优化方向

  1. 可以增加成交量指标作为辅助确认
  2. 考虑引入自适应的参数优化机制
  3. 可以增加趋势强度的量化判断
  4. 优化止损止盈的倍数设置
  5. 考虑加入震荡指标以优化横盘市场表现

总结

这是一个结构完整、逻辑严密的趋势跟踪策略。通过多重平滑处理和多重确认机制,有效地提高了交易信号的可靠性。动态的风险管理机制使其具有良好的适应性。虽然存在一定的滞后性,但通过参数优化和增加辅助指标,策略仍有较大的改进空间。

策略源码
/*backtest
start: 2024-12-17 00:00:00
end: 2025-01-16 00:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT","balance":49999}]
*/

//@version=6
strategy("Optimized Triple Smoothed MA Crossover Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=200)

// === Input Settings ===
slength = input.int(7, "Main Smoothing Length", group="Moving Average Settings")
siglen = input.int(12, "Signal Length", group="Moving Average Settings")
src = input.source(close, "Data Source", group="Moving Average Settings")
mat = input.string("EMA", "Triple Smoothed MA Type", ["EMA", "SMA", "RMA", "WMA"], group="Moving Average Settings")
mat1 = input.string("EMA", "Signal Type", ["EMA", "SMA", "RMA", "WMA"], group="Moving Average Settings")

// === Trend Confirmation (Higher Timeframe Filter) ===
useTrendFilter = input.bool(true, "Enable Trend Filter (200 EMA)", group="Trend Confirmation")
trendMA = ta.ema(close, 200)

// === Momentum Filter (RSI Confirmation) ===
useRSIFilter = input.bool(true, "Enable RSI Confirmation", group="Momentum Confirmation")
rsi = ta.rsi(close, 14)
rsiThreshold = input.int(50, "RSI Threshold", group="Momentum Confirmation")

// === Volatility Filter (ATR) ===
useATRFilter = input.bool(true, "Enable ATR Filter", group="Volatility Filtering")
atr = ta.atr(14)
atrMa = ta.sma(atr, 14)

// === Risk Management (ATR-Based Stop Loss) ===
useAdaptiveSL = input.bool(true, "Use ATR-Based Stop Loss", group="Risk Management")
atrMultiplier = input.float(1.5, "ATR Multiplier for SL", minval=0.5, maxval=5, group="Risk Management")
takeProfitMultiplier = input.float(2, "Take Profit Multiplier", group="Risk Management")

// === Moving Average Function ===
ma(source, length, MAtype) =>
    switch MAtype
        "SMA" => ta.sma(source, length)
        "EMA" => ta.ema(source, length)
        "RMA" => ta.rma(source, length)
        "WMA" => ta.wma(source, length)

// === Triple Smoothed Calculation ===
tripleSmoothedMA = ma(ma(ma(src, slength, mat), slength, mat), slength, mat)
signalLine = ma(tripleSmoothedMA, siglen, mat1)

// === Crossovers (Entry Signals) ===
bullishCrossover = ta.crossunder(signalLine, tripleSmoothedMA)
bearishCrossover = ta.crossover(signalLine, tripleSmoothedMA)

// === Additional Confirmation Conditions ===
trendLongCondition = not useTrendFilter or (close > trendMA)  // Only long if price is above 200 EMA
trendShortCondition = not useTrendFilter or (close < trendMA) // Only short if price is below 200 EMA

rsiLongCondition = not useRSIFilter or (rsi > rsiThreshold)  // RSI above 50 for longs
rsiShortCondition = not useRSIFilter or (rsi < rsiThreshold) // RSI below 50 for shorts

atrCondition = not useATRFilter or (atr > atrMa)  // ATR must be above its MA for volatility confirmation

// === Final Trade Entry Conditions ===
longCondition = bullishCrossover and trendLongCondition and rsiLongCondition and atrCondition
shortCondition = bearishCrossover and trendShortCondition and rsiShortCondition and atrCondition

// === ATR-Based Stop Loss & Take Profit ===
longSL = close - (atr * atrMultiplier)
longTP = close + (atr * takeProfitMultiplier)

shortSL = close + (atr * atrMultiplier)
shortTP = close - (atr * takeProfitMultiplier)

// === Strategy Execution ===
if longCondition
    strategy.entry("Long", strategy.long)
    strategy.exit("Long Exit", from_entry="Long", stop=longSL, limit=longTP)

if shortCondition
    strategy.entry("Short", strategy.short)
    strategy.exit("Short Exit", from_entry="Short", stop=shortSL, limit=shortTP)

// === Plots ===
plot(tripleSmoothedMA, title="Triple Smoothed MA", color=color.blue)
plot(signalLine, title="Signal Line", color=color.red)
plot(trendMA, title="200 EMA", color=color.gray)

// === Alerts ===
alertcondition(longCondition, title="Bullish Signal", message="Triple Smoothed MA Bullish Crossover Confirmed")
alertcondition(shortCondition, title="Bearish Signal", message="Triple Smoothed MA Bearish Crossover Confirmed")
相关推荐