0bps

Strategy vault / Momentum

DMI Balance Buy Sell Strategy

This strategy generates buy and sell signals based on the Direction Movement Index (DMI) indicators for trend direction. It utilizes the crossover of DMI's two indicators, DMI+ and DMI-, as well as their crossover…

Author
ChaoZhang
Complexity
Starter · 31 lines
Parameters
1

IMG

Overview

This strategy generates buy and sell signals based on the Direction Movement Index (DMI) indicators for trend direction. It utilizes the crossover of DMI's two indicators, DMI+ and DMI-, as well as their crossover with ADX to determine the bullish/bearish state and trend of the market, thereby producing entry and exit signals.

Strategy Logic

The strategy mainly uses three indicators from DMI: DMI+, DMI- and ADX. DMI+ reflects the strength of an uptrend, DMI- reflects the strength of a downtrend, while ADX reflects the trend intensity.

The buy signal is triggered when DMI+ crosses over DMI- and also crosses over ADX, indicating a switch from a bearish to bullish state and an emerging trend.

The sell signal is triggered when DMI+ crosses below either DMI- or ADX, indicating weakening bullish momentum and a need to take profit.

Therefore, the strategy dynamically adjusts positions by judging market sentiment and trend changes using the crossover patterns of the DMI indicators.

Advantage Analysis

The main advantages of this strategy are:

  1. Using DMI for trend and sentiment analysis provides reliability in capturing major trends.

  2. Incorporating ADX to gauge trend strength allows more accurate identification of inflection points.

  3. The simple, clear crossover signals of DMI indicators make this strategy easy to implement.

  4. Running with the trend provides good risk control, suitable for medium- to long-term holding periods.

Risk Analysis

Several risks to note:

  1. DMI indicators have some lag, which may result in late buys and premature sells.

  2. ADX has mediocre performance in distinguishing between trends and consolidations, thus some short-term opportunities may be missed.

  3. There is some risk of holding no positions, in case persistent uptrend or downtrend occurs.

  4. Parameter optimization risks exist, which may lead to deteriorated performance in live trading.

Improvement Areas

Some ways to improve this strategy:

  1. Incorporate other indicators to spot momentum divergence, enhancing accuracy of entries and exits.

  2. Add stop-loss mechanisms to limit loss in adverse moves.

  3. Adjust parameters or introduce adaptive settings to mitigate optimization bias.

  4. Implement position sizing to dynamically adjust stakes according to trend stages.

Conclusion

This DMI trend-following strategy is simple and practical for catching major trends over medium- to long-term horizons. However, lags, empty positions, and parameter optimization risks exist. Enhancements through combining indicators, stop losses, adaptive parameters etc. can improve live performance.

Parameters

NameDefaultWhat it controls
v_input_114DMI Length

Source Pine Script

//@version=5
strategy("DMI Buy/Sell Strategy", overlay=true)

// Input for DMI
length = input(14, title="DMI Length")
adxsmoothing =14

// Calculate DMI
[diPlus, diMinus, adx] = ta.dmi(length,adxsmoothing)

// Condition for Buy Entry
buyCondition = ta.crossover(diPlus, diMinus) and ta.crossover(diPlus, adx)

// Condition for Sell Exit
sellCondition = ta.crossunder(diPlus,diMinus) or ta.crossunder(diPlus,adx)

// Execute Buy Entry on the next day's open
if buyCondition
    strategy.entry("Buy", strategy.long)

// Execute Sell Exit on the next day's open
if sellCondition
    strategy.close("Buy")

// Plotting DMI components
plot(diPlus, title="DMI+", color=color.green)
plot(diMinus, title="DMI-", color=color.red)

// Plotting ADX
plot(adx, title="ADX", color=color.blue)

Published by ChaoZhang on the FMZ strategy square · last modified 2024-02-02. 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.

in Claude Code, Cursor, Codex & 4 more
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/DMI-Balance-Buy-Sell-Strategy.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. 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

esc

Try , , or .

↑↓ move↵ open