MQL4 iMACD Indicator

#### Overview

The iMACD function calculates the Moving Averages Convergence/Divergence (MACD) indicator and returns its value. In MetaTrader 4, MACD is typically plotted as a histogram.

#### Function Signature

double iMACD(
  string      symbol,         // Symbol name
  int         timeframe,      // Timeframe
  int         fast_ema_period,  // Fast EMA period
  int         slow_ema_period,  // Slow EMA period
  int         signal_period,    // Signal line period
  int         applied_price,    // Applied price
  int         mode,             // Line index
  int         shift           // Shift
);

#### Parameters

  • **symbol**: The name of the symbol for which the indicator is calculated. NULL indicates the current symbol.
  • **timeframe**: The timeframe of the chart. Can be any value from ENUM_TIMEFRAMES. 0 indicates the current chart's timeframe.
  • **fast_ema_period**: The averaging period for the Fast Exponential Moving Average (EMA).
  • **slow_ema_period**: The averaging period for the Slow Exponential Moving Average (EMA).
  • **signal_period**: The averaging period for the Signal Line.
  • **applied_price**: The price to be used for calculation. Refer to ENUM_APPLIED_PRICE enumeration values (e.g., PRICE_CLOSE).
  • **mode**: The index of the indicator line. 0 for MODE_MAIN (typically the MACD line or histogram), 1 for MODE_SIGNAL (the signal line).
  • **shift**: The index of the value from the indicator buffer, relative to the current bar. 0 refers to the current bar.
  • #### Return Value

    Returns the numerical value of the Moving Average of Oscillator indicator for the specified parameters.

    #### Notes

  • Some systems refer to the MACD histogram as two lines. In MetaTrader 4, it is presented as a histogram.
  • #### Related Functions

  • iOsMA
  • iOBV
  • #### Constants/Enums

  • ENUM_TIMEFRAMES: Defines available chart timeframes.
  • ENUM_APPLIED_PRICE: Defines available price types for indicator calculations.
  • Indicators line identifiers: MODE_MAIN (0), MODE_SIGNAL (1).
  • #### Example

    if(iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0) > iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0))
      return(0);