AntiAlligator MTF

Download script
AntiAlligator MTF

This script is a custom trading indicator designed to identify specific momentum shifts and trend reversals by analyzing the relationship between price action and a specialized moving average system known as the "Alligator."

Core Logic and Mechanism

The tool operates by comparing three distinct moving averages (representing the Jaws, Teeth, and Lips of the Alligator) against real-time price data. It calculates the distance between the current price and these moving averages to determine market strength and potential entry points.

The logic follows a specific sequence of conditions:

1. Trend Identification The script first establishes the prevailing trend by comparing the "Lips" and "Jaws" components of the Alligator indicator. If the Lips are above the Jaws, it identifies an upward movement; if they are below, it identifies a downward movement.

2. Rotation Detection Simultaneously, the tool monitors "rotation." It looks at where the previous candle closed relative to its own midpoint (the average of its high and low). This helps the script understand if the price is currently reacting against the immediate momentum.

3. Signal Generation To filter out "noise" and provide reliable signals, the script requires a specific convergence of events before displaying an indicator on your chart:

  • Buy Signals: These occur when the market is in a downward trend, but a rotation happens upward, and the current price closes below the "Lips" while simultaneously breaking above the previous candle's high. The script then measures the intensity (the "delta") of this movement.
  • Sell Signals: These occur when the market is in an upward trend, but a rotation happens downward, and the current price closes above the "Lips" while simultaneously breaking below the previous candle's low.

Visual Representation

The indicator provides two primary ways to view these results:

  • Histogram Window: The script maintains a separate window where it plots the intensity of these signals as a histogram. This allows you to see the strength of the momentum regardless of the price scale.
  • On-Chart Arrows: When the calculated intensity (the delta) exceeds a pre-defined threshold, the script automatically places visual markers directly on your main chart:
    • Green Up Arrows: Signal potential buying opportunities located at the bottom of the price action.
    • Red Down Arrows: Signal potential selling opportunities located at the top of the price action.

In summary, this tool is designed to filter out standard market fluctuations and only alert the user when price action shows a clear, high-intensity reversal against the prevailing trend.

Price Data Components
Series array that contains the highest prices of each barSeries array that contains the lowest prices of each barSeries array that contains close prices for each bar
Indicators Used
Bill Williams Alligator
Miscellaneous
Implements a curve of type %1
11 Views
0 Downloads
0 Favorites
AntiAlligator MTF
//+------------------------------------------------------------------+
//|                                                AntiAlligator.mq4 |
//+------------------------------------------------------------------+

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Green
#property indicator_color2 Red
#property indicator_width1 2
#property indicator_width2 2
#property indicator_level1 20 //áàé
#property indicator_level2 20 //ñåëë
#property indicator_levelcolor DarkSlateGray
extern double Timeframe = 15.0;
extern int JawsPeriod=13;
extern int JawsShift=8;
extern int TeethPeriod=8;
extern int TeethShift=5;
extern int LipsPeriod=5;
extern int LipsShift=3;
extern int TypeMA=MODE_SMMA;
extern int TypePrice=PRICE_MEDIAN;
//---- buffers
double OscBufferBuy[];
double OscBufferSell[];
//------------
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(0,OscBufferBuy);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexBuffer(1,OscBufferSell);

   SetIndexDrawBegin(0,10);
   SetIndexDrawBegin(1,10);
   IndicatorShortName("AntiAlligator");
   return(0);
  }

int deinit()
  {
   ObjectsDeleteAll(0,OBJ_ARROW);
   return(0);
  }
int start()
  {
   int counted_bars=IndicatorCounted();
   int limit;
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   
   int trend=0;
   int razvorot=0;
   double delta=0;
   string name_buy,name_sell;

   for(int i=0; i<limit; i++)
   {
     OscBufferBuy[i]=0;
     OscBufferSell[i]=0;
   }
   for(i=0; i<limit; i++)
   {
    double jaw=iAlligator(NULL,0,JawsPeriod,JawsShift,TeethPeriod,TeethShift,LipsPeriod,LipsShift,TypeMA,TypePrice,MODE_GATORJAW,i); 
    double lips=iAlligator(NULL,0,JawsPeriod,JawsShift,TeethPeriod,TeethShift,LipsPeriod,LipsShift,TypeMA,TypePrice,MODE_GATORLIPS,i);
    double high1=iHigh(NULL,0,i+1);
    double low1=iLow(NULL,0,i+1);
    double close1=iClose(NULL,0,i+1);
    double close0=iClose(NULL,0,i);
    
    if (lips>jaw)trend=1;
    if (lips<jaw)trend=-1;
    
    if (close1>(high1+low1)/2.0)razvorot=1;
    if (close1<(high1+low1)/2.0)razvorot=-1;
    
    if (trend==1)delta=close0-lips;
    if (trend==-1)delta=lips-close0;
    
    if (close0<lips&&trend==-1&&razvorot==1&&close0>high1)OscBufferBuy[i]=delta;
    if (close0>lips&&trend==1&&razvorot==-1&&close0<low1)OscBufferSell[i]=delta;

    name_buy="buy"+DoubleToStr(i,0);
    name_sell="sell"+DoubleToStr(i,0);
    
    if (OscBufferSell[i]>indicator_level2*Point)SetArrow(SYMBOL_ARROWDOWN,Red,name_sell,Time[i],High[i]+3*Point,3);
    if (OscBufferBuy[i]>indicator_level1*Point)SetArrow(SYMBOL_ARROWUP,Green,name_buy,Time[i],Low[i]-3*Point,3); 
   }  
   return(0);
  }
//+----------------------------------------------------------------------------+
//|  Ïàðàìåòðû:                                                                |
//|    cd - êîä çíà÷êà                                                         |
//|    cl - öâåò çíà÷êà                                                        |
//|    nm - íàèìåíîâàíèå               ("" - âðåìÿ îòêðûòèÿ òåêóùåãî áàðà)     |
//|    t1 - âðåìÿ îòêðûòèÿ áàðà        (0  - òåêóùèé áàð)                      |
//|    p1 - öåíîâîé óðîâåíü            (0  - Bid)                              |
//|    sz - ðàçìåð çíà÷êà              (0  - ïî óìîë÷àíèþ)                     |
//+----------------------------------------------------------------------------+
void SetArrow(int cd, color cl,
              string nm="", datetime t1=0, double p1=0, int sz=0) {
  if (nm=="") nm=DoubleToStr(Time[0], 0);
  if (t1<=0) t1=Time[0];
  if (p1<=0) p1=Bid;
  if (ObjectFind(nm)<0) ObjectCreate(nm, OBJ_ARROW, 0, 0,0);
  ObjectSet(nm, OBJPROP_TIME1    , t1);
  ObjectSet(nm, OBJPROP_PRICE1   , p1);
  ObjectSet(nm, OBJPROP_ARROWCODE, cd);
  ObjectSet(nm, OBJPROP_COLOR    , cl);
  ObjectSet(nm, OBJPROP_WIDTH    , sz);
}

Comments