/*
   Generated by ex4-to-mq4 decompiler FREEWARE 4.0.451.7
   Website:  h T t P: //W w w . m eT aqu o t E S . nE t
   E-mail : S uP pO rt@ m e TaQuO Te S .ne t
*/
#property copyright "Attila"
#property link      "pricebartrader@yahoo.com"

#property indicator_chart_window
#property indicator_buffers 6
#property indicator_color1 Black
#property indicator_color2 Black
#property indicator_color3 Black
#property indicator_color4 Black
#property indicator_color5 Black
#property indicator_color6 Black

extern int barsback = 50;
extern string minimum_nose_size = " 5 digit broker 50=5 pips";
extern int nose = 50;
extern string candle_ratio = "real body VS. shadow % // 4=40 precent real body";
extern int body = 4;
extern bool arrows = TRUE;
extern int arrowsize = 1;
extern color bullarrow = Blue;
extern color beararrow = Red;
extern bool paintbar = False;
extern int barthickness = 2;
extern color bullbar = Blue;
extern color bearbar = Red;
extern bool alarm = FALSE;
extern bool alert = FALSE;
extern string sound = ".wave file here";
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 int dist = 30;
int dist = 30;
extern int OffsetX = 20;
extern int OffsetY = 20;
extern bool  DrawBackground = True;
extern color BackgroundColor = DarkGray;
extern color LabelsColor = RoyalBlue;
extern bool  LeftCaption = true;

bool Gi_184;
bool Gi_188;
bool Gi_192;
bool Gi_196;
bool Gi_200;
double G_ibuf_204[];
double G_ibuf_208[];
double G_ibuf_212[];
double G_ibuf_216[];
double G_ibuf_220[];
double G_ibuf_224[];
string Gs_unused_228 = "Office Use";
int G_datetime_236 = 0;
int G_datetime_240 = 0;
int G_datetime_244 = 0;
int G_datetime_248 = 0;
int G_datetime_252 = 0;
int G_datetime_256 = 0;
int G_datetime_260 = 0;

// A28D5C501CF3CE16B54927994970FA3C
int f0_0(int A_timeframe_0, int Ai_4, int Ai_8) {
   bool Li_100;
   bool Li_104;
   bool Li_108;
   bool Li_112;
   bool Li_116;
   int Li_ret_120;
   double ihigh_12 = iHigh(NULL, A_timeframe_0, 1);
   double ilow_20 = iLow(NULL, A_timeframe_0, 1);
   double iclose_28 = iClose(NULL, A_timeframe_0, 1);
   double iopen_36 = iOpen(NULL, A_timeframe_0, 1);
   double ihigh_44 = iHigh(NULL, A_timeframe_0, 2);
   double ilow_52 = iLow(NULL, A_timeframe_0, 2);
   double iclose_60 = iClose(NULL, A_timeframe_0, 2);
   double iopen_68 = iOpen(NULL, A_timeframe_0, 2);
   double Ld_76 = ihigh_12 - ilow_20;
   double Ld_84 = ilow_20 + Ld_76 / 2.0;
   double Ld_92 = MathAbs(iopen_36 - iclose_28);
   if (ihigh_12 > ihigh_44 + Ai_4 * Point && ilow_20 > ilow_52) Li_100 = TRUE;
   else Li_100 = FALSE;
   if (Ld_92 < Ld_76 * Ai_8 / 10.0) Li_104 = TRUE;
   else Li_104 = FALSE;
   if (Ld_84 > iopen_36 && Ld_84 > iclose_28) Li_108 = TRUE;
   else Li_108 = FALSE;
   if (ilow_20 < ilow_52 - Ai_4 * Point && ihigh_12 < ihigh_44) Li_112 = TRUE;
   else Li_112 = FALSE;
   if (Ld_84 < iopen_36 && Ld_84 < iclose_28) Li_116 = TRUE;
   else Li_116 = FALSE;
   if (Li_100 == TRUE && Li_104 == TRUE && Li_108 == TRUE) Li_ret_120 = 255;
   if (Li_112 == TRUE && Li_104 == TRUE && Li_116 == TRUE) Li_ret_120 = 65280;
   else Li_ret_120 = 5197615;
   return (Li_ret_120);
}

// E37F0136AA3FFAF149B351F6A4C948E9
int init() {
   if (paintbar == TRUE) {
      SetIndexBuffer(0, G_ibuf_204);
      SetIndexStyle(0, DRAW_HISTOGRAM, STYLE_SOLID, barthickness, bullbar);
      SetIndexLabel(0, "pinbar_L");
      SetIndexEmptyValue(0, 0.0);
      SetIndexBuffer(1, G_ibuf_208);
      SetIndexStyle(1, DRAW_HISTOGRAM, STYLE_SOLID, barthickness, bullbar);
      SetIndexEmptyValue(1, 0.0);
      SetIndexBuffer(2, G_ibuf_212);
      SetIndexStyle(2, DRAW_HISTOGRAM, STYLE_SOLID, barthickness, bearbar);
      SetIndexLabel(2, "pinbar_S");
      SetIndexEmptyValue(2, 0.0);
      SetIndexBuffer(3, G_ibuf_216);
      SetIndexStyle(3, DRAW_HISTOGRAM, STYLE_SOLID, barthickness, bearbar);
      SetIndexEmptyValue(3, 0.0);
   }
   if (arrows == TRUE) {
      SetIndexBuffer(4, G_ibuf_220);
      SetIndexStyle(4, DRAW_ARROW, STYLE_SOLID, arrowsize, bullarrow);
      SetIndexArrow(4, SYMBOL_ARROWUP);
      SetIndexEmptyValue(4, 0.0);
      SetIndexBuffer(5, G_ibuf_224);
      SetIndexStyle(5, DRAW_ARROW, STYLE_SOLID, arrowsize, beararrow);
      SetIndexArrow(5, SYMBOL_ARROWDOWN);
      SetIndexEmptyValue(5, 0.0);
   }
   ObjectCreate("pb_caption", OBJ_LABEL, 0, 0, 0, 0, 0);
   ObjectSet("pb_caption", OBJPROP_CORNER, 0);
   ObjectSet("pb_caption", OBJPROP_XDISTANCE, OffsetX);
   ObjectSet("pb_caption", OBJPROP_YDISTANCE, OffsetY);
   ObjectSetText("pb_caption", "Pin Bar", 10, "Arial", LabelsColor);
//   for (int Li_0 = 6; Li_0 >= 0; Li_0--) {
//      ObjectCreate("ptf1" + Li_0, OBJ_LABEL, 0, 0, 0, 0, 0);
//      ObjectSet("ptf1" + Li_0, OBJPROP_CORNER, 0);
//      ObjectSet("ptf1" + Li_0, OBJPROP_XDISTANCE, phX);
//      ObjectSet("ptf1" + Li_0, OBJPROP_YDISTANCE, phY + 20);
//      ObjectSetText("ptf1" + Li_0, Gsa_180[Li_0], 10, "Verdana", RoyalBlue);
//      ObjectCreate("psig" + Li_0, OBJ_LABEL, 0, 0, 0, 0, 0);
//      ObjectSet("psig" + Li_0, OBJPROP_CORNER, 0);
//      ObjectSet("psig" + Li_0, OBJPROP_XDISTANCE, phX);
//      ObjectSet("psig" + Li_0, OBJPROP_YDISTANCE, phY + 30);
//      phX += 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 = "pb_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 = "pb_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 = "pb_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() {
//   for (int count_0 = 0; count_0 <= 7; count_0++) {
//      ObjectDelete("ptf1" + count_0);
//      ObjectDelete("psig" + count_0);
//   }
   ObjectDelete("pb_caption");
   int i;
   int ot=ObjectsTotal();
   string _n;
   for(i=0; i<ot; i++)
   {
      _n=ObjectName(i);
      if ((StringFind(_n,"pb_tf")>=0) || (StringFind(_n,"pb_sig")>=0) || (StringFind(_n,"pb_bg")>=0)) 
         {
            ObjectDelete(_n);
            i--;
         }
   }
//   Comment("");
   return (0);
}

// EA2B2676C28C0DB26D39331A336C6B92
int start() {
   double Ld_0;
   double Ld_8;
   double Ld_16;
   double Ld_24;
   double pips_44;
   double high_56;
   double low_64;
   double close_72;
   double open_80;
   double high_88;
   double low_96;
   double Ld_unused_104;
   double Ld_unused_112;
   double Ld_unused_120;
   double Ld_unused_128;
   color color_136;
   color color_140;
   color color_144;
   color color_148;
   int Li_32 = IndicatorCounted();
   if (Li_32 > 1) Li_32--;
   int Li_36 = Bars - Li_32;
   switch (Period()) {
   case PERIOD_M5:
      pips_44 = 50;
      break;
   case PERIOD_M15:
      pips_44 = 70;
      break;
   case PERIOD_M30:
      pips_44 = 80;
      break;
   case PERIOD_H1:
      pips_44 = 100;
      break;
   case PERIOD_H4:
      pips_44 = 150;
      break;
   case PERIOD_D1:
      pips_44 = 500;
      break;
   case PERIOD_W1:
      pips_44 = 1500;
   }
   for (int Li_52 = barsback; Li_52 >= 1; Li_52--) {
      high_56 = High[Li_52];
      low_64 = Low[Li_52];
      close_72 = Close[Li_52];
      open_80 = Open[Li_52];
      high_88 = High[Li_52 + 1];
      low_96 = Low[Li_52 + 1];
      Ld_unused_104 = Close[Li_52 + 1];
      Ld_unused_112 = Open[Li_52 + 1];
      Ld_unused_120 = High[Li_52 + 2];
      Ld_unused_128 = Low[Li_52 + 2];
      Ld_24 = high_88 - low_96;
      Ld_0 = high_56 - low_64;
      Ld_16 = low_64 + Ld_0 / 2.0;
      Ld_8 = MathAbs(open_80 - close_72);
      if (low_64 < low_96 - nose * Point && high_56 < high_88) Gi_196 = TRUE;
      else Gi_196 = FALSE;
      if (Ld_16 < open_80 && Ld_16 < close_72) Gi_200 = TRUE;
      else Gi_200 = FALSE;
      if (high_56 > high_88 + nose * Point && low_64 > low_96) Gi_184 = TRUE;
      else Gi_184 = FALSE;
      if (Ld_16 > open_80 && Ld_16 > close_72) Gi_188 = TRUE;
      else Gi_188 = FALSE;
      if (Ld_8 < Ld_0 * body / 10.0) Gi_192 = TRUE;
      else Gi_192 = FALSE;
      if (Gi_196 == TRUE && Gi_200 == TRUE && Gi_192 == TRUE) {
         G_ibuf_204[Li_52] = high_56;
         G_ibuf_208[Li_52] = low_64;
         G_ibuf_220[Li_52] = Low[Li_52] - pips_44 * Point;
      }
      if (Gi_184 == TRUE && Gi_188 == TRUE && Gi_192 == TRUE) {
         G_ibuf_212[Li_52] = high_56;
         G_ibuf_216[Li_52] = low_64;
         G_ibuf_224[Li_52] = High[Li_52] + pips_44 * Point;
      }
   }
   if (M5 == TRUE) {
      color_136 = f0_0(PERIOD_M5, nose, body);
      if (iTime(NULL, PERIOD_M5, 0) != G_datetime_236 && color_136 != DarkSlateGray) {
         G_datetime_236 = iTime(NULL, PERIOD_M5, 0);
         DoAlert();
      }
      ObjectSetText("pb_sig_M5", CharToStr(110), 18, "Wingdings", color_136);
   }
   if (M15 == TRUE) {
      color_140 = f0_0(PERIOD_M15, nose, body);
      if (iTime(NULL, PERIOD_M15, 0) != G_datetime_240 && color_140 != DarkSlateGray) {
         G_datetime_240 = iTime(NULL, PERIOD_M15, 0);
         DoAlert();
      }
      ObjectSetText("pb_sig_M15", CharToStr(110), 18, "Wingdings", color_140);      
   }
   if (M30 == TRUE) {
      color_144 = f0_0(PERIOD_M30, nose, body);
      if (iTime(NULL, PERIOD_M30, 0) != G_datetime_244 && color_144 != DarkSlateGray) {
         G_datetime_244 = iTime(NULL, PERIOD_M30, 0);
         DoAlert();
      }
      ObjectSetText("pb_sig_M30", CharToStr(110), 18, "Wingdings", color_144);
   }
   if (H1 == TRUE) {
      color_148 = f0_0(PERIOD_H1, nose, body);
      if (iTime(NULL, PERIOD_H1, 0) != G_datetime_248 && color_148 != DarkSlateGray) {
         G_datetime_248 = iTime(NULL, PERIOD_H1, 0);
         DoAlert();
      }
      ObjectSetText("pb_sig_H1", CharToStr(110), 18, "Wingdings", color_148);
   }
   if (H4 == TRUE) {
      color color_152 = f0_0(PERIOD_H4, nose, body);
      if (iTime(NULL, PERIOD_H4, 0) != G_datetime_252 && color_152 != DarkSlateGray) {
         G_datetime_252 = iTime(NULL, PERIOD_H4, 0);
         DoAlert();
      }
     ObjectSetText("pb_sig_H4", CharToStr(110), 18, "Wingdings", color_152); 
   }
   if (D1 == TRUE) {
      color color_156 = f0_0(PERIOD_D1, nose, body);
      if (iTime(NULL, PERIOD_D1, 0) != G_datetime_256 && color_156 != DarkSlateGray) {
         G_datetime_256 = iTime(NULL, PERIOD_D1, 0);
         DoAlert();
      }
      ObjectSetText("pb_sig_D1", CharToStr(110), 18, "Wingdings", color_156);
   }
   if (W1 == TRUE) {
      color color_160 = f0_0(PERIOD_W1, nose, body);
      if (iTime(NULL, PERIOD_W1, 0) != G_datetime_260 && color_160 != DarkSlateGray) {
         G_datetime_260 = iTime(NULL, PERIOD_W1, 0);
         DoAlert();
      }
      ObjectSetText("pb_sig_W1", CharToStr(110), 18, "Wingdings", color_160);  
   }
//   WindowRedraw();
   return (0);
}

void DoAlert() {
   if (alert == TRUE) Alert("Pin 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);
}