动态趋势确认的反转公平价值缺口量化交易策略


创建日期: 2025-06-25 16:35:59 最后修改: 2025-07-03 14:59:28
复制: 0 点击次数: 2
avatar of ianzeng123 ianzeng123
1
关注
123
关注者

动态趋势确认的反转公平价值缺口量化交易策略 动态趋势确认的反转公平价值缺口量化交易策略

策略概述

本策略是一种基于反向公平价值缺口(Inverted Fair Value Gap, IFVG)的交易系统,结合了趋势确认和动态跟踪止损机制。该策略首先识别市场中的公平价值缺口(Fair Value Gap, FVG),然后寻找这些缺口的反转信号,同时使用简单移动平均线(SMA)确认整体市场趋势,最后通过平均真实波幅(ATR)设置动态跟踪止损以优化风险管理。这种多重确认机制旨在提高交易信号的可靠性,同时通过动态止损保护已获利润。

策略原理

该策略的核心是识别和利用公平价值缺口(FVG)的反转。策略原理可分为以下几个关键步骤:

  1. FVG识别: 策略首先检测公平价值缺口,即当某个K线的最低价高于前一K线的最高价(看涨FVG)或某个K线的最高价低于前一K线的最低价(看跌FVG)时形成的价格区域。这些区域代表市场快速移动时未被交易的价格水平。

  2. IFVG确认: 当价格回到FVG区域并出现反转信号时,形成反向公平价值缺口(IFVG)。具体来说,当价格高于看涨FVG的高点且收盘价高于开盘价,或价格低于看跌FVG的低点且收盘价低于开盘价时,IFVG被确认。

  3. 趋势确认: 策略使用50周期和200周期的简单移动平均线(SMA)来确定市场趋势。当短期SMA(50周期)高于长期SMA(200周期)时,确认上升趋势;反之则确认下降趋势。

  4. 入场条件:

    • 做多条件: 当IFVG形成,价格低于IFVG低点,且市场处于上升趋势时
    • 做空条件: 当IFVG形成,价格高于IFVG高点,且市场处于下降趋势时
  5. 风险管理:

    • 初始止损设置为入场价格的0.5%
    • 止盈目标设置为入场价格的1.5%
    • 当利润达到止盈目标的一半(0.75%)时,启动动态跟踪止损
    • 跟踪止损基于ATR(14)动态调整,确保在市场波动加剧时提供更大的价格缓冲

策略优势

  1. 多重确认机制: 该策略结合了价格结构(IFVG)、趋势方向(SMA)和动态风险管理(ATR),形成多层过滤系统,显著减少了假信号。

  2. 市场结构驱动: 通过识别FVG和IFVG,策略能够捕捉市场微观结构变化,这些变化通常代表短期买卖力量的失衡和可能的方向性机会。

  3. 趋势一致性: 通过SMA交叉确认整体趋势方向,策略只在趋势方向上交易,避免了逆势交易的高风险。

  4. 动态风险管理: 策略不仅设置了固定的止损和止盈水平,还实现了基于ATR的动态跟踪止损,能够根据市场波动性自适应调整保护水平。

  5. 保护利润机制: 当交易达到预设利润的一半时,止损自动移动到保本位置以上,确保交易不会从盈利变为亏损。

  6. 时间框架灵活性: 尽管回测是在1分钟周期进行的,但策略的核心逻辑(FVG、趋势确认和动态止损)可适用于多种时间框架。

策略风险

  1. FVG可靠性问题: 在高波动市场中,FVG可能频繁出现但不一定都有交易价值,可能导致过度交易。解决方法是增加额外的过滤条件,如要求FVG具有最小宽度或在关键价格水平附近形成。

  2. 趋势定义局限性: 仅使用两条SMA来定义趋势可能在震荡市场中产生错误信号。解决方法是添加额外的趋势确认指标,如ADX(平均方向指数)来衡量趋势强度。

  3. 止损过窄风险: 0.5%的固定止损在某些高波动品种中可能过窄,容易被市场噪音触发。解决方法是将止损设置与ATR挂钩,使其适应不同品种的波动特性。

  4. 回撤管理不足: 当市场突然逆转时,跟踪止损可能无法快速响应,导致回撤扩大。解决方法是设置最大可接受回撤阈值,一旦超过则立即退出。

  5. 参数敏感性: 策略性能对SMA周期、止损比例和ATR乘数等参数高度敏感。解决方法是通过回测优化找到稳健的参数组合,并定期重新评估。

策略优化方向

  1. 多时间框架分析整合: 将更高时间框架的FVG和趋势信息纳入决策过程,可以提高信号质量。例如,可以要求1分钟图表上的信号与15分钟或1小时图表上的FVG和趋势方向一致。

  2. 动态止盈机制: 当前策略使用固定比例止盈,可以改进为基于ATR的动态止盈,或结合市场波动性自动调整止盈目标。

  3. 反转和盘整市场的适应性: 添加市场环境识别逻辑,在明确的趋势期使用当前策略,而在盘整期采用不同的入场和退出标准。

  4. 交易量确认: 整合交易量分析来验证FVG和IFVG的有效性。真正有意义的价格缺口通常伴随着显著的交易量变化。

  5. 机器学习优化: 使用机器学习算法来识别最具预测性的FVG特征组合,如缺口大小、形成速度、与支撑/阻力的关系等。

  6. 自适应参数调整: 开发一种机制,使策略能够根据最近的市场表现自动调整其参数,如在波动性增加时扩大止损范围。

  7. 增加仓位管理: 当前策略使用固定仓位(10单位),可以改进为基于波动性和风险度量的动态仓位管理系统,在高确信度信号上增加仓位,在不确定性高的市场减少暴露。

总结

趋势确认型反向公平价值缺口策略与动态跟踪止损是一个多层次的交易系统,将价格结构分析(FVG和IFVG)、趋势确认(SMA)和动态风险管理(ATR跟踪止损)有机结合。该策略的主要优势在于其多重确认机制和自适应风险管理,有效过滤了低质量信号并保护已实现的利润。

然而,该策略也面临FVG可靠性、趋势定义局限性和参数敏感性等挑战。未来的优化方向包括整合多时间框架分析、开发动态止盈机制、提高在不同市场环境的适应性以及引入机器学习技术来优化信号质量和参数选择。

通过这些改进,该策略有潜力发展成为一个更加稳健和自适应的交易系统,能够在各种市场条件下保持一致的性能。特别是通过增强其对市场结构和波动性变化的响应能力,策略可以更好地适应不断变化的市场环境,提高长期盈利能力和资金增长的稳定性。 ||

策略源码
/*backtest
start: 2025-01-01 00:00:00
end: 2025-07-02 00:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_CTP","currency":"FUTURES"}]
args: [["ContractType","au888",360008]]
*/

//@version=6
strategy("Inverted FVG Strategy with Trend Check and Trailing Stops", overlay=true)

// Function to detect FVG
fvgDetected(src, high, low) =>
    float prevHigh = na
    float prevLow = na
    float prevClose = na
    float fvgHigh = na
    float fvgLow = na
    bool fvg = false
    if (not na(src[3]))
        prevHigh := high[3]
        prevLow := low[3]
        prevClose := src[3]
        if (src[2] > prevClose and low[2] > prevHigh) or (src[2] < prevClose and high[2] < prevLow)
            fvg := true
            fvgHigh := low[2] > prevHigh ? high[2] : na
            fvgLow := high[2] < prevLow ? low[2] : na
    [fvg, fvgHigh, fvgLow]

// Detect FVG on the chart
[fvg, fvgHigh, fvgLow] = fvgDetected(close, high, low)

// Detect IFVG - Inversion of FVG
bool ifvg = false
float ifvgHigh = na
float ifvgLow = na

if (fvg)    
    if (high[1] > fvgHigh and close[1] > open[1]) or (high[1] < fvgLow and close[1] < open[1])
        ifvg := true
        ifvgHigh := close[1] > open[1] ? high[1] : na
        ifvgLow := close[1] <  open[1] ? low[1] : na

// Plot FVG and IFVG zones for visualization
plot(ifvgHigh, title="IFVG High", color=color.red, linewidth=2, style=plot.style_cross)
plot(ifvgLow, title="IFVG Low", color=color.red, linewidth=2, style=plot.style_cross)

// Trend Check using Simple Moving Averages
smaShort = ta.sma(close, 50)  // Short term SMA
smaLong = ta.sma(close, 200)  // Long term SMA
bool uptrend = false
bool downtrend = false

uptrend := smaShort > smaLong  // Up trend if short SMA is above long SMA
downtrend := smaShort < smaLong  // Down trend if short SMA is below long SMA

// Plot SMAs for visualization
plot(smaShort, title="SMA Short", color=color.blue, linewidth=1)
plot(smaLong, title="SMA Long", color=color.orange, linewidth=1)

// Trading logic with trend confirmation
longCondition = ifvg and close < ifvgLow and uptrend
shortCondition = ifvg and close > ifvgHigh and downtrend

// Risk Definition - 使用百分比
stopLoss = 0.005   // 0.5% 止损
takeProfit = 0.015  // 1.5% 止盈

if (longCondition and strategy.position_size == 0)
    strategy.entry("Long", strategy.long)
    stopPrice = close * (1 - stopLoss)
    limitPrice = close * (1 + takeProfit)
    strategy.exit("Initial Long Exit", "Long", stop=stopPrice, limit=limitPrice)

if (shortCondition and strategy.position_size == 0)
    strategy.entry("Short", strategy.short)
    stopPrice = close * (1 + stopLoss)
    limitPrice = close * (1 - takeProfit)
    strategy.exit("Initial Short Exit", "Short", stop=stopPrice, limit=limitPrice)

// ATR for dynamic trailing stop
atr = ta.atr(14)

// Trailing Stop for Long Position if the trade has moved > 0.5% (half of takeProfit)
if (strategy.position_size > 0)
    profitThreshold = takeProfit * 0.5  // 1.5% profit threshold
    if (close - strategy.position_avg_price >= strategy.position_avg_price * profitThreshold)
        // 将止损移动到盈亏平衡点加上一点利润
        trailingStopLong = math.max(strategy.position_avg_price * (1 + profitThreshold), close - (atr * 2))
        strategy.exit("Trailing Stop Long", "Long", stop=trailingStopLong)

// Trailing Stop for Short Position if the trade has moved > 0.5% (half of takeProfit)
if (strategy.position_size < 0)
    profitThreshold = takeProfit * 0.5  // 1.5% profit threshold
    if (strategy.position_avg_price - close >= strategy.position_avg_price * profitThreshold)
        // 将止损移动到盈亏平衡点加上一点利润
        trailingStopShort = math.min(strategy.position_avg_price * (1 - profitThreshold), close + (atr * 2))
        strategy.exit("Trailing Stop Short", "Short", stop=trailingStopShort)