动态摆动指标策略


创建日期: 2023-09-14 16:15:42 最后修改: 2023-09-14 16:15:42
复制: 3 点击次数: 671
avatar of ChaoZhang ChaoZhang
1
关注
1617
关注者

策略原理

该策略基于动态摆动指标(DMI)进行交易。DMI通过计算价格与不同长度均线的百分比偏离来判断趋势。

具体交易逻辑是:

  1. 计算价格与长周期均线(如200日)的百分比偏离,作为第1 DMI

  2. 计算价格与中周期均线(如50日)的百分比偏离,作为第2 DMI

  3. 计算价格与短周期均线(如20日)的百分比偏离,作为第3 DMI

  4. 当第3 DMI高于第1 DMI时看跌;当第3 DMI低于第2 DMI时看涨

  5. 根据DMI关系产生交易信号

DMI通过动态比较不同均线周期的相对强度,判断市场趋势转折点。参数优化可以适应不同周期。

策略优势

  • DMI结合多周期判断,比较全面

  • 比较相对强度,避免绝对数值判断

  • 可灵活调整周期参数适应市场

策略风险

  • DMI有一定滞后性,可能错过转折

  • 需要谨慎设定周期参数

  • 可能产生多次无效信号

总结

DMI策略通过比较多均线周期的强弱关系来判断转折。可通过参数优化适应不同市场环境。但滞后性存在,需辅助其他指标进行判断。

策略源码
/*backtest
start: 2023-08-14 00:00:00
end: 2023-09-13 00:00:00
period: 3h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=2
////////////////////////////////////////////////////////////
//  Copyright by HPotter v1.0 31/06/2018
// The related article is copyrighted materialfrom Stocks & Commodities Dec 2009
// My strategy modification.
//
// You can change long to short in the Input Settings
// WARNING:
// - For purpose educate only
// - This script to change bars colors.
////////////////////////////////////////////////////////////
strategy(title="CMOaDisparity Index Backtest")
LengthFirst = input(200, minval=1)
LengthSecond = input(50, minval=1)
LengthThird = input(20, minval=1)
ShowFirst = input(type=bool, defval=true)
ShowSecond = input(type=bool, defval=true)
ShowThird = input(type=bool, defval=true)
reverse = input(false, title="Trade reverse")
xEMAFirst = ema(close,LengthFirst)
xEMASecond  = ema(close,LengthSecond)
xEMAThird  = ema(close,LengthThird)
xResFirst = 100 * (close - xEMAFirst) / close
xResSecond = 100 * (close - xEMASecond) / close
xResThird = 100 * (close - xEMAThird) / close
pos = iff(xResThird > xResFirst, -1,
       iff(xResThird < xResSecond, 1, nz(pos[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)	   	    
barcolor(possig == -1 ? red: possig == 1 ? green : blue ) 
plot(ShowFirst ? xResFirst : na, color=red, title="DIX 1")
plot(ShowSecond ? xResSecond : na, color=blue, title="DIX 2")
plot(ShowThird ? xResThird : na, color=green, title="DIX 3")