Dynamic Momentum Index Strategy
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: 1. Calculate…
Strategy Logic
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.
Advantages
DMI combines multi-period lookback for robustness
Compares relative strength vs. absolute levels
Flexible MA periods for market adaption
Risks
DMI has lag and may miss reversals
Careful optimization of period parameters
Prone to multiple false signals
Summary
DMI judges turning points by comparing multi-MA period strength dynamics. Optimization can suit different market environments. But lag limitations necessitate additional filters.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 200 | LengthFirst |
| v_input_2 | 50 | LengthSecond |
| v_input_3 | 20 | LengthThird |
| v_input_4 | true | ShowFirst |
| v_input_5 | true | ShowSecond |
| v_input_6 | true | ShowThird |
| v_input_7 | false | Trade reverse |
Source Pine Script
/*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")Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-14. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.
Build this with AgenKit
A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Dynamic-Momentum-Index-Strategy.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- Get tests, backtest, risk controls and a paper-trading switch
Understand it first
Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.
Related specs
- ADX Momentum Trend StrategyPine Script · Momentum · 10m
- Advanced Multi Indicator Trend Following and Momentum Quantitative Trading StrategyPine Script · Momentum · 1h
- Dual EMA Crossover with RSI Momentum Enhanced Trading StrategyPine Script · Momentum · 1d
- Dual EMA Momentum Trend Trading Strategy with Full Body Candle Signal SystemPine Script · Momentum · 2h
- Ergotic Momentum Direction Convergence Trading StrategyPine Script · Momentum · 1d
- VWMA ADX Momentum and Trend Based Bitcoin Long StrategyPine Script · Momentum · 1h