FX-ALLIGATOR
Download scriptThis script functions as a visual financial analysis tool designed to help traders identify trends and momentum in the forex market. It works by creating a set of four distinct moving lines on your trading chart, which act collectively as a "trend-following" system.
How the Logic Works
The core logic relies on calculating four different types of smoothed averages based on the price history of the currency pair. By analyzing where these lines move in relation to one another, a trader can interpret the "mood" of the market. Here is the breakdown of how these components behave:
- The Four Moving Lines: The script calculates four separate lines, each with its own unique settings for sensitivity and time delay (referred to as Jaws, Teeth, Lips, and an additional Line).
- Smoothing Technique: Instead of reacting wildly to every small price tick, the script uses a "Smoothed Moving Average." This means it filters out "market noise" to provide a cleaner picture of the overall direction.
- Dynamic Offsetting (Shifting): One of the key features of this logic is that each line is intentionally shifted backward in time on the chart. This creates a visual "gap" between the price and the indicators, making it easier for you to see if the momentum is accelerating or slowing down.
What the Visuals Mean for You
When you look at the chart with this script active, you aren't just looking at single lines; you are looking at a relationship of movement:
- Trend Identification: When all four lines move in the same direction (up or down), it suggests a strong, established trend in the market.
- Momentum Analysis: Because the lines have different periods and shifts, they will react at different speeds. For example, the "Lips" might turn quickly, while the "Jaws" move more slowly. When the faster lines pull away from the slower ones, it indicates increasing momentum.
- Stability: By using the "Median Price" as the basis for these calculations, the script ensures that the lines represent a balanced average of the highs and lows of each candle, rather than just focusing on the closing price.
In summary, this tool serves as a visual roadmap. It allows you to see the "flow" of the market by transforming raw price data into four smoothed, shifted paths that highlight the prevailing direction and strength of price movement.
//+------------------------------------------------------------------+
//| FX-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 4
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Lime
#property indicator_color4 Aqua
//---- input parameters
int JawsPeriod=8;
int JawsShift=5;
int TeethPeriod=5;
int TeethShift=3;
int LipsPeriod=3;
int LipsShift=2;
int LPeriod=2;
int LShift=1;
//---- indicator buffers
double ExtBlueBuffer[];
double ExtRedBuffer[];
double ExtLimeBuffer[];
double ExtLBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- line shifts when drawing
SetIndexShift(0,JawsShift);
SetIndexShift(1,TeethShift);
SetIndexShift(2,LipsShift);
SetIndexShift(3,LShift);
//---- first positions skipped when drawing
SetIndexDrawBegin(0,JawsShift+JawsPeriod);
SetIndexDrawBegin(1,TeethShift+TeethPeriod);
SetIndexDrawBegin(2,LipsShift+LipsPeriod);
SetIndexDrawBegin(3,LShift+LPeriod);
//---- 3 indicator buffers mapping
SetIndexBuffer(0,ExtBlueBuffer);
SetIndexBuffer(1,ExtRedBuffer);
SetIndexBuffer(2,ExtLimeBuffer);
SetIndexBuffer(3,ExtLBuffer);
//---- drawing settings
SetIndexStyle(0,DRAW_LINE);
SetIndexStyle(1,DRAW_LINE);
SetIndexStyle(2,DRAW_LINE);
SetIndexStyle(3,DRAW_LINE);
//---- index labels
SetIndexLabel(0,"");
SetIndexLabel(1,"");
SetIndexLabel(2,"");
SetIndexLabel(3,"");
//---- 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);
ExtLBuffer[i]=iMA(NULL,0,LPeriod,0,MODE_SMMA,PRICE_MEDIAN,i);
}
//---- done
return(0);
}
//+------------------------------------------------------------------+
Comments