alligatorsignal
Download scriptThe AlligatorSignal script is a technical analysis tool designed to help traders identify potential market trends and entry points by monitoring the relationship between three specific moving averages, commonly referred to as the "Alligator" lines. These lines represent the Jaw, Teeth, and Lips of the indicator, each reacting to price action at different speeds.
Core Operational Logic
The script functions by calculating and analyzing the positioning of these three components to determine the prevailing market sentiment:
1. Trend Identification (The Alligator Structure) The tool monitors how these three lines interact with one another. It categorizes the market movement into four primary states:
- Rise: Occurs when the Lips are above the Teeth, and the Teeth are above the Jaw, suggesting a strong upward trend.
- Fall: Occurs when the Lips are below the Teeth, and the Teeth are below the Jaw, suggesting a strong downward trend.
- UpCross: A transitional state where the Jaw moves above the Teeth while the Lips were previously below them.
- DownCross: A transitional state where the Jaw moves below the Teeth while the Lips were previously above them.
2. Momentum Filtering (The "Force" Factor) To reduce "false positives"—where the market might look like it is moving but lacks the actual strength to sustain a trend—the script incorporates a secondary calculation known as "Force." This acts as a momentum filter. By comparing this Force value against a user-defined threshold, the script ensures that signals are only generated when there is sufficient volatility and movement behind the price action.
Signal Generation
The primary goal of the script is to provide clear visual cues for potential trades. It combines both the trend structure and the momentum filter to trigger specific signals:
- Buy Signals: These appear when the market is in a "Rise" configuration (Lips > Teeth > Jaw) and the momentum Force exceeds a specific strength level. When these conditions are met, the script places a visual arrow below the price candle.
- Sell Signals: These appear when the market is in a "Fall" configuration (Lips < Teeth < Jaw) and the momentum Force falls below a specific strength level. When these conditions are met, the script places a visual arrow above the price candle.
Summary for the User
In simple terms, this script looks for a "perfect storm" of conditions: it waits for the three Alligator lines to align in a clear direction (up or down) and then double-checks that the market is moving with enough power (Force) to justify a trade. If both conditions are satisfied, it marks the chart with an arrow to alert you to the opportunity.
//+------------------------------------------------------------------+
//| AlligatorSignal.mq4 |
//| Copyright 2016, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 5
#property indicator_plots 5
//--- plot Alligator_jaw
#property indicator_label1 "AlligatorJaw"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrBlue
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//--- plot AlligatorTeeth
#property indicator_label2 "AlligatorTeeth"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrRed
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
//--- plot AlligatorLips
#property indicator_label3 "AlligatorLips"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrGreen
#property indicator_style3 STYLE_SOLID
#property indicator_width3 1
//--- plot ArrowBuy
#property indicator_label4 "ArrowBuy"
#property indicator_type4 DRAW_ARROW
#property indicator_color4 clrRed
#property indicator_style4 STYLE_SOLID
#property indicator_width4 1
//--- plot ArrowSell
#property indicator_label5 "ArrowSell"
#property indicator_type5 DRAW_ARROW
#property indicator_color5 clrBlue
#property indicator_style5 STYLE_SOLID
#property indicator_width5 1
//--- input parameters
input int InpJawPeriod=8;// Jaws Period
input int InpJawShift=0;// Jaws Shift
input int InpTeethPeriod=5;// Teeth Period
input int InpTeethShift=0;// Teeth Shift
input int InpLipsPeriod=3;// Lips Period
input int InpLipsShift=0;// Lips Shift
input int InpMaPeriod=3;//averaging period
input ENUM_MA_METHOD InpMaMethod=MODE_EMA;// method of averaging of the Alligator lines
input ENUM_APPLIED_PRICE InpAppliedPrice=PRICE_WEIGHTED;// type of price used for calculation of Alligator
input double InpForceFilte=0.35;
//--- indicator buffers
double AlligatorJawBuffer[];
double AlligatorTeethBuffer[];
double AlligatorLipsBuffer[];
double ArrowBuyBuffer[];
double ArrowSellBuffer[];
string AlligatorSignalBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,AlligatorJawBuffer,INDICATOR_DATA);
SetIndexBuffer(1,AlligatorTeethBuffer,INDICATOR_DATA);
SetIndexBuffer(2,AlligatorLipsBuffer,INDICATOR_DATA);
SetIndexBuffer(3,ArrowBuyBuffer,INDICATOR_DATA);
SetIndexBuffer(4,ArrowSellBuffer,INDICATOR_DATA);
//--- Define the symbol code for drawing in PLOT_ARROW
SetIndexArrow(3,241);
SetIndexArrow(4,242);
//--- name for DataWindow and indicator subwindow label
string short_name="AlligatorSignal("+IntegerToString(InpJawPeriod)+","+IntegerToString(InpTeethPeriod)+","+IntegerToString(InpLipsPeriod)+")";
IndicatorShortName(short_name);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,// size of input time series
const int prev_calculated,// bars handled in previous call
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
//--- Get the number of bars available for the current symbol and chart period
/*
int bars=Bars(Symbol(),0);
Print("Bars = ",bars,", rates_total = ",rates_total,", prev_calculated = ",prev_calculated);
Print("time[0] = ",time[0]," time[rates_total-1] = ",time[rates_total-1]);
*/
int limit=rates_total-1;
ArrayResize(AlligatorSignalBuffer,rates_total,10);
//ArrayFill(AlligatorSignalBuffer,0,rates_total,"N/A");
for(int i=0; i<limit;i++)
{
AlligatorJawBuffer[i]=NormalizeDouble(iAlligator(NULL,NULL,
InpJawPeriod,InpJawShift,InpTeethPeriod,InpTeethShift,InpLipsPeriod,InpLipsShift,
InpMaMethod,InpAppliedPrice,MODE_GATORJAW,i
),Digits);
AlligatorTeethBuffer[i]=NormalizeDouble(iAlligator(NULL,NULL,
InpJawPeriod,InpJawShift,InpTeethPeriod,InpTeethShift,InpLipsPeriod,InpLipsShift,
InpMaMethod,InpAppliedPrice,MODE_GATORTEETH,i
),Digits);
AlligatorLipsBuffer[i]=NormalizeDouble(iAlligator(NULL,NULL,
InpJawPeriod,InpJawShift,InpTeethPeriod,InpTeethShift,InpLipsPeriod,InpLipsShift,
InpMaMethod,InpAppliedPrice,MODE_GATORLIPS,i
),Digits);
}
for(int i=0; i<limit;i++)
{
double Force=NormalizeDouble(iForce(NULL,NULL,InpMaPeriod,InpMaMethod,InpAppliedPrice,i),Digits);
string AlligatorSignal="N/A";
if(AlligatorJawBuffer[i]>AlligatorTeethBuffer[i] && AlligatorLipsBuffer[i+1]<=AlligatorTeethBuffer[i+1])
{
AlligatorSignal="UpCross";
}
if(AlligatorJawBuffer[i]<AlligatorTeethBuffer[i] && AlligatorLipsBuffer[i+1]>=AlligatorTeethBuffer[i+1])
{
AlligatorSignal="DownCross";
}
if(AlligatorLipsBuffer[i]>AlligatorTeethBuffer[i] && AlligatorTeethBuffer[i]>AlligatorJawBuffer[i])
{
AlligatorSignal="Rise";
}
if(AlligatorLipsBuffer[i]<AlligatorTeethBuffer[i] && AlligatorTeethBuffer[i]<AlligatorJawBuffer[i])
{
AlligatorSignal="Fall";
}
if(Force>InpForceFilte && AlligatorSignal=="Rise")
{
AlligatorSignal="Buy";
}
if(Force<InpForceFilte && AlligatorSignal=="Fall")
{
AlligatorSignal="Sell";
}
AlligatorSignalBuffer[i]=AlligatorSignal;
if(AlligatorSignalBuffer[i]=="Buy")
{
ArrowBuyBuffer[i]=low[i]-0.00050;
}
if(AlligatorSignalBuffer[i]=="Sell")
{
ArrowSellBuffer[i]=high[i]+0.00050;
}
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
Comments