//+------------------------------------------------------------------+
//|                                              des_engulf_indi.mq4 |
//|                        Copyright 2019, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, BUJU "
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 20
#property indicator_plots   20
//--- plot Label1
#property indicator_label1  "Label1"
#property indicator_type1   DRAW_ARROW
#property indicator_color1  clrYellow
#property indicator_style1  STYLE_SOLID
#property indicator_width1  3
//--- plot Label2
#property indicator_label2  "Label2"
#property indicator_type2   DRAW_ARROW
#property indicator_color2  clrTurquoise
#property indicator_style2  STYLE_SOLID
#property indicator_width2  3
//--- plot Label3
#property indicator_label3  "Label3"
#property indicator_type3   DRAW_LINE
#property indicator_color3  clrRed
#property indicator_style3  STYLE_SOLID
#property indicator_width3  1
//--- plot Label4
#property indicator_label4  "Label4"
#property indicator_type4   DRAW_LINE
#property indicator_color4  clrRed
#property indicator_style4  STYLE_SOLID
#property indicator_width4  1
//--- plot Label5
#property indicator_label5  "Label5"
#property indicator_type5   DRAW_LINE
#property indicator_color5  clrRed
#property indicator_style5  STYLE_SOLID
#property indicator_width5  1
//--- plot Label6
#property indicator_label6  "Label6"
#property indicator_type6   DRAW_LINE
#property indicator_color6  clrRed
#property indicator_style6  STYLE_SOLID
#property indicator_width6  1
//--- plot Label7
#property indicator_label7  "Label7"
#property indicator_type7   DRAW_LINE
#property indicator_color7  clrRed
#property indicator_style7  STYLE_SOLID
#property indicator_width7  1
//--- plot Label8
#property indicator_label8  "Label8"
#property indicator_type8   DRAW_LINE
#property indicator_color8  clrRed
#property indicator_style8  STYLE_SOLID
#property indicator_width8  1
//--- plot Label9
#property indicator_label9  "Label9"
#property indicator_type9   DRAW_LINE
#property indicator_color9  clrRed
#property indicator_style9  STYLE_SOLID
#property indicator_width9  1
//--- plot Label10
#property indicator_label10  "Label10"
#property indicator_type10   DRAW_LINE
#property indicator_color10  clrRed
#property indicator_style10  STYLE_SOLID
#property indicator_width10  1
//--- plot Label11
#property indicator_label11  "Label11"
#property indicator_type11   DRAW_LINE
#property indicator_color11  clrRed
#property indicator_style11  STYLE_SOLID
#property indicator_width11  1
//--- plot Label12
#property indicator_label12  "Label12"
#property indicator_type12   DRAW_LINE
#property indicator_color12  clrRed
#property indicator_style12  STYLE_SOLID
#property indicator_width12  1
//--- plot Label13
#property indicator_label13  "Label13"
#property indicator_type13   DRAW_LINE
#property indicator_color13  clrRed
#property indicator_style13  STYLE_SOLID
#property indicator_width13  1
//--- plot Label14
#property indicator_label14  "Label14"
#property indicator_type14   DRAW_LINE
#property indicator_color14  clrRed
#property indicator_style14  STYLE_SOLID
#property indicator_width14  1
//--- plot Label15
#property indicator_label15  "Label15"
#property indicator_type15   DRAW_LINE
#property indicator_color15  clrRed
#property indicator_style15  STYLE_SOLID
#property indicator_width15  1
//--- plot Label16
#property indicator_label16  "Label16"
#property indicator_type16   DRAW_LINE
#property indicator_color16  clrRed
#property indicator_style16  STYLE_SOLID
#property indicator_width16  1
//--- plot Label17
#property indicator_label17  "Label17"
#property indicator_type17   DRAW_LINE
#property indicator_color17  clrRed
#property indicator_style17  STYLE_SOLID
#property indicator_width17  1
//--- plot Label18
#property indicator_label18  "Label18"
#property indicator_type18   DRAW_LINE
#property indicator_color18  clrRed
#property indicator_style18  STYLE_SOLID
#property indicator_width18  1
//--- plot Label19
#property indicator_label19  "Label19"
#property indicator_type19   DRAW_LINE
#property indicator_color19  clrRed
#property indicator_style19  STYLE_SOLID
#property indicator_width19  1
//--- plot Label20
#property indicator_label20  "Label20"
#property indicator_type20   DRAW_LINE
#property indicator_color20  clrRed
#property indicator_style20  STYLE_SOLID
#property indicator_width20  1

extern bool alert = True;

//--- indicator buffers
double         Label1Buffer[];
double         Label2Buffer[];
double         Label3Buffer[];
double         Label4Buffer[];
double         Label5Buffer[];
double         Label6Buffer[];
double         Label7Buffer[];
double         Label8Buffer[];
double         Label9Buffer[];
double         Label10Buffer[];
double         Label11Buffer[];
double         Label12Buffer[];
double         Label13Buffer[];
double         Label14Buffer[];
double         Label15Buffer[];
double         Label16Buffer[];
double         Label17Buffer[];
double         Label18Buffer[];
double         Label19Buffer[];
double         Label20Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,Label1Buffer);
   SetIndexBuffer(1,Label2Buffer);
   SetIndexBuffer(2,Label3Buffer);
   SetIndexBuffer(3,Label4Buffer);
   SetIndexBuffer(4,Label5Buffer);
   SetIndexBuffer(5,Label6Buffer);
   SetIndexBuffer(6,Label7Buffer);
   SetIndexBuffer(7,Label8Buffer);
   SetIndexBuffer(8,Label9Buffer);
   SetIndexBuffer(9,Label10Buffer);
   SetIndexBuffer(10,Label11Buffer);
   SetIndexBuffer(11,Label12Buffer);
   SetIndexBuffer(12,Label13Buffer);
   SetIndexBuffer(13,Label14Buffer);
   SetIndexBuffer(14,Label15Buffer);
   SetIndexBuffer(15,Label16Buffer);
   SetIndexBuffer(16,Label17Buffer);
   SetIndexBuffer(17,Label18Buffer);
   SetIndexBuffer(18,Label19Buffer);
   SetIndexBuffer(19,Label20Buffer);
//--- setting a code from the Wingdings charset as the property of PLOT_ARROW
   PlotIndexSetInteger(0,PLOT_ARROW,159);
   PlotIndexSetInteger(1,PLOT_ARROW,159);

   ObjectsDeleteAll(0,"fibo");
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| 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[])
  {
//---
   int position=0;
   string ud;

   for(int i=Bars-2; i>=0; i--)
     {

      double high_prev = High[i+1];
      double low_prev = Low[i+1];
      double high_cur = High[i];
      double low_cur = Low[i];
      double close_prev = Close[i+1];
      double close_cur = Close[i];

      if(
         high_cur > high_prev &&
         low_cur < low_prev &&
         close_cur > close_prev
      )
        {
         Label1Buffer[i-1] = Open[i];
         position = i;
         ud = "up";
        }

      if(
         high_cur > high_prev &&
         low_cur < low_prev &&
         close_cur < close_prev
      )
        {
         Label2Buffer[i-1] = Open[i];
         position = i;
         ud = "down";
        }
     } //end for

//Print (ud );

///////////////////////////////////////////////////////////////////////

   if(ud == "up")
     {

      ObjectCreate("fibo", OBJ_FIBO, 0, Time[position], High[position], Time[position], Low[position]);
      ObjectSet("fibo", OBJPROP_FIBOLEVELS,7);
      ObjectSet("fibo", OBJPROP_FIBOLEVELS,  6);
      ObjectSet("fibo", OBJPROP_FIRSTLEVEL+0,   0.0);
      ObjectSet("fibo", OBJPROP_FIRSTLEVEL+1,   0.5);
      ObjectSet("fibo", OBJPROP_FIRSTLEVEL+2,   1.0);
      ObjectSet("fibo", OBJPROP_FIRSTLEVEL+3,   1.5);
      ObjectSet("fibo", OBJPROP_FIRSTLEVEL+4,   2.0);
      ObjectSet("fibo", OBJPROP_FIRSTLEVEL+5,   2.5);
      ObjectSetFiboDescription("fibo", 0, "0.0");
      ObjectSetFiboDescription("fibo", 1, "50");
      ObjectSetFiboDescription("fibo", 2, "100");
      ObjectSetFiboDescription("fibo", 3, "150");
      ObjectSetFiboDescription("fibo", 4, "200");
      ObjectSetFiboDescription("fibo", 5, "250");
      ObjectSet("fibo", OBJPROP_LEVELSTYLE, STYLE_DOT);
      ObjectSet("fibo", OBJPROP_LEVELCOLOR, Yellow);
     }

   if(ud == "down")
     {

      //-----------------------------

      ObjectCreate("fibo", OBJ_FIBO, 0, Time[position], Low[position], Time[position], High[position]);
      ObjectSet("fibo", OBJPROP_FIBOLEVELS,7);
      ObjectSet("fibo", OBJPROP_FIBOLEVELS,  6);
      ObjectSet("fibo", OBJPROP_FIRSTLEVEL+0,   0.0);
      ObjectSet("fibo", OBJPROP_FIRSTLEVEL+1,   0.5);
      ObjectSet("fibo", OBJPROP_FIRSTLEVEL+2,   1.0);
      ObjectSet("fibo", OBJPROP_FIRSTLEVEL+3,   1.5);
      ObjectSet("fibo", OBJPROP_FIRSTLEVEL+4,   2.0);
      ObjectSet("fibo", OBJPROP_FIRSTLEVEL+5,   2.5);
      ObjectSetFiboDescription("fibo", 0, "0.0");
      ObjectSetFiboDescription("fibo", 1, "50");
      ObjectSetFiboDescription("fibo", 2, "100");
      ObjectSetFiboDescription("fibo", 3, "150");
      ObjectSetFiboDescription("fibo", 4, "200");
      ObjectSetFiboDescription("fibo", 5, "250");
      ObjectSet("fibo", OBJPROP_LEVELSTYLE, STYLE_DOT);
      ObjectSet("fibo", OBJPROP_LEVELCOLOR, Yellow);
     }


///////////////////////////////////////////////////////////////////////////////


//-------------------------------------------------------------
   string currency_0 = "EURUSD";
   string currency_1 = "GBPUSD";
   string currency_2 = "USDCHF";
   string currency_3 = "USDJPY";
   string currency_4 = "AUDUSD";
   string currency_5 = "USDCAD";
   string currency_6 = "NZDUSD";
   string currency_7 = "EURGBP";
   string currency_8 = "EURCHF";
   string currency_9 = "EURJPY";
   string currency_10 = "EURAUD";
   string currency_11 = "EURCAD";
   string currency_12 = "EURNZD";
   string currency_13 = "NZDCAD";
   string currency_14 = "NZDCHF";
   string currency_15 = "NZDJPY";
   string currency_16 = "GBPCHF";
   string currency_17 = "GBPJPY";
   string currency_18 = "GBPAUD";
   string currency_19 = "GBPCAD";
   string currency_20 = "GBPNZD";
   string currency_21 = "CHFJPY";
   string currency_22 = "AUDCAD";
   string currency_23 = "AUDCHF";
   string currency_24 = "AUDJPY";
   string currency_25 = "AUDNZD";
   string currency_26 = "CADJPY";
   string currency_27 = "CADCHF";

   string array_C[28][2];

//input index
   for(int y=0; y<28; y++)
     {
      array_C[y][1] = y;
     }

//input currencies string
   array_C[0][0] = currency_0 ;
   array_C[1][0] = currency_1 ;
   array_C[2][0] = currency_2 ;
   array_C[3][0] = currency_3 ;
   array_C[4][0] = currency_4 ;
   array_C[5][0] = currency_5 ;
   array_C[6][0] = currency_6 ;
   array_C[7][0] = currency_7 ;
   array_C[8][0] = currency_8 ;
   array_C[9][0] = currency_9 ;
   array_C[10][0] = currency_10 ;
   array_C[11][0] = currency_11 ;
   array_C[12][0] = currency_12 ;
   array_C[13][0] = currency_13 ;
   array_C[14][0] = currency_14 ;
   array_C[15][0] = currency_15 ;
   array_C[16][0] = currency_16 ;
   array_C[17][0] = currency_17 ;
   array_C[18][0] = currency_18 ;
   array_C[19][0] = currency_19 ;
   array_C[20][0] = currency_20 ;
   array_C[21][0] = currency_21 ;
   array_C[22][0] = currency_22 ;
   array_C[23][0] = currency_23 ;
   array_C[24][0] = currency_24 ;
   array_C[25][0] = currency_25 ;
   array_C[26][0] = currency_26 ;
   array_C[27][0] = currency_27 ;


   if(alert == True)
     {
      static datetime tmp;    //only execute on a new bar
      if(tmp!= Time[0])     //
        {
         //
         tmp =  Time[0];
         Alert("--------- new bar ---------");


         for(int i=0; i<28; i++)
           {

            double high_prev = iHigh(array_C[i][0],0,2);
            double low_prev = iLow(array_C[i][0],0,2);

            double high_cur = iHigh(array_C[i][0],0,1);
            double low_cur = iLow(array_C[i][0],0,1);

            double close_prev = iClose(array_C[i][0],0,2);
            double close_cur = iClose(array_C[i][0],0,1);

            if(
               high_cur > high_prev &&
               low_cur < low_prev &&
               close_cur > close_prev
            )
              {
               Alert("engulf UP          ",array_C[i][0]);
              }

            if(
               high_cur > high_prev &&
               low_cur < low_prev &&
               close_cur < close_prev
            )
              {
               Alert("engulf DOWN   ",array_C[i][0]);
              }

           }
        }
     }



//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
