Author: Copyright � 2004, MetaQuotes Software Corp.
alligator

This script functions as a visual technical analysis tool designed to help traders identify trends and momentum in the financial markets. It works by overlaying three distinct moving averages onto your price chart, which are themed after the "Alligator" metaphor to represent different speeds of market movement.

How the Logic Works

The script analyzes historical price data to generate three separate lines on your screen. Each line reacts differently to price changes based on its specific settings:

  • The Jaws (Slowest Movement): This represents the broadest trend. It looks at a longer period of historical data, making it less sensitive to sudden "noise" or minor price fluctuations. Its purpose is to show the overall direction of the market.
  • The Teeth (Medium Movement): This line follows the price more closely than the Jaws but still smooths out smaller ripples. It acts as a bridge between the long-term trend and immediate price action.
  • The Lips (Fastest Movement): This is the most responsive line. It reacts quickly to recent price changes, helping traders see immediate shifts in momentum.

Visual Execution and Display

To make the data readable for the user, the script employs several visual logic rules:

  1. Time Offsets: The lines are intentionally shifted backward on the chart (the "Shift" parameters). This creates a visual gap that helps traders distinguish between current price action and the underlying momentum trends.
  2. Data Filtering: The script calculates where to begin drawing each line based on its specific period length. This ensures that the lines only appear once there is enough historical data to create a meaningful average, preventing the chart from looking cluttered with inaccurate "startup" data.
  3. Smoothing Method: The logic uses a specific type of moving average (Smoothed Moving Average) applied to the median price. This ensures that the lines flow gracefully across the screen rather than jaggedly jumping with every minor tick in price.

Summary for the User

By observing the relationship between these three lines—how they cross one another, how wide they spread apart, and their overall direction—traders can visually interpret whether the market is currently trending, consolidating, or preparing for a significant move in a specific direction.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
14 Views
0 Downloads
0 Favorites
alligator
//+------------------------------------------------------------------+
//|                                                    Alligator.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Lime
//---- input parameters
extern int JawsPeriod=13;
extern int JawsShift=8;
extern int TeethPeriod=8;
extern int TeethShift=5;
extern int LipsPeriod=5;
extern int LipsShift=3;
//---- indicator buffers
double ExtBlueBuffer[];
double ExtRedBuffer[];
double ExtLimeBuffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- line shifts when drawing
   SetIndexShift(0,JawsShift);
   SetIndexShift(1,TeethShift);
   SetIndexShift(2,LipsShift);
//---- first positions skipped when drawing
   SetIndexDrawBegin(0,JawsShift+JawsPeriod);
   SetIndexDrawBegin(1,TeethShift+TeethPeriod);
   SetIndexDrawBegin(2,LipsShift+LipsPeriod);
//---- 3 indicator buffers mapping
   SetIndexBuffer(0,ExtBlueBuffer);
   SetIndexBuffer(1,ExtRedBuffer);
   SetIndexBuffer(2,ExtLimeBuffer);
//---- drawing settings
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_LINE);
//---- index labels
   SetIndexLabel(0,"Gator Jaws");
   SetIndexLabel(1,"Gator Teeth");
   SetIndexLabel(2,"Gator Lips");
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Bill Williams' Alligator                                         |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
//---- main loop
   for(int i=0; i<limit; i++)
     {
      //---- ma_shift set to 0 because SetIndexShift called abowe
      ExtBlueBuffer[i]=iMA(NULL,0,JawsPeriod,0,MODE_SMMA,PRICE_MEDIAN,i);
      ExtRedBuffer[i]=iMA(NULL,0,TeethPeriod,0,MODE_SMMA,PRICE_MEDIAN,i);
      ExtLimeBuffer[i]=iMA(NULL,0,LipsPeriod,0,MODE_SMMA,PRICE_MEDIAN,i);
     }
//---- done
   return(0);
  }
//+------------------------------------------------------------------+

Comments