双机构量化反转追踪策略


创建日期: 2024-01-05 15:09:19 最后修改: 2024-01-05 15:09:19
复制: 0 点击次数: 571
avatar of ChaoZhang ChaoZhang
1
关注
1617
关注者

双机构量化反转追踪策略

概述

本策略综合运用双机构指标的优势,采用123形态判断反转信号,辅以正量指数判断量能信号,实现对短线反转行情的捕捉。

策略原理

  1. 123形态判断反转信号

    • 使用9日Stoch指标的快线和慢线构建

    • 当收盘价连续两日下跌,第三日收盘价上涨时,并且Stoch快线低于50时,产生买入信号

    • 当收盘价连续两日上涨,第三日收盘价下跌时,并且Stoch快线高于50时,产生卖出信号

  2. 正量指数判断量能信号

    • 正量指数(PVI)通过比较前一日和今日的成交量变化判断量能

    • 当PVI上穿其N日移动平均线时,说明量能放大,产生买入信号

    • 当PVI下穿其N日移动平均线时,说明量能缩减,产生卖出信号

  3. 双信号综合判断

    • 只有当123反转信号和PVI量能信号同向发出时,才产生交易信号

综上,该策略充分利用双机构指标的优势,能够有效识别短线量价反转机会。

优势分析

  1. 123形态判断,能够捕捉关键的短线反转点位

  2. PVI量能指标,判断量价配合,避免假突破

  3. Stoch指标参数优化,能过滤掉大部分躁动区域的无效信号

  4. 双信号结合,可靠度较单一信号更高

  5. 采用日内判断,避免隔夜风险,适合短线操作

风险分析

  1. 反转失败风险

    • 123形态反转信号并不总是有效,存在形态失败风险
  2. 指标失效风险

    • 在某些异常行情下,Stoch和PVI等指标会失效
  3. 双重信号遗漏风险

    • 同向双信号条件较为严苛,可能遗漏部分单边信号机会
  4. 交易频率风险

    • 策略交易频率偏高,需要密切监控仓位和风控

优化方向

  1. 参数优化空间大

    • Stoch窗口期、PVI周期数等参数存在优化空间
  2. 可加入止损策略

    • 可结合移动止损保证策略胜率
  3. 考虑加入过滤条件

    • 可测试加入均线、波动率等滤波指标
  4. 优化双信号组合

    • 可测试更多双指标的组合套利

总结

本策略通过 Stoch指标和 PVI 指标的组合,形成高可靠性的短线量价反转交易策略。相比单一指标,具有更高的胜率和正期望。通过参数优化和风控设置,可以进一步扩大夏普比率。总体来说,该策略利用双机构指标的优势,能够有效捕捉市场的短期反转机会,值得实盘验证优化。

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

//@version=4
////////////////////////////////////////////////////////////
//  Copyright by HPotter v1.0 22/04/2021
// 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 theory behind the indexes is as follows: On days of increasing volume, 
// you can expect prices to increase, and on days of decreasing volume, you can 
// expect prices to decrease. This goes with the idea of the market being in-gear 
// and out-of-gear. Both PVI and NVI work in similar fashions: Both are a running 
// cumulative of values, which means you either keep adding or subtracting price 
// rate of change each day to the previous day`s sum. In the case of PVI, if today`s 
// volume is less than yesterday`s, don`t add anything; if today`s volume is greater, 
// then add today`s price rate of change. For NVI, add today`s price rate of change 
// only if today`s volume is less than yesterday`s.
//
// 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


PVI(EMA_Len) =>
    pos = 0.0
    xROC = roc(close, 1)
    nRes = 0.0
    nResEMA = 0.0
    nRes := iff(volume > volume[1], nz(nRes[1], 0) + xROC, nz(nRes[1], 0))
    nResEMA := ema(nRes, EMA_Len)
    pos := iff(nRes > nResEMA, 1,
        	 iff(nRes < nResEMA, -1, nz(pos[1], 0))) 
    pos

strategy(title="Combo Backtest 123 Reversal & Positive Volume Index", shorttitle="Combo", overlay = true)
line1 = input(true, "---- 123 Reversal ----")
Length = input(14, minval=1)
KSmoothing = input(1, minval=1)
DLength = input(3, minval=1)
Level = input(50, minval=1)
//-------------------------
line2 = input(true, "---- Positive Volume Index ----")
EMA_Len = input(255, minval=1)
reverse = input(false, title="Trade reverse")
posReversal123 = Reversal123(Length, KSmoothing, DLength, Level)
posPVI = PVI(EMA_Len)
pos = iff(posReversal123 == 1 and posPVI == 1 , 1,
	   iff(posReversal123 == -1 and posPVI == -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 )