基于双重反转套利策略

Author: ChaoZhang, Date: 2024-02-06 09:58:04
Tags:

基于双重反转套利策略

概述

双重反转套利策略是一种融合双反转指标的套利算法。它整合了123反转系统和Gann摆线振荡指标两个子策略,在两个子策略同时发出信号时,产生交易信号,实现套利操作。

策略原理

该策略由两个子策略组成:

  1. 123反转系统:它源自Ulf Jensen的《我如何在期货市场上三倍盈利》一书第183页。它的交易规则是:当收盘价比前一日收盘价高,且比前两日收盘价低时,在慢速K线低于50时做多;当收盘价比前一日收盘价低,且比前两日收盘价高时,在快速K线高于50时做空。

  2. Gann摆线振荡指标:它源自Robert Krausz的《发现W.D.甘能的宝藏》一书。它通过计算一定周期内的最高价和最低价的涨跌情况,判断市场摆动方向。

该套利策略的交易逻辑是:当两个子策略的信号方向一致时,产生实际的交易信号。做多信号是当两个子策略同时发出做多信号时;做空信号是当两个子策略同时发出做空信号时。

优势分析

该策略最大的优势在于整合两个子策略的信号,可以有效过滤假信号,提高交易信号的准确率。两个子策略各有自己的优点,123反转系统可以抓住突发性反转行情,而Gann摆线振荡指标可以判断趋势反转的熟期。把两者结合,可以使交易信号更加可靠,从而提高策略的稳定性。

风险分析

该策略的主要风险在于,两个子策略发出的交易信号方向不一致的概率较大,从而导致交易信号较少的问题。此外,子策略本身也会存在一定的假信号风险。这两个因素结合,可能导致策略交易次数不足,无法充分把握市场机会。

为降低风险,可以调整子策略的参数,使其交易频率适当提高,或者结合其他指标来辅助判断,过滤假信号。当两个子策略之间存在较大的信号偏差时,也可以考虑只跟随较为可靠的一方。

优化方向

该策略可从以下几个方面进行优化: 1. 调整子策略的参数,优化交易频率; 2. 增加其他技术指标判断,提高信号质量; 3. 根据不同品种、周期优化子策略权重; 4. 加入止损机制,控制单笔损失。

总结

双重反转套利策略通过集成两种不同类型的反转策略,形成较强的交易信号。它可以有效滤除噪音,提高信号质量,适合捕捉市场中的反转机会。但子策略发出信号不一致的概率较大,可能导致交易频率不足的问题。此外,组合策略本身参数设置较为复杂,需要充分测试优化,才能发挥最大效果。


/*backtest
start: 2024-01-06 00:00:00
end: 2024-02-05 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
////////////////////////////////////////////////////////////
//  Copyright by HPotter v1.0 04/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
// The Gann Swing Oscillator has been adapted from Robert Krausz's book, 
// "A W.D. Gann Treasure Discovered". The Gann Swing Oscillator helps 
// define market swings. 
//
// 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

    
GannSO(Length) =>
    pos = 0.0
    xGSO = 0.0
    xHH = highest(Length)
    xLL = lowest(Length)
    xGSO:= iff(xHH[2] > xHH[1] and xHH[0] > xHH[1], 1,
             iff(xLL[2] < xLL[1] and xLL[0] < xLL[1], -1, nz(xGSO[1],0)))
    pos := iff(xGSO > 0, 1,
    	     iff(xGSO < 0, -1, nz(pos[1], 0))) 
    pos

strategy(title="Combo Backtest 123 Reversal & Gann Swing Oscillator", shorttitle="Combo", overlay = true)
Length = input(14, minval=1)
KSmoothing = input(1, minval=1)
DLength = input(3, minval=1)
Level = input(50, minval=1)
//-------------------------
LengthGSO = input(5, minval=1)
reverse = input(false, title="Trade reverse")
posReversal123 = Reversal123(Length, KSmoothing, DLength, Level)
posGannSO = GannSO(LengthGSO)
pos = iff(posReversal123 == 1 and posGannSO == 1 , 1,
	   iff(posReversal123 == -1 and posGannSO == -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 )

更多内容