双信号量化反转策略


创建日期: 2023-12-01 14:14:46 最后修改: 2023-12-01 14:14:46
复制: 0 点击次数: 407
avatar of ChaoZhang ChaoZhang
1
关注
1247
关注者

双信号量化反转策略

概述

双信号量化反转策略通过结合123反转策略和加速器振荡器指标,实现对趋势反转的判断,获取更准确的交易信号。该策略主要用于股指、外汇、贵金属和能源品种的短线和中线交易。

策略原理

该策略由两段独立的代码逻辑组成。

第一部分为123反转策略,其判断反转信号的原理是:当收盘价连续两天低于上一收盘价,且9日STOCH指标K线低于D线时产生多头信号;当收盘价连续两天高于上一收盘价,且9日STOCH指号K线高于D线时产生空头信号。

第二部分为加速器振荡器指标。该指标通过计算绝对价格振荡器和其5周期移动平均线的差值,反映绝对价格振荡器的变化速度,可以提前判断趋势反转点。

最后,该策略将两个指标的信号进行组合:当两指标信号同向时(双多或双空),输出该方向的交易信号;当两指标信号不一致时,输出零信号。

优势分析

该策略结合双重指标判断,可以过滤掉一定的假信号,信号准确可靠。同时利用绝对价格振荡器反映变化加速度的特点,可以提前捕捉到潜在的趋势反转点,从而争取更大的利润空间。

风险分析

该策略最大的风险在于指标发出信号前价格已经出现明显的反转,导致错过最佳入场点。此外,行情剧烈波动时,指标参数需要进行优化调整。

针对入场点风险,可以结合更多反转指标进行组合,确保信号的可靠性;针对参数优化问题,可以建立动态调整机制,确保参数的合理性。

优化方向

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

  1. 增加过滤条件,避免在高波动阶段产生错误信号

  2. 结合更多反转指标,形成多重验证机制

  3. 建立参数自适应机制,动态调整指标参数

  4. 优化止损策略,以控制单笔止损

总结

双信号量化反转策略通过双重验证提高信号准确率,有助于把握市场关键的反转点;同时也需要注意防范指标滞后和参数失效的风险,持续对策略进行验证和优化,使之能适应多变的市场环境。该策略适合有一定量化交易经验的投资者使用。

策略源码
/*backtest
start: 2023-11-23 00:00:00
end: 2023-11-30 00:00:00
period: 2h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=3
////////////////////////////////////////////////////////////
//  Copyright by HPotter v1.0 25/04/2019
// This is combo strategies for get 
// a cumulative signal. Result signal will return 1 if two strategies 
// is long, -1 if all strategies is short and 0 if signals of strategies is not equal.
//
// 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.
//
// Secon strategy
// The Accelerator Oscillator has been developed by Bill Williams 
// as the development of the Awesome Oscillator. It represents the 
// difference between the Awesome Oscillator and the 5-period moving 
// average, and as such it shows the speed of change of the Awesome 
// Oscillator, which can be useful to find trend reversals before the 
// Awesome Oscillator does.
//
// 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

AcceleratorOscillator(nLengthSlow, nLengthFast) =>
    xSMA1_hl2 = sma(hl2, nLengthFast)
    xSMA2_hl2 = sma(hl2, nLengthSlow)
    xSMA1_SMA2 = xSMA1_hl2 - xSMA2_hl2
    xSMA_hl2 = sma(xSMA1_SMA2, nLengthFast)
    nRes =  xSMA1_SMA2 - xSMA_hl2
    cClr = nRes > nRes[1] ? blue : red
    pos = 0.0
    pos := iff(nRes > 0, 1,
             iff(nRes < 0, -1, nz(pos[1], 0))) 
    pos

strategy(title="Combo Backtest 123 Reversal and Accelerator Oscillator (AC)", shorttitle="Combo", overlay = true)
Length = input(14, minval=1)
KSmoothing = input(1, minval=1)
DLength = input(3, minval=1)
Level = input(50, minval=1)
nLengthSlow = input(34, minval=1, title="Length Slow")
nLengthFast = input(5, minval=1, title="Length Fast")
reverse = input(false, title="Trade reverse")
posReversal123 = Reversal123(Length, KSmoothing, DLength, Level)
posAcceleratorOscillator = AcceleratorOscillator(nLengthSlow, nLengthFast)
pos = iff(posReversal123 == 1 and posAcceleratorOscillator == 1 , 1,
	   iff(posReversal123 == -1 and posAcceleratorOscillator == -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 ? red: possig == 1 ? green : blue )