ADX and MACD Indicators based Trading Strategy

Author: ChaoZhang, Date: 2023-12-13 15:45:24



The strategy is named “Trend Following Strategy Based on ADX and MACD Indicators”. It utilizes Average Directional Movement Index (ADX) to determine the trend direction and strength, combined with the trading signals from Moving Average Convergence Divergence (MACD), to implement trend following trades. It will establish long or short positions only when ADX indicates a strong trend and MACD gives out trading signals.

Strategy Logic

The strategy calculates the ADX and +DI, -DI lines to judge market trend direction and intensity. When +DI line crosses above -DI, it is an uptrend; when -DI drops below +DI, it is a downtrend. Additionally, when ADX reading is above 20, it indicates the trend is strong enough. The strategy then takes MACD indicator’s difference value (macdline) and signal line (signalline) crossings as buy and sell signals, to carry out trend following trades.

Specifically, the trading signals logic is:

Long signal: +DI > -DI and MACD difference line crosses above signal line
Short signal: -DI > +DI and MACD difference line crosses below signal line

With this logic, the strategy is able to capture optimal entry timing within strong trends.


The biggest advantage of this strategy is that it takes both trend judgment and entry timing selection into consideration, allowing traders to find relatively good entry points when there is a strong directional market. This greatly improves the stability and profitability of the system.

In addition, a stop loss logic is also implemented. It will cut losses actively if the position loss exceeds user defined stop loss price. This is also a highlight of the strategy.


Although the strategy has some merits, there are still risks to be awared of:

  1. The trading signals composed of ADX and MACD may fail or give false signals in certain market situations, incurring unnecessary losses.

  2. The user defined stop loss price could be penetrated, leading to losses beyond expectation.

  3. Too many ineffective trades may occur in ranging markets, consuming transaction costs.

To mitigate these risks, parameters optimization of ADX and MACD is recommended, as well as implementing strict money management rules. Stop loss logic should also be adjusted accordingly in different market environments.

Enhancement Directions

There is still room for enhancement on this strategy:

  1. More indicators could be introduced to form stronger trading signals, e.g. combining volatility index to limit trades.

  2. ADX and MACD parameters could be auto optimized via machine learning.

  3. An adaptive stop loss mechanism can be established for dynamic tracking of market fluctuation.

These methods may help to further improve the stability and profitability of the strategy.


In conclusion, the Trend Following Strategy Based on ADX and MACD Indicators has merits in determining trend direction, finding optimal entry timing, setting stop loss logic etc, making it a considerable trading system. Given proper parameters tuning and risk control, it is capable of harvesting decent investment returns. But traders should still be cautious of the potential risks, and closely monitor the changing market environments. With systemic monitoring and enhancement, the strategy has the potential to achieve sustainable alpha.

start: 2022-12-06 00:00:00
end: 2023-12-12 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]

strategy("TUE ADX/MACD Confluence V1.0", overlay=true)

showsignals = input(true, title="Show BUY/SELL Signals")
showcandlecolors = input(true, title="Show Candle Colors")
length = input(14, title="ADX Length")
smoothing = input(10, title="ADX Smoothing")
macdsource = input(close, title="MACD Source")
macdfast = input(12, title="MACD Fast Length")
macdslow = input(26, title="MACD Slow Length")
macdsignal = input(9, title="MACD Signal Length")
colorup = input(, title="Up Candle Color")
colordown = input(, title="Down Candle Color")

/////////////////////////////////////////////////////////////////////////////////////////////// ADX AND MACD CALC
[diplus, diminus, adx] = ta.dmi(length, smoothing)

[macdline, signalline, histline] = ta.macd(macdsource, macdfast, macdslow, macdsignal)

//////////////////////////////////////////////////////////////////////////////////////////////TRADE CALC

longcheck = diplus > diminus and macdline > signalline
shortcheck = diminus > diplus and signalline > macdline

int trade = 0

//Open from nothing

if trade == 0 and longcheck
    trade := 1

else if trade == 0 and shortcheck
    trade := -1

else if trade == 1 and shortcheck
    trade := -1
else if trade == -1 and longcheck
    trade := 1
//Keep status quo until crossover

    trade := trade[1]


colors = longcheck ? colorup : shortcheck ? colordown : color.white

plotcandle(open, high, low, close, color = showcandlecolors ? colors : na)

plotshape(trade[1] != 1 and trade == 1 and showsignals, style=shape.labelup, text='BUY', textcolor=color.white,, size=size.small, location=location.belowbar)
plotshape(trade[1] != -1 and trade == -1 and showsignals, style=shape.labeldown, text='SELL', textcolor=color.white,, size=size.small, location=location.abovebar)

///////////////////////////////////////////////////////////////////////////////////////////// ALERTS

// Add Stop Loss
stopLossPrice = input(100, title="Stop Loss Price")

if trade == 1
    strategy.entry("Long", strategy.long)

if trade == -1
    strategy.entry("Short", strategy.short)

if trade == 1 and close < close[1] - stopLossPrice

if trade == -1 and close > close[1] + stopLossPrice