反向突破交易策略


创建日期: 2023-10-25 12:09:40 最后修改: 2023-10-25 12:38:23
复制: 0 点击次数: 571
avatar of ChaoZhang ChaoZhang
1
关注
1364
关注者

反向突破交易策略

概述

反向突破交易策略是一种基于价格连续上涨或下跌突破进行反向操作的交易策略。该策略通过设置价格连续上涨或下跌的周期,在价格形成一定趋势之后,进行反向操作,以获利。

策略原理

该策略主要通过以下几个部分来实现:

  1. 设置价格连续上涨和下跌的周期长度,即consecutiveBarsUp和consecutiveBarsDown,当前周期价格趋势达到设置长度后触发交易信号。

  2. 计算当前价格相对上一个周期价格的涨跌情况,根据涨跌情况计算当前连续上涨或下跌的周期长度ups和dns。

  3. 设置回测的时间范围,通过time_cond来限定策略只在回测时间内操作。

  4. 设置每日的交易时间,通过timetobuy来限定只有在设置的时间段内发出交易信号。

  5. 当价格连续上涨周期达到设置长度,发出做多信号,通过strategy.long;当价格连续下跌周期达到设置长度,发出做空信号,通过strategy.short。

  6. 可以设置止损和止盈价格。做多时设置短期止损,做空时设置长期止损;做多时设置长期止盈,做空时设置短期止盈。

  7. 可以设置发送交易信号时的消息提示。

  8. 根据以上参数和价位判断,在符合条件时发出做多或做空信号。

优势分析

这种反向突破策略具有以下几点优势:

  1. 捕捉价格反转点,反向操作可获得较好利润。当价格形成趋势后,进行反向操作,可以在价格反转时获利。

  2. 可配置参数灵活,可以根据市场调整参数。可调节连续上涨和下跌的周期数,调整止盈止损点位,限定交易时间段,可根据实际情况进行参数优化。

  3. 可添加止损止盈,控制风险。做多做空后可预先设置止损和止盈,有助于控制交易风险。

  4. 可设置交易提示消息,便于自动化交易。可以设置发送交易信号时的消息提示,配合自动交易系统使用。

  5. 可设置回测时间范围,方便测试策略。添加了回测时间范围的设置,可以方便观察不同市场条件下策略效果。

风险分析

该策略也存在一些风险需要注意:

  1. 需避开重要新闻事件。重大消息发布时无法判断价格走势,策略会同时发出做多做空信号,造成亏损。需避开重要财经消息的发布时间。

  2. 反转不明显时作用不大。趋势不明显时,反向操作效果不佳,需要谨慎使用。

  3. 回测数据拟合风险。策略优化要避免过度依赖回测数据,回测数据不代表未来走势。实盘时应适当调整参数。

  4. 交易频率过高容易盯市。若设置的周期过短,交易频率过高,不利于长期稳定盈利。

  5. 可适当优化止损止盈策略,降低风险。现有的固定止损止盈可进一步优化为趋势跟踪止损等方式。

优化方向

该策略可以从以下几个方面进行进一步优化:

  1. 增加趋势判断机制,避免非趋势市场的乱反转。可以检测价格波动率、通道等指标,判断趋势程度,避免错过价格反转点。

  2. 优化止损止盈策略,使其能根据市场波动自动调整。可以采用余额百分比止损、ATR 止损等方法,使止损止盈设置更加智能化。

  3. 加入量能指标判断。结合交易量变化等指标,避免单纯依据K线形态产生的错误信号。

  4. 多品种组合。将策略应用于不同品种,进行组合,可以分散单一品种的风险。

  5. 参数优化和机器学习。收集更多历史数据,使用机器学习方法自动优化参数,使策略更稳定。

总结

反向突破交易策略通过捕捉价格反转点进行反向操作,可以获取不错的交易信号。该策略优势在于配置灵活,可控制风险,适合自动化交易。但也存在一定的风险,需要对参数及策略进行不断优化和完善,才能长期稳定获利。

策略源码
/*backtest
start: 2023-10-17 00:00:00
end: 2023-10-24 00:00:00
period: 45m
basePeriod: 5m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4

// Strategy
strategy("Up/Down Strategy - Contrarian", overlay=true, initial_capital = 10000, default_qty_value = 10000, default_qty_type = strategy.cash)

consecutiveBarsUp = input(1, title='Consecutive Bars Up')
consecutiveBarsDown = input(1, title='Consecutive Bars Down')

price = close

ups = 0.0
ups := price > price[1] ? nz(ups[1]) + 1 : 0

dns = 0.0
dns := price < price[1] ? nz(dns[1]) + 1 : 0

// Strategy Backtesting
startDate  = input(timestamp("2021-01-01T00:00:00"), type = input.time, title='Backtesting Start Date')
finishDate = input(timestamp("2021-12-31T00:00:00"), type = input.time, title='Backtesting End Date')

time_cond  = true

//Time Restriction Settings
startendtime = input("", title='Time Frame To Enter Trades')
enableclose = input(false, title='Enable Close Trade At End Of Time Frame')
timetobuy = true
timetoclose = true

// Stop Loss & Take Profit Tick Based
enablesltp = input(false, title='Enable Take Profit & Stop Loss')
stopTick = input(5.0, title='Stop Loss Ticks', type=input.float) / 100
takeTick = input(10.0, title='Take Profit Ticks', type=input.float) / 100

longStop = strategy.position_avg_price - stopTick
shortStop = strategy.position_avg_price + stopTick
shortTake = strategy.position_avg_price - takeTick
longTake = strategy.position_avg_price + takeTick

plot(strategy.position_size > 0 and enablesltp ? longStop : na, style=plot.style_linebr, color=color.red, linewidth=1, title="Long Fixed SL")
plot(strategy.position_size < 0 and enablesltp ? shortStop : na, style=plot.style_linebr, color=color.red, linewidth=1, title="Short Fixed SL")
plot(strategy.position_size > 0 and enablesltp ? longTake : na, style=plot.style_linebr, color=color.green, linewidth=1, title="Long Take Profit")
plot(strategy.position_size < 0 and enablesltp ? shortTake : na, style=plot.style_linebr, color=color.green, linewidth=1, title="Short Take Profit")

// Alert messages
message_enterlong  = input("", title="Long Entry message")
message_entershort = input("", title="Short Entry message")
message_closelong = input("", title="Close Long message")
message_closeshort = input("", title="Close Short message")

// Strategy Execution
if (dns >= consecutiveBarsDown) and time_cond and timetobuy
    strategy.entry("Long", strategy.long, stop = high + syminfo.mintick, alert_message = message_enterlong)
    
if (ups >= consecutiveBarsUp) and time_cond and timetobuy
    strategy.entry("Short", strategy.short, stop = low + syminfo.mintick, alert_message = message_entershort)
    
if strategy.position_size < 0 and timetoclose and enableclose
    strategy.close_all(alert_message = message_closelong)
if strategy.position_size > 0 and timetoclose and enableclose
    strategy.close_all(alert_message = message_closeshort)
    
if strategy.position_size < 0 and enablesltp and time_cond
    strategy.exit(id="Close Long", stop=longStop, limit=longTake, alert_message = message_closelong)
if strategy.position_size > 0 and enablesltp and time_cond
    strategy.exit(id="Close Short", stop=shortStop, limit=shortTake, alert_message = message_closeshort)