The Gator or Alligator is an indicator that comprises three lines of smoothed moving averages computed based on a simple moving average of five, eight, and thirteen periods. Each line has a name — jaw, teeth, and lips — for the 5-period, 8-period, and 13-period, respectively. The indicator is not that different from three simple moving averages (SMA), and signals are recognized by SMA crossover or convergence and divergence between the lines.

The Alligator indicator employs three smoothed moving averages: 5-period, 8-period, and 13-period, which are all Fibonacci numbers. The initial smoothed average is computed with a simple moving average (SMA), adding extra smoothed averages that decelerate indicator turns (Fig.206).

Alligator indicator formula
Fig.206 Alligator indicator formula

In this guide, we will go through how to use the Alligator indicator to set a buy and a sell signal and explain the notion used in MQL4 and MQL5 to collect data points. MQL4 Gator function retrieves the indicator’s data point, unlike MQL5, which requires the data to be stored in the indicator 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 particularity. To conclude, we will demonstrate to you a practical example of usage of the Alligator indicator.

How does the indicator signal work for the Alligator?

Before we dive into the Alligator code implementation, let us explain the most common buy and sell signals interpretation of this indicator. As this indicator is a trend-following derived from the price averaging, the signal will be very similar to a combination of three simple moving averages to determine entry and exit. There are a few strategies on how to use the Alligator to detect a buy or sell entry. In this guide, we will highlight the two most frequently used to determine a buy and sell entry into a trend continuation.

Buy signal

Buy signal

A buy signal can be identified by the cross of the fast line represented by the jaw (blue line) under both the lips (green line) and the teeth (red line). Once the Alligator indicator is aligned with the lips on top followed by the teeth and jaws below, an upside trend is likely to continue.

Sell signal

Sell signal

A sell signal is when the Alligator jaw (blue line) crossover both the lips (green line) and the teeth (red line). When the Alligator is upside down with the jaw on top and the lips at the bottom, a downside trend continuation is likely to persist.

How does the Alligator indicator store its data points?

The Alligator indicator keeps its data point in an indicator buffer which is a dynamic array. The size of the array is controlled by MetaTrader at the Expert Advisor initialization. An indicator buffer is a time-series array; hence, it has a unique feature of reverse indexing. It means that the array is sorted by the last data points being the latest. Timeseries are used to store historical data and include the time information.

Consequently, the time-series element with index zero contains the latest data point of an indicator. For instance, an indicator on the daily timeframe will have the current data point at index zero and yesterday’s data at the position index one. Note that the Alligator has the particularity to have three buffers, one for the Jawline, one for the teeth line, and another for the Lips line. The Jawline has a buffer index of zero, one for the teeth line and two for the Lips line (Fig.207).

Indicator data points array 
Fig.207 Indicator data points array 

MQL5

To access the Alligator 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 Alligator data point instead of the indicator handle. The following parameters should be provided to collect the iAlligator() data points in MQL5.

  1. Provide the handle that is returned by the iAlligator() function.
  2. Provide the buffer number. You may provide zero to collect the Jawline e value, one for the teeth line value and two for the Lips line value. The Jawline corresponds to the 5-period, the teeth line for the 8-period, and the Lips for the 13-period.
  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 iAlligator() function.
  5. Provide the variable where the data will be stored. The variable must be a double type.

How to retrieve Alligator data with CopyBuffer() function?

  1. Declare a variable for the handle: int IndicatorHandle = iAlligator();
  2. Declare a variable to store indicator data: double alli_indicator;
  3. Copy the data to the indicator variable and retrieve data points
    1. CopyBuffer(IndicatorHandle, 0, 0, 100, alli_indicator_jaw_5); //jaw,
    2. CopyBuffer(IndicatorHandle, 0, 1, 100, alli_indicator_teeth_8); //teeth,
    3. CopyBuffer(IndicatorHandle, 0, 2, 100, alli_indicator_lips_13); //lips,
    4. Retrieve Alligator data point with for instance: alli_indicator_jaw_5[0], alli_indicator_jaw_5[1], alli_indicator_lips_13[2], alli_indicator_teeth_8[0].

CopyBuffer() Function
Fig.208 CopyBuffer() Function

How to access the Alligator indicator data?

MQL4

Note: MQL4 has two indicators for the Alligator, the iAlligator() and the derived indicator iGator(). The iGator() indicator is an oscillator derived from the Alligator indicator computation and provides the exact same signal as the original simple moving average (SMA) based indicator. The only difference is that the iGator() displays the data as an oscillator from the convergence and divergence relationship between the three SMA lines. In this guide, we will only cover the original indicator developed by Bill Williams.

The iAlligator() function will return the data point value according to the following 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 (Note that the default period is 20-period:
    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 Jawline period; the default value is 5-period.
  4. Provide the Jawline shift, and the default value is zero.
  5. Provide the Teeth line period; the default value is 8-period.
  6. Provide the Teeth line shift; the default value is zero.
  7. Provide the Lips line period; the default value is 13-period.
  8. Provide the Lips line shift; the default value is zero.
  9. Specify the moving average method with the enumeration value from the constant ENUM_MA_METHOD, for instance:
    1. MODE_SMA, for the simple averaging.
    2. MODE_EMA, for the exponential averaging.
    3. MODE_SMMA, for the smoothed average.
    4. MODE_LWMA, for the linear-weighted averaging.
  10. Specify the applied price using the enumeration value from the constant ENUM_APPLIED_PRICE, for instance:
    1. PRICE_CLOSE, for value, computed based on close price.
    2. PRICE_OPEN, for value, computed based on open price.
    3. PRICE_HIGH, for value, computed based on highs.
    4. PRICE_LOW, for value, computed based on lows.
  11. Finally, provide which data source to return with the indicator line identifier:
    1. MODE_GATORJAW, for the Jawline (blue).
    2. MODE_GATORTEETH, for the teeth line (red).
    3. MODE_GATORLIPS, for the lips (green).
  12. Provide the index of the value from the indicator array. The most recent data points are zero, while the previous is one.

MQL4 Alligator function
Fig.209 MQL4 Alligator function

MQL5

When calling the iAlligator() function, MQL5 will create the Alligator indicator in the MetaTrader global cache and returns its handle according to the following 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. 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 time frame.
  3. Provide the Jawline period; the default value is 5-period.
  4. Provide the Jawline shift; the default value is zero.
  5. Provide the Teeth line period; the default value is 8-period.
  6. Provide the Teeth line shift; the default value is zero.
  7. Provide the Lips line period; the default value is 13-period.
  8. Provide the Lips line shift; the default value is zero.
  9. Specify the moving average method with the enumeration value from the constant ENUM_MA_METHOD, for instance:
    1. MODE_SMA, for the simple averaging.
    2. MODE_EMA, for the exponential averaging.
    3. MODE_SMMA, for the smoothed average.
    4. MODE_LWMA, for the linear-weighted averaging.
  10. Specify the applied price using the enumeration value from the constant ENUM_APPLIED_PRICE, for instance:
    1. PRICE_CLOSE, for value, computed based on close price.
    2. PRICE_OPEN, for value, computed based on open price.
    3. PRICE_HIGH, for value, computed based on highs.
    4. PRICE_LOW, for value, computed based on lows.

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

MQL5 Alligator function
Fig.210 MQL5 Alligator function

Practical case

MQL5

Fig.211 demonstrates the use of the Alligator indicator to generate a simple trend-following signal to trade a momentum continuation pattern by identifying the Alligator Jaw and Lips line crossover.

Line 68: Declare the indicator handle and assign the content returned from the function iAlligator().

Line 69 – 71: Declare the indicator array that will store data points for each Alligator Line, Jaw, teeth, and Lips.

Line 73 – 75: Collect the Alligator data points for each indicator line and store the data in the respective variables that are the double arrays: alli_indicator_jaw, alli_indicator_teeth, and alli_indicator_lips.

Line 77 – 91: Conditional statement to identify the Jawline and Lips line crossover to define buy and sell signals.

Alligator trend-following signal example with MQL4
Fig.211 Alligator trend-following signal example with MQL4

MQL4

Fig.212 demonstrates the use of the Alligator indicator to create a simple trend-following signal to trade a momentum continuation pattern by identifying the Alligator Jaw and Lips line crossover.

Line 95 – 100: Declare the indicator arrays and assign the content returned from the function iAlligator() for each Jaw and Lips line. Note the last parameter from the function iAlligator(); the number represents the index of the array where zero is the most recent data point and one the previous data points.

Line 102 – 114: Conditional statement to identify the Jawline, and Lips line crossover to define buy and sell signals.

Alligator trend-following signal example with MQL5
Fig.212 Alligator trend-following signal example with MQL5

Leave a Reply

  +  29  =  30