双向追踪反转量化交易策略

Author: ChaoZhang, Date: 2024-02-22 13:46:51
Tags:

双向追踪反转量化交易策略

本策略运用双向追踪机制,结合价格反转信号和成交量指标,实现自动化的量化交易。其最大优势在于可靠的风险控制,通过追踪止损来锁定利润,避免亏损扩大。同时,反转交易信号增强了策略的胜率。本文将详细解析该策略的原理、优势、风险和优化方向。

策略原理

本策略由两个子策略组成。第一个子策略运用随机指标判定价格反转信号,具体逻辑是:

如果收盘价连续两天上涨,且9日Slow K线低于50,则做多;如果收盘价连续两天下跌,且9日Fast K线高于50,则做空。

第二个子策略则是结合成交量指标,判断力度的强弱。具体来说,是将当前成交量与40日成交量平均值比较。如果当前成交量大于平均值,认为是量能上攻,属于反转信号,做空;如果当前成交量小于平均值,认为是量能下泻,属于反转信号,做多。

最终交易信号,是上述两个子策略信号的交集。即两子策略同时发出信号时,才会开仓。通过这种“Intersection Targets”方法,可以过滤掉部分噪声交易,提高信号质量。

策略优势

  1. 利用双重指标确认,提高信号质量
  2. 反转交易模式,具有一定的时序优势
  3. 结合成交量分析,判断未来价格走势
  4. 可靠的止损机制,有效控制单笔亏损

策略风险

  1. 反转信号可能出现失效,无法完全过滤市场噪声
  2. 成交量异常时,量能判断会失效
  3. 止损设置不当,可能造成过早止损或停损幅度过大
  4. 回撤控制机制不完善,可能缩短策略寿命

可以从以下几个方面进一步优化:

  1. 增加趋势判断规则,避免逆势交易
  2. 优化止损逻辑,实现追踪止损和分阶段止损
  3. 增加最大回撤限制,关闭策略避免巨额亏损
  4. 结合机器学习算法,建立动态止损和头寸控制模型

总的来说,本策略以双向追踪和价格反转为主要交易逻辑,并辅以量能判断,通过双重确认提高信号质量。在实际应用中,仍需要进一步测试和优化,特别要防范止损和资金管理方面的风险,防止回撤过大导致的破产。但整体来说,本策略运用了量化交易的多种技巧,思路清晰,值得深入研究。


/*backtest
start: 2024-01-01 00:00:00
end: 2024-01-31 23:59:59
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
////////////////////////////////////////////////////////////
//  Copyright by HPotter v1.0 16/11/2020
// This is combo strategies for get a cumulative signal. 
//
// First strategy
// This System was created from the Book "How I Tripled My Money In The 
// Futures Market" by Ulf Jensen, Page 183. This is reverse type of strategies.
// The strategy buys at market, if close price is higher than the previous close 
// during 2 days and the meaning of 9-days Stochastic Slow Oscillator is lower than 50. 
// The strategy sells at market, if close price is lower than the previous close price 
// during 2 days and the meaning of 9-days Stochastic Fast Oscillator is higher than 50.
//
// Second strategy
// Volume and SMA
//
// WARNING:
// - For purpose educate only
// - This script to change bars colors.
////////////////////////////////////////////////////////////
Reversal123(Length, KSmoothing, DLength, Level) =>
    vFast = sma(stoch(close, high, low, Length), KSmoothing) 
    vSlow = sma(vFast, DLength)
    pos = 0.0
    pos := iff(close[2] < close[1] and close > close[1] and vFast < vSlow and vFast > Level, 1,
	         iff(close[2] > close[1] and close < close[1] and vFast > vSlow and vFast < Level, -1, nz(pos[1], 0))) 
	pos

    
VSAVol(Length) =>
    pos = 0.0
    xSMA_vol = sma(volume, Length)
    pos := iff(volume > xSMA_vol, -1,
    	     iff(volume < xSMA_vol, 1, nz(pos[1], 0))) 
    pos

strategy(title="Combo Backtest 123 Reversal & Volume SMA", shorttitle="Combo", overlay = true)
Length = input(14, minval=1)
KSmoothing = input(1, minval=1)
DLength = input(3, minval=1)
Level = input(50, minval=1)
//-------------------------
Length_MAVol = input(40, minval=1)
reverse = input(false, title="Trade reverse")
posReversal123 = Reversal123(Length, KSmoothing, DLength, Level)
posVSAVol = VSAVol(Length_MAVol)
pos = iff(posReversal123 == 1 and posVSAVol == 1 , 1,
	   iff(posReversal123 == -1 and posVSAVol == -1, -1, 0)) 
possig = iff(reverse and pos == 1, -1,
          iff(reverse and pos == -1 , 1, pos))	   
if (possig == 1) 
    strategy.entry("Long", strategy.long)
if (possig == -1)
    strategy.entry("Short", strategy.short)	 
if (possig == 0) 
    strategy.close_all()
barcolor(possig == -1 ? #b50404: possig == 1 ? #079605 : #0536b3 )

更多内容