iMAOnArray

Calculates the Moving Average indicator on data stored in an array and returns its value.

Function Signature

double iMAOnArray(
  double        array[],      // Array with data
  int           total,        // Number of elements (0 for whole array)
  int           ma_period,    // Averaging period
  int           ma_shift,     // MA shift
  int           ma_method,    // MA averaging method (ENUM_MA_METHOD)
  int           shift         // Shift relative to current bar
);

Parameters

  • array[]: Input array containing the data.
  • total: The number of elements to consider in the array. 0 indicates the entire array.
  • ma_period: The period for the Moving Average calculation.
  • ma_shift: The shift of the Moving Average line relative to the chart timeframe.
  • ma_method: The method used for averaging. Must be one of the ENUM_MA_METHOD enumeration values.
  • shift: The index of the value to retrieve from the indicator buffer, representing the number of periods ago from the current bar.
  • Return Value

    A double representing the calculated Moving Average indicator value.

    Notes

  • Unlike iMA(), iMAOnArray() does not accept symbol, timeframe, or applied price. Data must be pre-prepared.
  • The indicator calculates from left to right. Use ArraySetAsSeries() for right-to-left access.
  • Related Functions

  • iMA()
  • iOsMA()
  • MA Methods (ENUM_MA_METHOD)

  • MODE_SMA (Simple Moving Average)
  • MODE_EMA (Exponential Moving Average)
  • MODE_SMMA (Smoothed Moving Average)
  • MODE_LWMA (Linear Weighted Moving Average)
  • Example

    double macurrent = iMAOnArray(ExtBuffer, 0, 5, 0, MODE_LWMA, 0);
    double macurrentslow = iMAOnArray(ExtBuffer, 0, 10, 0, MODE_LWMA, 0);
    double maprev = iMAOnArray(ExtBuffer, 0, 5, 0, MODE_LWMA, 1);
    double maprevslow = iMAOnArray(ExtBuffer, 0, 10, 0, MODE_LWMA, 1);

    if (maprev < maprevslow && macurrent >= macurrentslow) Alert("crossing up");