All indicators

MACD Strategy

Jul 22, 2017

Static chart image
SignalsOscillatorsMoving Averages

The MACD Strategy indicator is a trend-following tool designed to identify potential entry and exit points by combining Moving Average Convergence Divergence (MACD) crossovers with trend-filtering through an Exponential Moving Average.

Usage

The strategy generates long entries and exits based on the momentum of the MACD lines in relation to price action.

  • Long Entry: A buy signal is triggered when the MACD line crosses above the signal line, provided the 18-period EMA (labeled as sma18 in the script) is below the current high price.
  • Long Exit: The strategy closes a long position when the signal line crosses back above the MACD line, indicating a potential reversal or loss of momentum.

The script provides visual cues on the chart with "x" shapes marking buy (green) and sell (red) crossovers, alongside an 18-period EMA line to help visualize the trend filter.

Details

The script utilizes standard MACD parameters (12, 26, 9) to determine market momentum. It implements a specific logic where long trades are only considered when price is trading relatively high compared to the 18-period EMA. Although the variable is named sma18 in the code, it functions as an Exponential Moving Average (EMA). The strategy is designed with built-in alerts for both bullish and bearish crossovers to facilitate real-time monitoring.

Settings

  • MACD Parameters: The script uses hardcoded values of 12 for the fast length, 26 for the slow length, and 9 for the signal smoothing length.
  • EMA Filter: A 18-period EMA is used as a baseline trend filter for entering long positions.
  • Strategy Margins: Both long and short margins are set to 100% within the strategy properties.

FAQ

How do I interpret the crossover signals? A green cross indicates a bullish MACD crossover (MACD line moving above the signal line), while a red cross indicates a bearish crossover (signal line moving above the MACD line).

What is the purpose of the EMA line on the chart? The EMA serves as a trend filter; in this specific strategy, buy signals are only executed when the 18-period EMA is lower than the high of the current bar.

How can I access the MACD Strategy? You can get access on the LuxAlgo Library for charting platforms like TradingView, MetaTrader (MT4/MT5), and NinjaTrader for free.

Free indicator

Get free access to this indicator on the platforms below.

TradingView
NinjaTrader
MetaTrader 4/5

Unlock the entire LuxAlgo Library

Every indicator, every strategy, full charts, and complete access to Quant — our AI agent.