本文介绍的是一个结合达瓦斯箱体(Darvas Box)和25周期移动平均线(MA25)的趋势跟踪交易系统。该策略通过识别价格盘整区间形成的箱体,并结合均线趋势确认,在突破时捕捉强势行情。系统设计充分考虑了趋势延续性和假突破过滤,为交易者提供了一个完整的市场进出场框架。
策略主要包含三个核心组成部分: 1. 达瓦斯箱体的构建:系统通过计算过去5个周期的最高价和最低价来确定箱体边界。箱体顶部由新高点确定,底部由相应区间内的最低点确定。 2. 均线趋势确认:引入25周期简单移动平均线作为趋势过滤器,只有当价格位于MA25之上时才考虑开仓。 3. 交易信号生成: - 买入信号:价格突破箱体顶部且位于MA25之上 - 卖出信号:价格跌破箱体底部
该策略通过结合经典的达瓦斯箱体理论和移动平均线趋势跟踪,构建了一个稳健的交易系统。系统的主要优势在于能够有效捕捉趋势性行情,同时通过多重过滤机制控制风险。虽然存在一定的滞后性,但通过合理的参数优化和风险管理,该策略能够在趋势市场中获得稳定表现。建议交易者在实盘使用时,重点关注市场环境的选择,并根据实际情况动态调整参数设置。
/*backtest start: 2024-10-01 00:00:00 end: 2024-10-31 23:59:59 period: 1h basePeriod: 1h exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy("DARVAS BOX with MA25 Buy Condition", overlay=true, shorttitle="AEG DARVAS") // Input for box length boxp = input.int(5, "BOX LENGTH") // Calculate 25-period moving average ma25 = ta.sma(close, 25) // Lowest low and highest high within the box period LL = ta.lowest(low, boxp) k1 = ta.highest(high, boxp) k2 = ta.highest(high, boxp - 1) k3 = ta.highest(high, boxp - 2) // New high detection NH = ta.valuewhen(high > k1[1], high, 0) // Logic to detect top and bottom of Darvas Box box1 = k3 < k2 TopBox = ta.valuewhen(ta.barssince(high > k1[1]) == boxp - 2 and box1, NH, 0) BottomBox = ta.valuewhen(ta.barssince(high > k1[1]) == boxp - 2 and box1, LL, 0) // Plot the top and bottom Darvas Box lines plot(TopBox, linewidth=3, color=color.green, title="Top Box") plot(BottomBox, linewidth=3, color=color.red, title="Bottom Box") plot(ma25, color=#2195f31e, linewidth=2, title="ma25") // --- Buy and Sell conditions --- // Buy when price breaks above the Darvas Box AND MA15 buyCondition = ta.crossover(close, TopBox) and close > ma25 // Sell when price drops below the Darvas Box sellCondition = ta.crossunder(close, BottomBox) // --- Buy and Sell Signals --- // Plot BUY+ and SELL labels plotshape(series=buyCondition, title="Buy+ Signal", location=location.abovebar, color=#72d174d3, style=shape.labeldown, text="BUY") plotshape(series=sellCondition, title="Sell Signal", location=location.belowbar, color=color.rgb(234, 62, 62, 28), style=shape.labelup, text="SELL") // --- Strategy execution --- if (buyCondition) strategy.entry("Buy", strategy.long) if (sellCondition) strategy.close("Buy")