This script functions as a visual trading tool designed to help traders identify market trends by analyzing price movements over different timeframes. It operates by calculating three distinct moving averages, which are plotted on your chart as three separate lines. These lines—conceptually named the "Jaws," "Teeth," and "Lips"—act as a smoothed representation of historical price data.
Core Logic and Mechanics
The script works by looking backward at a specific number of previous price candles (the "Period") and calculating a smoothed average price (specifically using a Smoothed Moving Average method). By doing this for three different timeframes simultaneously, the tool provides a multi-layered view of market momentum:
- The Jaws (Blue Line): This represents the slowest moving average. It looks further back into the past over a longer period to identify the primary, long-term trend of the market.
- The Teeth (Red Line): This occupies the middle ground. It uses a shorter period than the Jaws, allowing it to react more quickly to recent price changes while still smoothing out minor "noise."
- The Lips (Lime Line): This is the fastest moving average. It focuses on the most immediate price action, reacting swiftly to current market fluctuations.
Visual Representation and Offsets
To make the data easier for a human trader to read, the script applies specific "shifts" to each line. Instead of all three lines starting at the exact same point on the current price candle, they are offset horizontally. This spacing creates a visual "opening" or "closing" effect, similar to the mouth of an alligator.
When the lines are spread apart in a specific direction, it typically indicates a strong trending move. When the lines converge or intertwine, it suggests a period of consolidation or a potential shift in market direction. By observing the relationship between these three lines, traders can better gauge whether the current momentum is accelerating, slowing down, or reversing.
//+------------------------------------------------------------------+
//| 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,JawsPeriod-1);
SetIndexDrawBegin(1,TeethPeriod-1);
SetIndexDrawBegin(2,LipsPeriod-1);
//---- 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