This strategy trades based on the Dynamic Momentum Index (DMI). DMI measures the percentage deviation between price and moving averages of different lengths to determine trend.
The trading logic is:
Calculate percentage deviation of price from a long MA (e.g. 200-day) as 1st DMI
Calculate deviation from a medium MA (e.g. 50-day) as 2nd DMI
Calculate deviation from a short MA (e.g. 20-day) as 3rd DMI
When 3rd DMI is higher than 1st DMI, bearish. When 3rd DMI is lower than 2nd DMI, bullish.
Trade signals generated based on DMI relationship
By comparing relative strength dynamically across MA periods, DMI aims to identify trend turning points. Parameters can be optimized for different cycles.
DMI combines multi-period lookback for robustness
Compares relative strength vs. absolute levels
Flexible MA periods for market adaption
DMI has lag and may miss reversals
Careful optimization of period parameters
Prone to multiple false signals
DMI judges turning points by comparing multi-MA period strength dynamics. Optimization can suit different market environments. But lag limitations necessitate additional filters.
/*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")