NRTR_GATOR_v1

Author: Rosh
Indicators Used
Indicator of the average true rangeBill Williams Alligator
1 Views
0 Downloads
0 Favorites
NRTR_GATOR_v1
ÿþ//+------------------------------------------------------------------+

//|                          NRTR GATOR(barabashkakvn's edition).mq5 |

//|                                                             Rosh |

//|                           http://forexsystems.ru/phpBB/index.php |

//+------------------------------------------------------------------+

#property copyright "Rosh"

#property link      "http://forexsystems.ru/phpBB/index.php"



#property indicator_chart_window

#property indicator_buffers 9

#property indicator_plots   5 

#property indicator_color1 clrTomato

#property indicator_type1 DRAW_ARROW



#property indicator_color2 clrDeepSkyBlue

#property indicator_type2 DRAW_ARROW



#property indicator_color3 clrDeepSkyBlue

#property indicator_type3 DRAW_ARROW



#property indicator_color4 clrTomato

#property indicator_type4 DRAW_ARROW



#property indicator_color5 clrYellowGreen,clrRed

#property indicator_type5 DRAW_COLOR_HISTOGRAM2 

#property indicator_width5 3 



//#property indicator_color6 clrRed

//---- input parameters

input int       PerATR=40;

input double    kATR=2.0;

input bool      useSendMail=false;

//---- buffers

double SellBuffer[];

double BuyBuffer[];

double Ceil[];

double Floor[];

double UpBar[];

double DownBar[];

double ColorHistogram_2Colors[];

double Trend[];

double GatorTrend[];

//---

int    handle_iATR;                          // variable for storing the handle of the iATR indicator 

int    handle_iAlligator;                    // variable for storing the handle of the iAlligator indicator 

//+------------------------------------------------------------------+ 

//| Custom indicator initialization function                         | 

//+------------------------------------------------------------------+ 

int OnInit()

  {

//--- indicator buffers mapping 



   PlotIndexSetInteger(0,PLOT_ARROW,251);

   SetIndexBuffer(0,SellBuffer,INDICATOR_DATA);

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);

   PlotIndexSetString(0,PLOT_LABEL,"8=8O ?@>4068");



   PlotIndexSetInteger(1,PLOT_ARROW,251);

   SetIndexBuffer(1,BuyBuffer,INDICATOR_DATA);

   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0);

   PlotIndexSetString(1,PLOT_LABEL,"8=8O ?>:C?:8");



   PlotIndexSetInteger(2,PLOT_ARROW,159);

   SetIndexBuffer(2,Ceil,INDICATOR_DATA);

   PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,0.0);

   PlotIndexSetString(2,PLOT_LABEL,">B>;>:");



   PlotIndexSetInteger(3,PLOT_ARROW,159);

   SetIndexBuffer(3,Floor,INDICATOR_DATA);

   PlotIndexSetDouble(3,PLOT_EMPTY_VALUE,0.0);

   PlotIndexSetString(3,PLOT_LABEL,">;");



   SetIndexBuffer(4,UpBar,INDICATOR_DATA);

//PlotIndexSetString(4,PLOT_LABEL,"5@E 10@0");



   SetIndexBuffer(5,DownBar,INDICATOR_DATA);

//PlotIndexSetString(4,PLOT_LABEL,"87 10@0");



   SetIndexBuffer(6,ColorHistogram_2Colors,INDICATOR_COLOR_INDEX);

   PlotIndexSetDouble(6,PLOT_EMPTY_VALUE,2);



   SetIndexBuffer(7,Trend,INDICATOR_CALCULATIONS);



   SetIndexBuffer(8,GatorTrend,INDICATOR_CALCULATIONS);



//--- create handle of the indicator iATR

   handle_iATR=iATR(Symbol(),Period(),PerATR);

//--- if the handle is not created 

   if(handle_iATR==INVALID_HANDLE)

     {

      //--- tell about the failure and output the error code 

      PrintFormat("Failed to create handle of the iATR indicator for the symbol %s/%s, error code %d",

                  Symbol(),

                  EnumToString(Period()),

                  GetLastError());

      //--- the indicator is stopped early 

      return(INIT_FAILED);

     }

//--- create handle of the indicator iAlligator

   handle_iAlligator=iAlligator(Symbol(),Period(),13,8,8,5,5,3,MODE_SMMA,PRICE_MEDIAN);

//--- if the handle is not created 

   if(handle_iAlligator==INVALID_HANDLE)

     {

      //--- tell about the failure and output the error code 

      PrintFormat("Failed to create handle of the iAlligator indicator for the symbol %s/%s, error code %d",

                  Symbol(),

                  EnumToString(Period()),

                  GetLastError());

      //--- the indicator is stopped early 

      return(INIT_FAILED);

     }

//---

   ArraySetAsSeries(SellBuffer,true);

   ArraySetAsSeries(BuyBuffer,true);

   ArraySetAsSeries(Ceil,true);

   ArraySetAsSeries(Floor,true);

   ArraySetAsSeries(UpBar,true);

   ArraySetAsSeries(DownBar,true);

   ArraySetAsSeries(ColorHistogram_2Colors,true);

   ArraySetAsSeries(Trend,true);

   ArraySetAsSeries(GatorTrend,true);

//---

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//| ?@>18B85 25@E0 #B@5=40                                        |

//+------------------------------------------------------------------+

bool BreakDown(int shift,const double close_value)

  {

   bool result=false;

   if(close_value>SellBuffer[shift+1])

      result=true;

   return(result);

  }

//+------------------------------------------------------------------+

//| ?@>18B85 4=0 B@5=40                                            |

//+------------------------------------------------------------------+

bool BreakUp(int shift,const double close_value)

  {

   bool result=false;

   if(close_value<BuyBuffer[shift+1])

      result=true;

   return(result);

  }

//+------------------------------------------------------------------+

//| 27OB85 =>2>3> <8=8<C<0 ?> #B@5=4C                             |

//+------------------------------------------------------------------+

bool BreakFloor(int shift,const double high_value)

  {

   bool result=false;

   if(high_value<Floor[shift+1])

      result=true;

   return(result);

  }

//+------------------------------------------------------------------+

//| 27OB85 =>2>3> <0:A8<C<0 ?> B@5=4C                              |

//+------------------------------------------------------------------+

bool BreakCeil(int shift,const double low_value)

  {

   bool result=false;

   if(low_value>Ceil[shift+1])

      result=true;

   return(result);

  }

//+------------------------------------------------------------------+

//| >?@545;5=85 ?@54K4CI53> B@5=40                                   |

//+------------------------------------------------------------------+

bool Uptrend(int shift)

  {

   bool result=false;

   if(Trend[shift+1]==1.0)

      result=true;

   if(Trend[shift+1]==-1.0)

      result=false;

   if((Trend[shift+1]!=1.0) && (Trend[shift+1]!=-1))

      Print("=8<0=85! "@5=4 =5 >?@545;5=, B0:>3> 1KBL =5 <>65B. 0@ # ",shift);

   return(result);

  }

////+------------------------------------------------------------------+

////| 2KG8A;5=85 2>;0B8;L=>AB8                                         |

////+------------------------------------------------------------------+

//double ATR(int iPer,int shift)

//  {

//   double result;

//   result=iATR(NULL,0,iPer,shift);

//   return(result);

//

//

//

//

//  }

//+------------------------------------------------------------------+

//| CAB0=>2:0 =>2>3> C@>2=O ?>B>;:0                                  |

//+------------------------------------------------------------------+

void NewCeil(int shift,const double close_value)

  {

   Ceil[shift]=close_value;

   Floor[shift]=0.0;

  }

//+------------------------------------------------------------------+

//| CAB0=>2:0 =>2>3> C@>2=O ?>;0                                     |

//+------------------------------------------------------------------+

void NewFloor(int shift,const double close_value)

  {

   Floor[shift]=close_value;

   Ceil[shift]=0.0;

  }

//+------------------------------------------------------------------+

//| CAB0=>2:0 C@>2=O ?>445@6:8 B@5=40                              |

//+------------------------------------------------------------------+

void SetBuyBuffer(int shift,const double close_value)

  {

   BuyBuffer[shift]=close_value-kATR*iATRGet(shift);

   SellBuffer[shift]=0.0;

  }

//+------------------------------------------------------------------+

//| CAB0=>2:0 C@>2=O ?>445@6:8 #B@5=40                            |

//+------------------------------------------------------------------+

void SetSellBuffer(int shift,const double close_value)

  {

   SellBuffer[shift]=close_value+kATR*iATRGet(shift);

   BuyBuffer[shift]=0.0;

  }

//+------------------------------------------------------------------+

//| @525@A B@5=40 8 CAB0=>2:0 =>2KE C@>2=59                          |

//+------------------------------------------------------------------+

void NewTrend(int shift,const double close_value)

  {

   if(Trend[shift+1]==1.0)

     {

      Trend[shift]=-1.0;

      NewFloor(shift,close_value);

      SetSellBuffer(shift,close_value);

     }

   else

     {

      Trend[shift]=1.0;

      NewCeil(shift,close_value);

      SetBuyBuffer(shift,close_value);

     }

   if((Trend[shift+1]!=1) && (Trend[shift+1]!=-1))

      Print("=8<0=85! "@5=4 =5 >?@545;5=, B0:>3> 1KBL =5 <>65B");

  }

//+------------------------------------------------------------------+

//| ?@>4>;65=85 B@5=40                                               |

//+------------------------------------------------------------------+

void CopyLastValues(int shift)

  {

   SellBuffer[shift]=SellBuffer[shift+1];

   BuyBuffer[shift]=BuyBuffer[shift+1];

   Ceil[shift]=Ceil[shift+1];

   Floor[shift]=Floor[shift+1];

   Trend[shift]=Trend[shift+1];

  }

//+------------------------------------------------------------------+

//| Custor indicator deinitialization function                       |

//+------------------------------------------------------------------+

int deinit()

  {

//---- 



//----

   return(0);

  }

//+------------------------------------------------------------------+ 

//| Custom indicator iteration function                              | 

//+------------------------------------------------------------------+ 

int OnCalculate(const int rates_total,

                const int prev_calculated,

                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[])

  {

//---

   ArraySetAsSeries(time,true);

   ArraySetAsSeries(open,true);

   ArraySetAsSeries(high,true);

   ArraySetAsSeries(low,true);

   ArraySetAsSeries(close,true);

////--- C7=05< :>;8G5AB2> @0AAG8B0==KE 7=0G5=89 2 8=48:0B>@5 

//   Comment(time[0],"A53> ?>AG8B0=>: \n",

//           "rates_total: ",rates_total,"\n",

//           "ATR: ",BarsCalculated(handle_iATR),"\n",

//           "Alligator: ",BarsCalculated(handle_iAlligator));

//return(rates_total);

//Print(rates_total,", ",BarsCalculated(handle_iATR),", ",BarsCalculated(handle_iAlligator));

//--- =0 "4" 10@ "0" - A0<K9 ?@02K9 10@ =0 3@0D8:5

//int    counted_bars=IndicatorCounted();

   int limit=0;

   if(prev_calculated>0)

      limit=rates_total-prev_calculated+1;

   if(prev_calculated==0)

     {

      ArrayInitialize(SellBuffer,0.0);

      ArrayInitialize(BuyBuffer,0.0);

      ArrayInitialize(Ceil,0.0);

      ArrayInitialize(Floor,0.0);;

      ArrayInitialize(UpBar,0.0);

      ArrayInitialize(DownBar,0.0);

      ArrayInitialize(ColorHistogram_2Colors,2);

      ArrayInitialize(Trend,0.0);

      ArrayInitialize(GatorTrend,0.0);

      //---

      limit=rates_total-PerATR-1;

      if(close[limit+1]>open[limit+1])

        {

         Trend[limit+1]=1.0;

         Ceil[limit+1]=close[limit+1];

         BuyBuffer[limit+1]=close[limit+1]-kATR*iATRGet(limit+1);

        }

      if(close[limit+1]<open[limit+1])

        {

         Trend[limit+1]=-1.0;

         Floor[limit+1]=close[limit+1];

         SellBuffer[limit+1]=close[limit+1]+kATR*iATRGet(limit+1);

        }

      if(close[limit+1]==open[limit+1])

        {

         Trend[limit+1]=1.0;

         Ceil[limit+1]=close[limit+1];

         BuyBuffer[limit+1]=close[limit+1]-kATR*iATRGet(limit+1);

        }

     }

//---

//--- =0 "4" 10@ "0" - A0<K9 ?@02K9 10@ =0 3@0D8:5

//--- =0 "5" 10@ "0" - A0<K9 ;52K9 10@ =0 3@0D8:5

   for(int cnt=limit;cnt>=0;cnt--)

     {

      if((iAlligatorGet(GATORJAW_LINE,cnt)<iAlligatorGet(GATORTEETH_LINE,cnt)) && 

         (iAlligatorGet(GATORTEETH_LINE,cnt)<iAlligatorGet(GATORLIPS_LINE,cnt)))

         GatorTrend[cnt]=1.0;

      if((iAlligatorGet(GATORJAW_LINE,cnt)>iAlligatorGet(GATORTEETH_LINE,cnt)) && 

         (iAlligatorGet(GATORTEETH_LINE,cnt)>iAlligatorGet(GATORLIPS_LINE,cnt)))

         GatorTrend[cnt]=-1.0;



      if(GatorTrend[cnt]==1.0)

        {

         UpBar[cnt]=high[cnt];

         DownBar[cnt]=low[cnt];

        }

      if(GatorTrend[cnt]==-1.0)

        {

         UpBar[cnt]=low[cnt];

         DownBar[cnt]=high[cnt];

        }

      if(UpBar[cnt]>DownBar[cnt])

         ColorHistogram_2Colors[cnt]=0;

      else

         ColorHistogram_2Colors[cnt]=1;



      if(Uptrend(cnt))

        {

         if(BreakCeil(cnt,low[cnt]))

           {

            NewCeil(cnt,close[cnt]);

            SetBuyBuffer(cnt,close[cnt]);

            Trend[cnt]=1.0;

            continue;

           }

         if(BreakUp(cnt,close[cnt]))

           {

            NewTrend(cnt,close[cnt]);

            continue;

           }

         CopyLastValues(cnt);

        }

      else

        {

         if(BreakFloor(cnt,high[cnt]))

           {

            NewFloor(cnt,close[cnt]);

            SetSellBuffer(cnt,close[cnt]);

            Trend[cnt]=-1.0;

            continue;

           }

         if(BreakDown(cnt,close[cnt]))

           {

            NewTrend(cnt,close[cnt]);

            continue;

           }

         CopyLastValues(cnt);

        }

     }



//---

   return(rates_total);

  }

//+------------------------------------------------------------------+

//| Get value of buffers for the iATR                                |

//+------------------------------------------------------------------+

double iATRGet(const int index)

  {

   double ATR[1];

//--- reset error code 

   ResetLastError();

//--- fill a part of the iATR array with values from the indicator buffer that has 0 index 

   if(CopyBuffer(handle_iATR,0,index,1,ATR)<0)

     {

      //--- if the copying fails, tell the error code 

      PrintFormat("Failed to copy data from the iATR indicator, error code %d",GetLastError());

      //--- quit with zero result - it means that the indicator is considered as not calculated 

      return(0.0);

     }

   return(ATR[0]);

  }

//+------------------------------------------------------------------+

//| Get value of buffers for the iAlligator                          |

//|  the buffer numbers are the following:                           |

//|   0 - GATORJAW_LINE, 1 - GATORTEETH_LINE, 2 - GATORLIPS_LINE     |

//+------------------------------------------------------------------+

double iAlligatorGet(const int buffer,const int index)

  {

   double Alligator[1];

//--- reset error code 

   ResetLastError();

//--- fill a part of the iStochasticBuffer array with values from the indicator buffer that has 0 index 

   if(CopyBuffer(handle_iAlligator,buffer,index,1,Alligator)<0)

     {

      //--- if the copying fails, tell the error code 

      PrintFormat("Failed to copy data from the iAlligator indicator, error code %d, buffer %d , index %d ",GetLastError(),buffer,index);

      //--- quit with zero result - it means that the indicator is considered as not calculated 

      return(0.0);

     }

   return(Alligator[0]);

  }

//+------------------------------------------------------------------+

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---