双Donchian通道突破策略


创建日期: 2024-02-21 11:38:48 最后修改: 2024-02-21 11:38:48
复制: 0 点击次数: 779
avatar of ChaoZhang ChaoZhang
1
关注
1368
关注者

双Donchian通道突破策略

概述

双Donchian通道突破策略(Dual Donchian Channel Breakout Strategy)是一种基于Donchian通道的突破交易策略。它利用快速和慢速两个Donchian通道构建多头和空头交易信号。当价格突破慢速通道时开仓做多或做空,当价格重新突破快速通道时平仓。该策略同时设置了止盈和止损条件。

策略原理

双Donchian通道突破策略基于两个参数:慢速Donchian通道周期快速Donchian通道周期。策略首先计算两个Donchian通道的上轨和下轨。

  • 慢速Donchian通道周期默认为50根K线,反映了较长期的趋势。
  • 快速Donchian通道周期默认为30根K线,反映了较短期的趋势变化。

多头入场信号是价格突破上轨波动率大于阈值。空头入场信号则是价格突破下轨波动率大于阈值

多头止损平仓信号是价格重新突破下轨。空头止损平仓信号是价格重新突破上轨

该策略同时设置了止盈退出条件。默认设置为止盈比例为2%,即价格变动达到2%时止盈一半仓位。

优势分析

双Donchian通道突破策略具有以下优势:

  1. 使用双通道设计,能捕捉较长线和较短线的趋势信号,实现更准确的入场。

  2. 波动率条件避免了横盘市的频繁交易。

  3. 止盈和止损设置全面,可以锁定部分利润,也可以减少损失。

  4. 策略逻辑简单清晰,容易理解和实现。

  5. 可自定义参数,适应不同品种和交易偏好。

风险分析

双Donchian通道突破策略也存在一定的风险:

  1. 双通道设计较为敏感,容易产生错误信号。可以适当拓宽通道范围或调整波动率参数来减少错误信号。

  2. 剧烈行情中止损可能触发过于频繁。可以设置交易次数上限或扩大止损幅度。

  3. 固定比例止盈无法最大限度锁定利润。可以考虑动态跟踪止盈或人工干预确定止盈价格。

  4. 回测外的实盘情况可能与预期不符,应提前充分验证,必要时调整参数。

优化方向

双Donchian通道突破策略可从以下几个方面进行优化:

  1. 测试更多周期参数组合,找到最佳参数。

  2. 尝试不同的波动率计算方法,如ATR,寻找最稳定的参数。

  3. 设置开仓次数限制,避免趋势末期打反弹带来损失。

  4. 尝试动态跟踪止盈,实现更高的单笔利润。

  5. 结合其他指标过滤入场信号,提高决策准确性。例如结合成交量指标.

  6. 优化资金管理策略,如固定份额、凯利公式等,控制更好的风险收益比。

总结

双Donchian通道突破策略整体来说是一种优秀的趋势跟踪策略。它同时兼具趋势识别能力和反转防护能力。通过参数优化和规则完善,能够适应大部分品种,在多种市场中 profitable trading。该策略简单实用,值得量化交易者学习和应用。

策略源码
/*backtest
start: 2024-01-01 00:00:00
end: 2024-01-31 23:59:59
period: 1h
basePeriod: 15m
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/
// © omererkan

//@version=5
strategy(title="Double Donchian Channel Breakout", overlay=true, initial_capital = 1000, commission_value = 0.05, default_qty_value = 100, default_qty_type = strategy.percent_of_equity)

// Donchian Channels
slowLen = input.int(50, title="Slow Donchian", group = "Conditions")
fastLen = input.int(30, title="Fast Donchian", group = "Conditions")

// Volatility Calculated as a percentage
volatility = input.int(3, title="Volatility (%)", group = "Conditions")

// Long positions
long = input.bool(true, "Long Position On/Off", group = "Strategy")
longProfitPerc = input.float(2, title="Long TP1 (%)", group = "Strategy", minval=0.0, step=0.1) * 0.01

// Short positions
short = input.bool(true, "Short Position On/Off", group = "Strategy")
shortProfitPerc = input.float(2, title="Short TP1 (%)", group = "Strategy", minval=0.0, step=0.1) * 0.01

// First take profit point for positions
TP1Yuzde =input.int(50, title = "TP1 Position Amount (%)", group = "Strategy")

// Slow Donchian Calculated
ubSlow = ta.highest(high, slowLen)[1]
lbSlow = ta.lowest(low, slowLen)[1]

// Fast Donchian Calculated
ubFast = ta.highest(high, fastLen)[1]
lbFast = ta.lowest(low, fastLen)[1]

// Plot Donchian Channel for entries
plot(ubSlow, color=color.green, linewidth=2, title="Slow DoCh - Upperband")
plot(lbSlow, color=color.green, linewidth=2, title="Slow DoCh - Lowerband")
plot(ubFast, color=color.blue, linewidth=2, title="Fast DoCh - Upperband")
plot(lbFast, color=color.blue, linewidth=2, title="Fast DoCh - Lowerband")

// This calculation, the strategy does not open position in the horizontal market.
fark = (ubSlow - lbSlow) / lbSlow * 100

// Take profit levels
longExitPrice  = strategy.position_avg_price * (1 + longProfitPerc)
shortExitPrice = strategy.position_avg_price * (1 - shortProfitPerc)

// Code long trading conditions
longCondition = ta.crossover(close, ubSlow) and fark > volatility
if longCondition and long == true
    strategy.entry("Long", strategy.long)

// Code short trading conditions
shortCondition = ta.crossunder(close, lbSlow) and fark > volatility
if shortCondition and short == true
    strategy.entry("Short", strategy.short)

// Determine long trading conditions
if strategy.position_size > 0 and ta.crossunder(close, lbFast) 
    strategy.close_all("Close All")

// Determine short trading conditions
if strategy.position_size < 0 and ta.crossover(close, ubFast)
    strategy.close_all("Close All")

// Take Profit Long
if strategy.position_size > 0
    strategy.exit("TP1", "Long", qty_percent = TP1Yuzde, limit = longExitPrice)

// Take Profit Short
if strategy.position_size < 0
    strategy.exit("TP1", "Short", qty_percent = TP1Yuzde, limit = shortExitPrice)