Author: Copyright � 2004, MetaQuotes Software Corp.
gator

The "Gator" indicator is a momentum-based visual tool designed to help traders identify the strength and direction of market trends by analyzing the relationship between different moving averages. Rather than looking at raw price action, it focuses on the "velocity" or distance between three distinct layers of data, which are metaphorically described as the Jaws, Teeth, and Lips of a predator.

Core Logic and Methodology

The script operates by calculating several Moving Averages (MAs) with different lengths and time offsets. By comparing these averages against one another, the indicator creates a multi-layered visualization:

  • Layered Momentum: The logic calculates the difference between two moving averages to determine market momentum. For example, it compares a "faster" average to a "slower" one. If the distance between them is widening, it suggests strengthening momentum; if it is narrowing, it suggests a weakening trend.
  • Directional Filtering: The indicator separates these calculations into "Up" and "Down" movements. It determines whether the market is leaning toward an upward push or a downward pull, allowing traders to see which side of the market has the current advantage.
  • Trend Velocity (Color Coding): To make the data easy to read at a glance, the script employs a dynamic color-switching logic based on the change between consecutive bars:
    • Increasing Momentum: When the distance between averages grows compared to the previous bar, the indicator highlights this with one specific color (Green).
    • Decreasing Momentum: When the distance shrinks or reverses, the indicator switches to a different color (Red).

Visual Representation

Instead of a single line, the Gator provides a histogram-style visual in a separate window below the main price chart. This allows traders to:

  1. Identify Trend Strength: A large expansion in the histogram bars indicates a powerful move in the market.
  2. Detect Exhaustion: When the colors switch from green to red (or vice versa) while the trend is still moving, it can signal that the momentum is slowing down, potentially alerting the trader to a coming reversal or consolidation.
  3. Analyze Market Structure: By observing the interaction between the "Jaws," "Teeth," and "Lips" layers, traders can get a sense of how different timeframes are interacting—essentially seeing if a short-term move is supported by a longer-term trend.

Summary for Traders

In essence, this script acts as a momentum gauge. It simplifies complex moving average math into a visual "pulse," showing you not just where the price is going, but how fast it is getting there and whether that speed is accelerating or decelerating.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
9 Views
0 Downloads
0 Favorites
gator
//+------------------------------------------------------------------+
//|                                                        Gator.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"
//********************************************************************
// Attention! Following correlations must abide:
// 1.ExtJawsPeriod>ExtTeethPeriod>ExtLipsPeriod;
// 2.ExtJawsShift>ExtTeethShift>ExtLipsShift;
// 3.ExtJawsPeriod>ExtJawsShift;
// 4.ExtTeethPeriod>ExtTeethShift;
// 5.ExtLipsPeriod>ExtLipsShift.
//********************************************************************
//---- indicator settings
#property  indicator_separate_window
#property indicator_buffers 6
#property indicator_color1 Black
#property indicator_color2 Red
#property indicator_color3 Green
#property indicator_color4 Black
#property indicator_color5 Red
#property indicator_color6 Green
//---- input parameters
extern int ExtJawsPeriod=13;
extern int ExtJawsShift=8;
extern int ExtTeethPeriod=8;
extern int ExtTeethShift=5;
extern int ExtLipsPeriod=5;
extern int ExtLipsShift=3;
extern int ExtMAMethod=2;
extern int ExtAppliedPrice=PRICE_MEDIAN;
//---- indicator buffers
double ExtUpBuffer[];
double ExtUpRedBuffer[];
double ExtUpGreenBuffer[];
double ExtDownBuffer[];
double ExtDownRedBuffer[];
double ExtDownGreenBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicator buffers mapping
   SetIndexBuffer(0,ExtUpBuffer);
   SetIndexBuffer(1,ExtUpRedBuffer);
   SetIndexBuffer(2,ExtUpGreenBuffer);
   SetIndexBuffer(3,ExtDownBuffer);
   SetIndexBuffer(4,ExtDownRedBuffer);
   SetIndexBuffer(5,ExtDownGreenBuffer);
//----
   IndicatorDigits(Digits+1);
//---- sets first bar from what index will be drawn
   SetIndexDrawBegin(1,ExtJawsPeriod+ExtJawsShift-ExtTeethShift);
   SetIndexDrawBegin(2,ExtJawsPeriod+ExtJawsShift-ExtTeethShift);
   SetIndexDrawBegin(4,ExtTeethPeriod+ExtTeethShift-ExtLipsShift);
   SetIndexDrawBegin(5,ExtTeethPeriod+ExtTeethShift-ExtLipsShift);
//---- line shifts when drawing
   SetIndexShift(0,ExtTeethShift);
   SetIndexShift(1,ExtTeethShift);
   SetIndexShift(2,ExtTeethShift);
   SetIndexShift(3,ExtLipsShift);
   SetIndexShift(4,ExtLipsShift);
   SetIndexShift(5,ExtLipsShift);
//---- drawing settings
   SetIndexStyle(0,DRAW_NONE);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexStyle(2,DRAW_HISTOGRAM);
   SetIndexStyle(3,DRAW_NONE);
   SetIndexStyle(4,DRAW_HISTOGRAM);
   SetIndexStyle(5,DRAW_HISTOGRAM);
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("Gator("+ExtJawsPeriod+","+ExtTeethPeriod+","+ExtLipsPeriod+")");
   SetIndexLabel(0,"GatorUp");
   SetIndexLabel(1,NULL);
   SetIndexLabel(2,NULL);
   SetIndexLabel(3,"GatorDown");
   SetIndexLabel(4,NULL);
   SetIndexLabel(5,NULL);
//---- sets drawing line empty value
   SetIndexEmptyValue(1,0.0);
   SetIndexEmptyValue(2,0.0);
   SetIndexEmptyValue(4,0.0);
   SetIndexEmptyValue(5,0.0);
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Gator Oscillator                                                 |
//+------------------------------------------------------------------+
int start()
  {
   int    i,nLimit;
   double dPrev,dCurrent; 
//---- bars count that does not changed after last indicator launch.
   int    nCountedBars=IndicatorCounted();
//---- last counted bar will be recounted
   if(nCountedBars<=ExtTeethPeriod+ExtTeethShift-ExtLipsShift)
      nLimit=Bars-(ExtTeethPeriod+ExtTeethShift-ExtLipsShift);
   else
      nLimit=Bars-nCountedBars-1;
//---- moving averages absolute difference
   for(i=0; i<nLimit+1; i++)
     {
      dCurrent=iMA(NULL,0,ExtTeethPeriod,ExtTeethShift-ExtLipsShift,ExtMAMethod,ExtAppliedPrice,i)-
               iMA(NULL,0,ExtLipsPeriod,0,ExtMAMethod,ExtAppliedPrice,i);
      if(dCurrent<=0.0) ExtDownBuffer[i]=dCurrent;
      else              ExtDownBuffer[i]=-dCurrent;
     }
//---- dispatch values between 2 lower buffers
   for(i=nLimit-1; i>=0; i--)
     {
      dPrev=ExtDownBuffer[i+1];
      dCurrent=ExtDownBuffer[i];
      if(dCurrent<dPrev) 
        {
         ExtDownRedBuffer[i]=0.0;
         ExtDownGreenBuffer[i]=dCurrent;
        }
      if(dCurrent>dPrev)
        {
         ExtDownRedBuffer[i]=dCurrent;
         ExtDownGreenBuffer[i]=0.0;
        }
      //---- arbitrage
      if(dCurrent==dPrev)
        {
         if(ExtDownRedBuffer[i+1]<0.0) ExtDownRedBuffer[i]=dCurrent;
         else                          ExtDownGreenBuffer[i]=dCurrent;
        }
     }
//---- last counted bar will be recounted
   if(nCountedBars<=ExtJawsPeriod+ExtJawsShift-ExtTeethShift)
      nLimit=Bars-(ExtJawsPeriod+ExtJawsShift-ExtTeethShift);
   else
      nLimit=Bars-nCountedBars-1;
//---- moving averages absolute difference
   for(i=0; i<nLimit+1; i++)
     {
      dCurrent=iMA(NULL,0,ExtJawsPeriod,ExtJawsShift-ExtTeethShift,ExtMAMethod,ExtAppliedPrice,i)-
                   iMA(NULL,0,ExtTeethPeriod,0,ExtMAMethod,ExtAppliedPrice,i);
      if(dCurrent>=0.0) ExtUpBuffer[i]=dCurrent;
      else              ExtUpBuffer[i]=-dCurrent;
     }
//---- dispatch values between 2 upper buffers
   for(i=nLimit-1; i>=0; i--)
     {
      dPrev=ExtUpBuffer[i+1];
      dCurrent=ExtUpBuffer[i];
      if(dCurrent>dPrev) 
        {
         ExtUpRedBuffer[i]=0.0;
         ExtUpGreenBuffer[i]=dCurrent;
        }
      if(dCurrent<dPrev) 
        {
         ExtUpRedBuffer[i]=dCurrent;
         ExtUpGreenBuffer[i]=0.0;
        }
      //---- arbitrage
      if(dCurrent==dPrev)
        {
         if(ExtUpGreenBuffer[i+1]>0.0) ExtUpGreenBuffer[i]=dCurrent;
         else                          ExtUpRedBuffer[i]=dCurrent;
        }
     }
//---- done
   return(0);
  }
//+------------------------------------------------------------------+

Comments