/*
   Generated by ex4-to-mq4 decompiler FREEWARE 4.0.451.7
   Website:  H t tp :// WW w .Me t Aq uot eS .nET
   E-mail : su pP o RT@ ME tAQU o t Es . net
*/
#property copyright "Attila"
#property link      "priceactiontools.com"

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Black
#property indicator_color2 Black
#property indicator_color3 Black

extern int barsback = 50;
extern bool arrows = TRUE;
extern int arrowsize = 1;
extern color arrowcolor = Aqua;
extern bool paint = false;
extern int barthickness = 2;
extern color paintcolor = Red;
extern bool alarm = FALSE;
extern string sound = ".wav file here";
extern bool alert = FALSE;
extern int OffsetX = 20;
extern int OffsetY = 65;
//extern int dist = 30;
int dist = 30;
extern bool M5 = False;
extern bool M15 = False;
extern bool M30 = False;
extern bool H1 = False;
extern bool H4 = True;
extern bool D1 = True;
extern bool W1 = False;
extern bool  DrawBackground = True;
extern color BackgroundColor = DarkGray;
extern color LabelsColor = RoyalBlue;
extern bool  LeftCaption = true;

double G_ibuf_148[];
double G_ibuf_152[];
double G_ibuf_156[];
//string Gsa_160[7] = {"W1", "D1", "4H", "60M", "30M", "15M", "5M"};
int G_datetime_164 = 0;
int G_datetime_168 = 0;
int G_datetime_172 = 0;
int G_datetime_176 = 0;
int G_datetime_180 = 0;
int G_datetime_184 = 0;
int G_datetime_188 = 0;

// 30D1161B8EDC2FB9CEFCDF6546666BB1
int f0_0(int A_timeframe_0) {
   int Li_ret_68;
   double ihigh_4 = iHigh(NULL, A_timeframe_0, 1);
   double ilow_12 = iLow(NULL, A_timeframe_0, 1);
   double iclose_20 = iClose(NULL, A_timeframe_0, 1);
   double iopen_28 = iOpen(NULL, A_timeframe_0, 1);
   double ihigh_36 = iHigh(NULL, A_timeframe_0, 2);
   double ilow_44 = iLow(NULL, A_timeframe_0, 2);
   double iclose_52 = iClose(NULL, A_timeframe_0, 2);
   double iopen_60 = iOpen(NULL, A_timeframe_0, 2);
   if (ihigh_4 < ihigh_36 && ilow_12 > ilow_44) Li_ret_68 = arrowcolor;
   else Li_ret_68 = 5197615;
   return (Li_ret_68);
}

// E37F0136AA3FFAF149B351F6A4C948E9
int init() {
   if (paint == TRUE) {
      SetIndexBuffer(0, G_ibuf_148);
      SetIndexStyle(0, DRAW_HISTOGRAM, STYLE_SOLID, barthickness, paintcolor);
      SetIndexEmptyValue(0, 0.0);
      SetIndexBuffer(1, G_ibuf_152);
      SetIndexStyle(1, DRAW_HISTOGRAM, STYLE_SOLID, barthickness, paintcolor);
      SetIndexEmptyValue(1, 0.0);
   }
   if (arrows == TRUE) {
      SetIndexBuffer(2, G_ibuf_156);
      SetIndexStyle(2, DRAW_ARROW, STYLE_SOLID, arrowsize, arrowcolor);
      SetIndexArrow(2, 116); //SYMBOL_ARROWDOWN
      SetIndexEmptyValue(2, 0.0);
   }
   ObjectCreate("ib_caption", OBJ_LABEL, 0, 0, 0, 0, 0);
   ObjectSet("ib_caption", OBJPROP_CORNER, 0);
   ObjectSet("ib_caption", OBJPROP_XDISTANCE, OffsetX);
   ObjectSet("ib_caption", OBJPROP_YDISTANCE, OffsetY);
   ObjectSetText("ib_caption", "Inside Bar", 10, "Arial", LabelsColor);
//   for (int Li_0 = 6; Li_0 >= 0; Li_0--) {
//      ObjectCreate("istf1" + Li_0, OBJ_LABEL, 0, 0, 0, 0, 0);
//      ObjectSet("istf1" + Li_0, OBJPROP_CORNER, 0);
//      ObjectSet("istf1" + Li_0, OBJPROP_XDISTANCE, ishX);
//      ObjectSet("istf1" + Li_0, OBJPROP_YDISTANCE, ishY + 20);
//      ObjectSetText("istf1" + Li_0, Gsa_160[Li_0], 10, "Arial", LabelsColor);
//      ObjectCreate("issig" + Li_0, OBJ_LABEL, 0, 0, 0, 0, 0);
//      ObjectSet("issig" + Li_0, OBJPROP_CORNER, 0);
//      ObjectSet("issig" + Li_0, OBJPROP_XDISTANCE, ishX);
//      ObjectSet("issig" + Li_0, OBJPROP_YDISTANCE, ishY + 30);
//      ishX += dist;
//   }
   DrawCaptionBG();
   CreateSignalLabels();
   return (0);
}

void CreateSignalLabels() {
   if (LeftCaption) OffsetX = OffsetX+96;
      else OffsetY = OffsetY + 18;
   if (M5) CreateSignalLabels_One("M5");
   if (M15) CreateSignalLabels_One("M15");
   if (M30) CreateSignalLabels_One("M30");
   if (H1) CreateSignalLabels_One("H1");
   if (H4) CreateSignalLabels_One("H4");
   if (D1) CreateSignalLabels_One("D1");
   if (W1) CreateSignalLabels_One("W1");
}

void CreateSignalLabels_One(string LabelName) {
   string _LabelName = "ib_tf_" + LabelName;
   ObjectCreate(_LabelName, OBJ_LABEL, 0, 0, 0, 0, 0);
   ObjectSet(_LabelName, OBJPROP_CORNER, 0);
   ObjectSet(_LabelName, OBJPROP_XDISTANCE, OffsetX);
   ObjectSet(_LabelName, OBJPROP_YDISTANCE, OffsetY);
   ObjectSetText(_LabelName, LabelName, 10, "Arial", LabelsColor);
   _LabelName = "ib_sig_" + LabelName;
   ObjectCreate(_LabelName, OBJ_LABEL, 0, 0, 0, 0, 0);
   ObjectSet(_LabelName, OBJPROP_CORNER, 0);
   ObjectSet(_LabelName, OBJPROP_XDISTANCE, OffsetX);
   ObjectSet(_LabelName, OBJPROP_YDISTANCE, OffsetY + 14);
   OffsetX += dist;
}

void DrawCaptionBG()
{
   if (!DrawBackground) return(0);
   
   int CountX = 0;
   int _YDISTANCE = 0;
   if (LeftCaption) {CountX = 3;}
   if (M5)  CountX=CountX +1;
   if (M15) CountX=CountX +1;
   if (M30) CountX=CountX +1;
   if (H1)  CountX=CountX +1;
   if (H4)  CountX=CountX +1;
   if (D1)  CountX=CountX +1;
   if (W1)  CountX=CountX +1;
   int CountY;
   if (DrawBackground) CountY = 2; else CountY = 3;
   if ((!LeftCaption) && (CountX<3)) CountX=3;
   
   int ix, iy;
   string _LabelName;
   for(ix=1; ix<=CountX; ix++)
   {
      for(iy=1; iy<=CountY; iy++)
      {
         _LabelName = "ib_bg_" + DoubleToStr(ix,0) + DoubleToStr(iy,0);
         ObjectCreate(_LabelName, OBJ_LABEL, 0, 0, 0, 0, 0);
         ObjectSet(_LabelName, OBJPROP_CORNER, 0);
         ObjectSet(_LabelName, OBJPROP_XDISTANCE, OffsetX-7+(ix-1)*32);
         _YDISTANCE=OffsetY-7+(iy-1)*33;
         if ((LeftCaption) && (iy>1)) _YDISTANCE=_YDISTANCE-15;
         ObjectSet(_LabelName, OBJPROP_YDISTANCE, _YDISTANCE);
         ObjectSetText(_LabelName, "g", 25, "Webdings", BackgroundColor);
      }
   }
}

// 52D46093050F38C27267BCE42543EF60
int deinit() {
//   Comment("");
//   for (int count_0 = 0; count_0 <= 7; count_0++) {
//      ObjectDelete("istf1" + count_0);
//      ObjectDelete("issig" + count_0);
//   }
   ObjectDelete("ib_caption");
   int i;
   int ot=ObjectsTotal();
   string _n;
   for(i=0; i<ot; i++)
   {
      _n=ObjectName(i);
      if ((StringFind(_n,"ib_tf")>=0) || (StringFind(_n,"ib_sig")>=0) || (StringFind(_n,"ib_bg")>=0)) 
         {
            ObjectDelete(_n);
            i--;
         }
   }
   return (0);
}

// EA2B2676C28C0DB26D39331A336C6B92
int start() {
   double pips_12;
   color color_24;
   color color_28;
   color color_32;
   color color_36;
   int Li_0 = IndicatorCounted();
   if (Li_0 < 0) return (0);
   if (Li_0 > 1) Li_0--;
   int Li_4 = Bars - Li_0 - 2;
   switch (Period()) {
   case PERIOD_M5:
      pips_12 = 50;
      break;
   case PERIOD_M15:
      pips_12 = 70;
      break;
   case PERIOD_M30:
      pips_12 = 80;
      break;
   case PERIOD_H1:
      pips_12 = 100;
      break;
   case PERIOD_H4:
      pips_12 = 150;
      break;
   case PERIOD_D1:
      pips_12 = 500;
      break;
   case PERIOD_W1:
      pips_12 = 1500;
   }
   for (int Li_20 = barsback; Li_20 >= 1; Li_20--) {
      if (High[Li_20] < High[Li_20 + 1] && Low[Li_20] > Low[Li_20 + 1]) {
         G_ibuf_148[Li_20] = Low[Li_20];
         G_ibuf_152[Li_20] = High[Li_20];
         G_ibuf_156[Li_20] = High[Li_20] + pips_12 * Point;
      }
   }
   if (M5 == TRUE) {
      color_24 = f0_0(PERIOD_M5);
      if (iTime(NULL, PERIOD_M5, 0) != G_datetime_164 && color_24 == arrowcolor) {
         G_datetime_164 = iTime(NULL, PERIOD_M5, 0);
         DoAlert();
      }
      ObjectSetText("ib_sig_M5", CharToStr(110), 18, "Wingdings", color_24);
   }
   if (M15 == TRUE) {
      color_28 = f0_0(PERIOD_M15);
      if (iTime(NULL, PERIOD_M15, 0) != G_datetime_168 && color_28 == arrowcolor) {
         G_datetime_168 = iTime(NULL, PERIOD_M15, 0);
         DoAlert();
      }
      ObjectSetText("ib_sig_M15", CharToStr(110), 18, "Wingdings", color_28);
   }
   if (M30 == TRUE) {
      color_32 = f0_0(PERIOD_M30);
      if (iTime(NULL, PERIOD_M30, 0) != G_datetime_172 && color_32 == arrowcolor) {
         G_datetime_172 = iTime(NULL, PERIOD_M30, 0);
         DoAlert();
      }
      ObjectSetText("ib_sig_M30", CharToStr(110), 18, "Wingdings", color_32);
   }
   if (H1 == TRUE) {
      color_36 = f0_0(PERIOD_H1);
      if (iTime(NULL, PERIOD_H1, 0) != G_datetime_176 && color_36 == arrowcolor) {
         G_datetime_176 = iTime(NULL, PERIOD_H1, 0);
         DoAlert();
      }
      ObjectSetText("ib_sig_H1", CharToStr(110), 18, "Wingdings", color_36);
   }
   if (H4 == TRUE) {
      color color_40 = f0_0(PERIOD_H4);
      if (iTime(NULL, PERIOD_H4, 0) != G_datetime_180 && color_40 == arrowcolor) {
         G_datetime_180 = iTime(NULL, PERIOD_H4, 0);
         DoAlert();
      }
      ObjectSetText("ib_sig_H4", CharToStr(110), 18, "Wingdings", color_40);
   }
   if (D1 == TRUE) {
      color color_44 = f0_0(PERIOD_D1);
      if (iTime(NULL, PERIOD_D1, 0) != G_datetime_184 && color_44 == arrowcolor) {
         G_datetime_184 = iTime(NULL, PERIOD_D1, 0);
         DoAlert();
      }
      ObjectSetText("ib_sig_D1", CharToStr(110), 18, "Wingdings", color_44);
   }
   if (W1 == TRUE) {
      color color_48 = f0_0(PERIOD_W1);
      if (iTime(NULL, PERIOD_W1, 0) != G_datetime_188 && color_48 == arrowcolor) {
         G_datetime_188 = iTime(NULL, PERIOD_W1, 0);
         DoAlert();
      }
      ObjectSetText("ib_sig_W1", CharToStr(110), 18, "Wingdings", color_48);
   }
//   WindowRedraw();
   return (0);
}

void DoAlert() {
   if (alert == TRUE) Alert("Inside bar on ", Symbol(), GetTFname(Period()));
   if (alarm == TRUE) PlaySound(sound);
}

string GetTFname (int aPeriod)
{
  string _sResult;
  switch(aPeriod)
     {
      case 1  : _sResult="Ì1";   break;
      case 5  : _sResult="Ì5";   break;
      case 15 : _sResult="Ì15";  break;
      case 30 : _sResult="Ì30";  break;
      case 60 : _sResult="H1";   break;
      case 240 : _sResult="H4";  break;
      case 1440 : _sResult="D1"; break;
     }
  return (_sResult);
}