How to Setup MACD Signals
Problem
You want to use the Moving Average Convergence Divergence (MACD) indicator to identify trend changes, generate entry/exit signals, or confirm momentum in your trading algorithm.
Prerequisites
- Basic understanding of entry conditions
- Familiarity with trend indicators
Understanding MACD
What is MACD?
MACD is a trend-following momentum indicator that shows the relationship between two exponential moving averages.
Components:
- MACD Line: 12 EMA - 26 EMA
- Signal Line: 9 EMA of MACD Line
- Histogram: MACD Line - Signal Line
Standard Parameters: 12, 26, 9
MACD Signals
| Signal | Interpretation | Action |
|---|---|---|
| MACD crosses above Signal | Bullish crossover | Consider buying |
| MACD crosses below Signal | Bearish crossover | Consider selling |
| Histogram increasing | Momentum strengthening | Trend continuation |
| Histogram decreasing | Momentum weakening | Potential reversal |
| MACD crosses above 0 | Bullish momentum | Uptrend confirmation |
| MACD crosses below 0 | Bearish momentum | Downtrend confirmation |
MACD vs Zero Line
- Above 0: Bullish momentum (12 EMA > 26 EMA)
- Below 0: Bearish momentum (12 EMA < 26 EMA)
- Crossing 0: Major trend change
Solution
Example 1: Basic MACD Signal Line Crossover (Long)
Enter long when MACD crosses above the signal line.
{
"entryConditions": {
"positionType": "long",
"logicalOperator": "AND",
"conditions": [
{
"type": "indicator_indicator",
"indicator1": "MACD",
"period1": 12,
"indicator2": "MACD_Signal",
"period2": 9,
"comparison": "crosses_above"
}
]
}
}
Explanation: This is the most basic MACD strategy - enter long when the MACD line crosses above the signal line, indicating bullish momentum.
Example 2: MACD Signal Line Crossover (Short)
Enter short when MACD crosses below the signal line.
{
"entryConditions": {
"positionType": "short",
"logicalOperator": "AND",
"conditions": [
{
"type": "indicator_indicator",
"indicator1": "MACD",
"period1": 12,
"indicator2": "MACD_Signal",
"period2": 9,
"comparison": "crosses_below"
}
]
}
}
Explanation: Enter short when the MACD line crosses below the signal line, indicating bearish momentum.
Example 3: MACD Zero Line Cross (Long)
Enter long when MACD crosses above zero line.
{
"entryConditions": {
"positionType": "long",
"logicalOperator": "AND",
"conditions": [
{
"type": "indicator_value",
"indicator": "MACD",
"period": 12,
"comparison": "crosses_above",
"value": 0
}
]
}
}
Explanation: MACD crossing above zero indicates the 12 EMA has crossed above the 26 EMA, signaling a potential uptrend.
Example 4: MACD with Trend Filter
Only take MACD signals in the direction of the major trend.
{
"entryConditions": {
"positionType": "long",
"logicalOperator": "AND",
"conditions": [
{
"type": "price_indicator",
"priceType": "close",
"indicator": "EMA",
"period": 200,
"comparison": "above"
},
{
"type": "indicator_indicator",
"indicator1": "MACD",
"period1": 12,
"indicator2": "MACD_Signal",
"period2": 9,
"comparison": "crosses_above"
}
]
}
}
Explanation: This strategy combines:
- Price above 200 EMA (uptrend filter)
- MACD bullish crossover
This filters out counter-trend signals, improving win rate.
Example 5: MACD Histogram Reversal
Enter when histogram changes from negative to positive.
{
"entryConditions": {
"positionType": "long",
"logicalOperator": "AND",
"conditions": [
{
"type": "indicator_value",
"indicator": "MACD_Histogram",
"period": 12,
"comparison": "crosses_above",
"value": 0
}
]
}
}
Explanation: The histogram crossing above zero indicates the MACD line has crossed above the signal line, but using the histogram directly can provide earlier signals.
Example 6: MACD Below Zero Crossover (Oversold Bounce)
Enter long when MACD crosses above signal while both are below zero.
{
"entryConditions": {
"positionType": "long",
"logicalOperator": "AND",
"conditions": [
{
"type": "indicator_value",
"indicator": "MACD",
"period": 12,
"comparison": "below",
"value": 0
},
{
"type": "indicator_indicator",
"indicator1": "MACD",
"period1": 12,
"indicator2": "MACD_Signal",
"period2": 9,
"comparison": "crosses_above"
}
]
}
}
Explanation: This strategy looks for bullish crossovers in oversold territory (below zero), which can signal strong reversals.
Example 7: MACD Divergence Setup
Identify potential divergences by monitoring MACD behavior.
{
"entryConditions": {
"positionType": "long",
"logicalOperator": "AND",
"conditions": [
{
"type": "indicator_value",
"indicator": "MACD",
"period": 12,
"comparison": "below",
"value": 0
},
{
"type": "indicator_indicator",
"indicator1": "MACD",
"period1": 12,
"indicator2": "MACD_Signal",
"period2": 9,
"comparison": "crosses_above"
},
{
"type": "indicator_value",
"indicator": "RSI",
"period": 14,
"comparison": "below",
"value": 40
}
]
}
}
Explanation: Bullish divergence often occurs when:
- Price makes lower lows
- MACD makes higher lows
- MACD crosses above signal line
- RSI confirms oversold condition
Example 8: MACD Trend Following
Stay in trades while MACD remains above signal line.
{
"entryConditions": {
"positionType": "long",
"logicalOperator": "AND",
"conditions": [
{
"type": "indicator_indicator",
"indicator1": "MACD",
"period1": 12,
"indicator2": "MACD_Signal",
"period2": 9,
"comparison": "crosses_above"
}
]
},
"exitConditions": {
"customExitConditions": [
{
"type": "indicator_indicator",
"indicator1": "MACD",
"period1": 12,
"indicator2": "MACD_Signal",
"period2": 9,
"comparison": "crosses_below"
}
]
}
}
Explanation: Enter on bullish crossover, exit on bearish crossover. This keeps you in the trade for the entire trend.
Example 9: MACD with RSI Confirmation
Combine MACD with RSI for stronger signals.
{
"entryConditions": {
"positionType": "long",
"logicalOperator": "AND",
"conditions": [
{
"type": "indicator_indicator",
"indicator1": "MACD",
"period1": 12,
"indicator2": "MACD_Signal",
"period2": 9,
"comparison": "crosses_above"
},
{
"type": "indicator_value",
"indicator": "RSI",
"period": 14,
"comparison": "above",
"value": 50
}
]
}
}
Explanation: This strategy requires:
- MACD bullish crossover (trend signal)
- RSI above 50 (momentum confirmation)
Both indicators must agree, reducing false signals.
Example 10: MACD Histogram Increasing
Enter when histogram is growing (momentum strengthening).
{
"entryConditions": {
"positionType": "long",
"logicalOperator": "AND",
"conditions": [
{
"type": "indicator_value",
"indicator": "MACD_Histogram",
"period": 12,
"comparison": "above",
"value": 0
},
{
"type": "indicator_indicator",
"indicator1": "MACD",
"period1": 12,
"indicator2": "MACD_Signal",
"period2": 9,
"comparison": "above"
}
],
"confirmationCandles": 2
}
}
Explanation: This strategy looks for:
- Histogram above zero (bullish)
- MACD above signal line (bullish)
- 2 confirmation candles (momentum sustained)
This ensures the trend is established before entering.
Verification
After configuring your MACD conditions:
- Backtest the strategy to see historical performance
- Check signal frequency - MACD generates fewer signals than RSI
- Verify crossover detection - Ensure crosses are detected correctly
- Test in different market conditions - MACD works best in trending markets
- Paper trade first before going live
Troubleshooting
Problem: Too Many Whipsaws (False Signals)
Solution:
- Add trend filter (200 EMA)
- Use zero line crosses instead of signal line crosses
- Add confirmation candles (1-2)
- Combine with RSI or other indicators
- Avoid using MACD in ranging/choppy markets
Problem: Signals Too Slow
Solution:
- Use faster parameters (e.g., 5, 13, 5 instead of 12, 26, 9)
- Use histogram crosses instead of MACD/signal crosses
- Remove confirmation candles
- Consider using MACD on lower timeframes
Problem: Missing Trend Reversals
Solution:
- Watch for divergences (price vs MACD)
- Use signal line crosses instead of zero line crosses
- Combine with RSI oversold/overbought
- Add volume confirmation
Problem: MACD Not Working in Sideways Markets
Solution:
- MACD is a trend-following indicator
- Use RSI or Bollinger Bands for ranging markets
- Add a trend filter to avoid sideways periods
- Consider switching strategies based on market conditions
Best Practices
-
Understand market conditions:
- MACD works best in trending markets
- Generates false signals in ranging markets
- Use ADX to confirm trend strength
-
Combine with other indicators:
- MACD + RSI: Trend + momentum confirmation
- MACD + Moving Averages: Trend direction filter
- MACD + Volume: Confirm signal strength
-
Watch for divergences:
- Bullish divergence: Price lower low, MACD higher low
- Bearish divergence: Price higher high, MACD lower high
- Divergences often precede reversals
-
Use different parameters:
- Standard: 12, 26, 9 (balanced)
- Fast: 5, 13, 5 (more signals, more noise)
- Slow: 19, 39, 9 (fewer signals, more reliable)
-
Signal priority:
- Zero line crosses: Major trend changes
- Signal line crosses: Entry/exit timing
- Histogram: Momentum strength
-
Exit strategies:
- Exit on opposite crossover
- Exit when histogram starts decreasing
- Use trailing stop to lock in profits