The Accelerator Oscillator or abbreviated by AC is a technical indicator created by Bill Williams. This indicator helps traders to determine shifts in momentum. It is built from the foundation of the Awesome Oscillator or AO and rates the variation between that indicator and its 5-period moving average, essentially indicating how promptly the AO changes and forecasting the next trend. If the AC is positive, the upward momentum is expected to continue. On the other hand, if the AC is negative, the downward momentum may remain. The bars in the histogram have two colors: red for a bearish trend and green for a bullish trend. 

In this guide, we will go through how to detect a buy and a sell signal with the Accelerator Oscillator and explain to you how to store the data points and how to retrieve them. MQL4 Accelerator Oscillator function retrieves the indicator’s data point, unlike MQL5, which requires the data to be stored in the buffer and in a declared “double type” array. It may seem confusing, but it is actually not. We will explain step by step this MQL5 specific feature. And finally, we will show you a practical example of usage.

How does the indicator signal work for the Accelerator Oscillator?

Before we dive into the Accelerator Oscillator code implementation, let us explain the buy and sell signals interpretation. As this indicator is an oscillator, the signal will be mainly derived from comparing the previous bar reading from the current one to project and anticipate the market movement.

Buy signal

A buy signal is initiated if the Accelerator Oscillator crosses the middle section above zero and the current bar rises above the previous one.

A buy signal is initiated if the Accelerator Oscillator crosses the middle section above zero and the current bar rises above the previous one.

An alternative buy signal that may occur from a reversal trend is a green bar that is below the middle section that starts to approach the zero level. If the current bar is closer to the middle section than the previous one, it indicates a possible reversal.

An alternative buy signal that may occur from a reversal trend is a green bar that is below the middle section that starts to approach the zero level.


Sell signal

A sell signal is materialized if the Accelerator Oscillator bar crosses below zero and that the current bar stays below the previous bar.

A sell signal is materialized if the Accelerator Oscillator bar crosses below zero and that the current bar stays below the previous bar.

A bullish reversal may occur if the Accelerator Oscillator bar value subsequently falls from the previous bars. If red bars are approaching the middle section, a signal may be initiated.

A bullish reversal may occur if the Accelerator Oscillator bar value subsequently falls from the previous bars.

How does the Accelerator Oscillator store its data points?

The Accelerator Oscillator keeps its data point in an indicator buffer which is a dynamic array. The size of the array is managed automatically by MetaTrader at its initialization. An indicator buffer is by definition a time-series array and therefore has the unique feature of reverse indexing. It means that the array is sorted by descending where the most recent data point is on the left side of the array. Time-series is used to store historical data and include the time information.

Therefore, the time-series element with index zero contains the latest quote of a symbol. For instance, an indicator on the daily timeframe will have the current price at index zero and yesterday’s data at the position index one (Fig.127).

Indicator data points array
Fig.127 Indicator data points array 

MQL5

To access the Accelerator Oscillator data, MQL5 requires the use of the CopyBuffer() function. This method does not apply to MQL4 as the MQL4 indicators function directly returns the value of the Oscillator data point instead of the handle. The following parameters should be provided:

  1. Provide the handle that is returned by the iAC() function
  2. Provide the buffer number. You may provide zero as the default value.
  3. Provide the start position. You may provide zero to retrieve from the most recent data point. This number represents the index where zero is the most recent data point, and one is the previous data point.
  4. Specify the number of data points to get from the iAC() function.
  5. Provide the variable where the data will be stored. The variable is a double type.

How to retrieve Accelerator Oscillator data with CopyBuffer() function?

  1. Declare a variable for the handle: int IndicatorHandle = iAC();
  2. Declare a variable to store indicator data: double ac_indicator;
  3. Copy the data to the indicator variable and retrieve data points
    1. CopyBuffer(IndicatorHandle, 0, 0, 100, ac_indicator);
    2. Retrieve Accelerator Oscillator data point with ac_indicator[0], ac_indicator[1].

CopyBuffer() Function
Fig.128 CopyBuffer() Function

How to access the indicator data?

MQL4

The iAC() function will return the bar value according to these three parameters:

  1. The symbol of the traded instrument. You may provide a string such as EURUSD or use the function Symbol() to retrieve the symbol from the chart where the Expert Advisor is attached to.
  2. Provide the time frame using the enumeration value from the constant ENUM_TIMEFRAMES, for instance:
    1. PERIOD_CURRENT, for the current timeframe from the chart,
    2. PERIOD_M1, for the one-minute timeframe,
    3. PERIOD_D1, for the daily timeframe.
  3. Provide the index of the indicator buffer where zero is the latest data point and one the previous data point.

MQL4 Accelerator Oscillator function
Fig.129 MQL4 Accelerator Oscillator function

MQL5

When calling the iAC() function, the function will create the Accelerator Oscillator in the MetaTrader global cache and returns its handle according to these provided parameters:

  1. The symbol of the traded instrument. You may provide a string such as EURUSD, or you can use the function Symbol() to get the symbol from the chart where the Expert Advisor is attached to.
  2. Provide the time frame of the data point to extract using the enumeration value from the constant ENUM_TIMEFRAMES:
    1. PERIOD_CURRENT, to get data points from the current timeframe from the chart to which the Expert Advisor is attached to,
    2. PERIOD_M1, for the one-minute timeframe,
    3. PERIOD_D1, for the daily timeframe.

Note that to retrieve data points from the iAC() function, you need to use it in combination with the function CopyBuffer().

MQL5 Accelerator Oscillator function
Fig.130 MQL5 Accelerator Oscillator function

Practical case

MQL5

Fig.131 demonstrates the use of the Accelerator Oscillator to generate a simple signal comparing the previous oscillator bar with the current bar.

Line 40: Declare the indicator handle and assign the content returned from the function iAC().

Line 41: Declare the indicator array that will store data points.

Line 43: Get the latest 100 bars and store them in the ac_indicator array.

Line 45 – 51: Conditional statement to compare the current bar with the previous bar to determine an action to take for each condition.

Compare Accelerator Oscillator current bar with the previous bar in MQL5
Fig.131 Compare Accelerator Oscillator current bar with the previous bar in MQL5

MQL4

Fig.132 demonstrates the use of the Accelerator Oscillator to create a simple signal comparing the previous oscillator bar with the current bar.

Line 56: Declare the Accelerator Oscillator previous bar and collect data from the function iAC()

Line 57: Declare the Accelerator Oscillator current bar and collect data from the function iAC().

Line 59 – 65: Conditional statement to compare the current bar with the previous bar to determine which instruction to execute according to the outcome of the IF statement.

Compare Accelerator Oscillator current bar with the previous bar in MQL4.
Fig.132 Compare Accelerator Oscillator current bar with the previous bar in MQL4.

 

Leave a Reply

  +  77  =  83