
双重趋势追踪策略是一种同时结合双重指标判断趋势的量化交易策略。该策略首先利用123反转指标判断价格反转信号,然后再结合方向趋势指标(DTI)判断价格趋势方向,从而实现双重确认下单信号。
该策略主要由两部分组成:
123反转指标
123反转指标的判断原理是:
当收盘价连续2天上涨,并且9日慢速K线低于50时,做多;
当收盘价连续2天下跌,并且9日快速K线高于50时,做空。
这样可以捕捉到价格反转的时机点。
方向趋势指标(DTI)
DTI指标判断原理是:计算一段时间价格波动的绝对值均线,再除以价格的平均波幅。
当DTI高于超买线时,表明目前是下跌趋势;
当DTI低于超卖线时,表明目前是上涨趋势。
两者结合
首先利用123反转指标判断价格是否出现反转信号。然后再结合DTI指标判断反转后价格的总体趋势方向。
这样可以避免单纯依靠反转信号所带来的假反转问题,从而提高策略的稳定性和盈利能力。
双重指标确认,避免假反转带来的风险
结合反转与趋势判断,兼顾操作灵活性与稳定性
参数优化空间大,可以灵活调整适应不同品种
DTI参数设置需要经验,不恰当会误判趋势方向
反转不一定代表新的趋势形成,可能出现震荡RANGE市
需要有效止损,控制单笔损失
解决方法:参数优化测试 + 合理止损 + 结合其他指标
对DTI参数进行测试,找到最佳参数组合
结合其他指标过滤假反转信号
优化止损策略,找到最佳止损点
双重趋势追踪策略通过123反转与DTI双重指标确认,可以有效判断价格反转实质性并捕捉新的趋势方向,从而提高策略获利概率。但参数设置及止损策略仍需不断测试优化,才能将策略盈利空间最大化。总的来说,该策略结合了趋势与反转交易的优点,是一种值得推荐的量化策略。
/*backtest
start: 2023-12-25 00:00:00
end: 2024-01-01 00:00:00
period: 15m
basePeriod: 5m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
////////////////////////////////////////////////////////////
// Copyright by HPotter v1.0 19/02/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
// This technique was described by William Blau in his book "Momentum,
// Direction and Divergence" (1995). His book focuses on three key aspects
// of trading: momentum, direction and divergence. Blau, who was an electrical
// engineer before becoming a trader, thoroughly examines the relationship between
// price and momentum in step-by-step examples. From this grounding, he then looks
// at the deficiencies in other oscillators and introduces some innovative techniques,
// including a fresh twist on Stochastics. On directional issues, he analyzes the
// intricacies of ADX and offers a unique approach to help define trending and
// non-trending periods.
// Directional Trend Index is an indicator similar to DM+ developed by Welles Wilder.
// The DM+ (a part of Directional Movement System which includes both DM+ and
// DM- indicators) indicator helps determine if a security is "trending." William
// Blau added to it a zeroline, relative to which the indicator is deemed positive or
// negative. A stable uptrend is a period when the DTI value is positive and rising, a
// downtrend when it is negative and falling.
//
// 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
TDI(r,s,u,OS,OB) =>
pos = 0.0
xHMU = iff(high - high[1] > 0, high - high[1], 0)
xLMD = iff(low - low[1] < 0, -(low - low[1]), 0)
xPrice = xHMU - xLMD
xPriceAbs = abs(xPrice)
xuXA = ema(ema(ema(xPrice, r),s),u)
xuXAAbs = ema(ema(ema(xPriceAbs, r),s),u)
Val1 = 100 * xuXA
Val2 = xuXAAbs
DTI = iff(Val2 != 0, Val1 / Val2, 0)
pos := iff(DTI > OS, -1,
iff(DTI < OB, 1, nz(pos[1], 0)))
pos
strategy(title="Combo Backtest 123 Reversal & Directional Trend Index (DTI)", shorttitle="Combo", overlay = true)
Length = input(14, minval=1)
KSmoothing = input(1, minval=1)
DLength = input(3, minval=1)
Level = input(50, minval=1)
//-------------------------
r = input(14, minval=1)
s = input(10, minval=1)
u = input(5, minval=1)
OS = input(45, minval=1)
OB = input(-45, maxval=-1)
reverse = input(false, title="Trade reverse")
posReversal123 = Reversal123(Length, KSmoothing, DLength, Level)
posTDI = TDI(r,s,u,OS,OB)
pos = iff(posReversal123 == 1 and posTDI == 1 , 1,
iff(posReversal123 == -1 and posTDI == -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 )