Author: Copyright � 2004, MetaQuotes Software Corp.
Gator_v1

This script creates a specialized visual tool designed to help traders identify market momentum and trend reversals by analyzing the relationship between different moving averages. Unlike standard indicators that might only show you a single line, this logic focuses on the "gap" or distance between various price averages to reveal the underlying strength of a move.

Core Logic and Methodology

The indicator operates by comparing three distinct layers of moving averages, which are conceptually referred to in the code as the "Jaws," "Teeth," and "Lips." Each layer represents a different timeframe of market activity:

  • The Jaws: Represent long-term trend data.
  • The Teeth: Represent medium-term price movement.
  • The Lips: Represent short-term, immediate price action.

By calculating the difference between these layers, the script identifies how quickly and forcefully the market is moving. If the gap between a short-term average and a long-term average expands, it suggests accelerating momentum; if that gap begins to shrink, it may signal that the trend is losing steam.

Visual Representation and Color Coding

To make this data easy for a human to interpret at a glance, the script translates these mathematical differences into a multi-colored histogram. The logic divides the data into two primary sections:

  1. Upward Momentum (The Upper Section): This section tracks the difference between the "Jaws" and the "Teeth." It calculates whether the long-term trend is pulling away from the medium-term price. The script uses a dual-color system here:

    • Green: Indicates increasing strength or an expansion in the trend.
    • Red: Indicates a weakening of that momentum or a contraction in the gap.
  2. Downward Momentum (The Lower Section): This section tracks the difference between the "Teeth" and the "Lips." It focuses on the relationship between medium-term trends and immediate price action. Similarly, it uses a color-coded system:

    • Green: Indicates increasing downward momentum.
    • Red: Indicates a deceleration or potential reversal in the downward move.

How to Interpret the Results

Instead of looking at raw prices, this script allows you to visualize "energy." When the colors shift, it provides a visual cue regarding whether the current market trend is gaining power or exhausting itself. By observing these changes in the histogram height and color, traders can look for potential entry points where momentum is peaking or where a reversal is beginning to form in the price action.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
10 Views
0 Downloads
0 Favorites
Gator_v1
//+------------------------------------------------------------------+
//|                                                        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