多重时序趋势甄别型自适应动态调仓策略

DEMA ATR supertrend
创建日期: 2025-02-24 09:48:55 最后修改: 2025-02-27 16:49:07
复制: 3 点击次数: 110
avatar of ianzeng123 ianzeng123
2
关注
52
关注者

多重时序趋势甄别型自适应动态调仓策略 多重时序趋势甄别型自适应动态调仓策略

概述

本策略是一个基于Supertrend和双重指数移动平均线(DEMA)的趋势跟踪交易系统。该策略通过结合Supertrend指标的趋势方向识别能力和DEMA的趋势确认功能,构建了一个可靠的交易决策框架。系统支持双向交易,并具备仓位动态调整机制,可根据市场环境灵活切换多空方向。

策略原理

策略的核心逻辑基于以下几个关键组件: 1. Supertrend指标:利用ATR周期设置为10,因子值为3.0,用于捕捉价格趋势的转折点。 2. DEMA指标:采用100周期的双重指数移动平均线,用于过滤市场噪音和确认趋势的可靠性。 3. 交易信号生成机制: - 多头信号:当价格上穿Supertrend且收盘价位于DEMA之上时触发 - 空头信号:当价格下穿Supertrend且收盘价位于DEMA之下时触发 4. 仓位管理:系统支持灵活的仓位调整,包括直接开仓、反手和平仓操作。

策略优势

  1. 多重确认机制:通过组合Supertrend和DEMA两个指标,显著提高了交易信号的可靠性。
  2. 灵活的仓位管理:支持多空双向交易,可根据市场情况动态调整持仓方向。
  3. 风险控制完善:在趋势转折点具有快速响应机制,能及时止损并把握新趋势机会。
  4. 参数可调性强:关键参数如ATR周期、Supertrend因子和DEMA周期均可根据不同市场特征进行优化。

策略风险

  1. 横盘市场表现欠佳:在无明显趋势的市场环境下,可能产生频繁的假突破信号。
  2. 滞后性风险:使用DEMA作为过滤器可能导致入场时机略有延迟,影响部分盈利空间。
  3. 参数敏感性:策略效果对参数设置较为敏感,不同市场环境可能需要不同的参数组合。

策略优化方向

  1. 引入波动率自适应机制:
    • 根据市场波动率动态调整Supertrend因子值
    • 在高波动期间提高过滤门槛,低波动期间适当放宽条件
  2. 增加市场环境识别模块:
    • 添加趋势强度指标,在横盘市场降低交易频率
    • 引入成交量指标辅助确认突破有效性
  3. 完善止损机制:
    • 实现基于ATR的动态止损
    • 添加移动止损功能以保护盈利

总结

该策略通过巧妙结合Supertrend和DEMA指标,构建了一个稳健的趋势跟踪系统。其优势在于信号可靠性高、风险控制完善,但仍需要交易者根据具体市场特征进行参数优化。通过提出的优化方向,策略的适应性和稳定性有望得到进一步提升。

策略源码
/*backtest
start: 2025-02-16 00:00:00
end: 2025-02-23 00:00:00
period: 5m
basePeriod: 5m
exchanges: [{"eid":"Binance","currency":"SOL_USDT"}]
*/

//@version=6
strategy("Supertrend with DEMA Strategy (Reversal Enabled)", overlay=true)

// ===== Parameters for Supertrend =====
atrPeriod = input.int(10, "ATR Length", minval=1)
factor    = input.float(3.0, "Factor", minval=0.01, step=0.01)

// ===== Parameters for Allowing Trade Directions =====
allowLong  = input.bool(true,  "Allow LONG")
allowShort = input.bool(true,  "Allow SHORT")

// Supertrend Calculation
[supertrend, direction] = ta.supertrend(factor, atrPeriod)
// Set the value to na for the first bar to avoid false signals
supertrend := barstate.isfirst ? na : supertrend

// Plot Supertrend Lines
plot(direction < 0 ? supertrend : na, "Up Trend",   color=color.green, style=plot.style_linebr)
plot(direction < 0 ? na : supertrend, "Down Trend", color=color.red,   style=plot.style_linebr)

// ===== Parameters and Calculation for DEMA =====
demaLength = input.int(100, "DEMA Length", minval=1)
e1 = ta.ema(close, demaLength)
e2 = ta.ema(e1, demaLength)
dema = 2 * e1 - e2

// Plot DEMA
plot(dema, "DEMA", color=#43A047)

// ===== Signal Definitions =====
// Basic Supertrend Trend Change Signals
trendUp   = ta.crossover(close, supertrend)
trendDown = ta.crossunder(close, supertrend)

// Entry Signals considering DEMA
longSignal  = trendUp and (close > dema)
shortSignal = trendDown and (close < dema)

// ===== Entry/Exit Logic =====

// LONG Signal
if (longSignal)
    // If there is an open SHORT position – reverse it to LONG if allowed
    if (strategy.position_size < 0)
        if (allowLong)
            strategy.close("Short")
            strategy.entry("Long", strategy.long)
        else
            // If reversal to LONG is not allowed – just close SHORT
            strategy.close("Short")
    // If there is no position – open LONG if allowed
    else if (strategy.position_size == 0)
        if (allowLong)
            strategy.entry("Long", strategy.long)

// SHORT Signal
if (shortSignal)
    // If there is an open LONG position – reverse it to SHORT if allowed
    if (strategy.position_size > 0)
        if (allowShort)
            strategy.close("Long")
            strategy.entry("Short", strategy.short)
        else
            // If reversal to SHORT is not allowed – just close LONG
            strategy.close("Long")
    // If there is no position – open SHORT if allowed
    else if (strategy.position_size == 0)
        if (allowShort)
            strategy.entry("Short", strategy.short)

// ===== Additional Position Closure on Trend Change without Entry =====
// If Supertrend crosses (trend change) but DEMA conditions are not met,
// close the opposite position if open.
if (trendUp and not longSignal and strategy.position_size < 0)
    strategy.close("Short")

if (trendDown and not shortSignal and strategy.position_size > 0)
    strategy.close("Long")

相关推荐