#property copyright "Copyright ?2006, Hua Ai (aha)"
#property link      ""

#property indicator_chart_window
#property indicator_buffers 6
#property indicator_color1 Yellow
#property indicator_color2 Yellow
#property indicator_color3 Fuchsia
#property indicator_color4 Fuchsia
#property indicator_color5 Yellow
#property indicator_color6 Yellow

extern bool Alerts = TRUE;
extern bool History = FALSE;
extern bool CheckPinBars = TRUE;
extern int Min_Nose_Ratio = 60;
extern int Max_Body_Ratio = 40;
extern bool CheckDoubleBarHighLows = TRUE;
extern bool CheckOutsideBars = TRUE;
extern bool CheckI4Bars = TRUE;
extern bool SearchM15 = FALSE;
extern bool SearchM30 = FALSE;
extern bool SearchH1 = TRUE;
extern bool SearchH4 = TRUE;
extern bool SearchD1 = TRUE;
extern bool SearchW1 = TRUE;
extern bool SearchMN1 = TRUE;
double g_ibuf_136[];
double g_ibuf_140[];
double g_ibuf_144[];
double g_ibuf_148[];
double g_ibuf_152[];
double g_ibuf_156[];
bool gi_160;
int gi_164;
int gi_168;
int gi_180;
string gs_184;
int gi_192;
int gi_196;
int gi_unused_200;
int gi_204;
int gi_208;
int gi_212;
int gi_216;
int gi_220;
int gi_224;
int gi_228;
int gi_232;
int gi_236;
int gi_240;
int gi_244;
int gi_248;
int gi_252;
int gi_256;
int gi_260;
int gi_264;
int gi_268;
int gi_272;
int gi_276;
int gi_280;
int gi_284;
int gi_288;

int init() {
   SetIndexStyle(0, DRAW_ARROW);
   SetIndexArrow(0, 74);
   SetIndexBuffer(0, g_ibuf_140);
   SetIndexEmptyValue(0, 0.0);
   SetIndexStyle(1, DRAW_ARROW);
   SetIndexArrow(1, 74);
   SetIndexBuffer(1, g_ibuf_136);
   SetIndexEmptyValue(1, 0.0);
   SetIndexStyle(2, DRAW_ARROW);
   SetIndexArrow(2, 249);
   SetIndexBuffer(2, g_ibuf_144);
   SetIndexEmptyValue(2, 0.0);
   SetIndexStyle(3, DRAW_ARROW);
   SetIndexArrow(3, 249);
   SetIndexBuffer(3, g_ibuf_148);
   SetIndexEmptyValue(3, 0.0);
   SetIndexStyle(4, DRAW_ARROW);
   SetIndexArrow(4, 217);
   SetIndexBuffer(4, g_ibuf_152);
   SetIndexEmptyValue(4, 0.0);
   SetIndexStyle(5, DRAW_ARROW);
   SetIndexArrow(5, 218);
   SetIndexBuffer(5, g_ibuf_156);
   SetIndexEmptyValue(5, 0.0);
   gi_160 = TRUE;
   clearmarks(g_ibuf_136, g_ibuf_140, g_ibuf_144, g_ibuf_148, g_ibuf_152, g_ibuf_156);
   switch (Period()) {
   case PERIOD_MN1:
      gs_184 = "MN1";
      break;
   case PERIOD_W1:
      gs_184 = "W1";
      break;
   case PERIOD_D1:
      gs_184 = "D1";
      break;
   case PERIOD_H4:
      gs_184 = "H4";
      break;
   case PERIOD_H1:
      gs_184 = "H1";
      break;
   case PERIOD_M30:
      gs_184 = "M30";
      break;
   case PERIOD_M15:
      gs_184 = "M15";
      break;
   case PERIOD_M5:
      gs_184 = "M5";
      break;
   case PERIOD_M1:
      gs_184 = "M1";
      break;

      return (0);
   }
   gi_192 = 0;
   gi_196 = 0;
   gi_unused_200 = 0;
   gi_204 = 0;
   gi_208 = 0;
   gi_212 = 0;
   gi_216 = 0;
   gi_220 = 0;
   gi_224 = 0;
   gi_228 = 0;
   gi_232 = 0;
   gi_236 = 0;
   gi_240 = 0;
   gi_244 = 0;
   gi_248 = 0;
   gi_252 = 0;
   gi_256 = 0;
   gi_260 = 0;
   gi_264 = 0;
   gi_268 = 0;
   gi_272 = 0;
   gi_276 = 0;
   gi_280 = 0;
   gi_284 = 0;
   gi_288 = 0;
   return (0);
}

int deinit() {
   gi_160 = FALSE;
   clearmarks(g_ibuf_136, g_ibuf_140, g_ibuf_144, g_ibuf_148, g_ibuf_152, g_ibuf_156);
   return (0);
}

void CheckTime(int &ai_0, int &ai_4, int &ai_8) {
   switch (Period()) {
   case PERIOD_M1:
   case PERIOD_M5:
   case PERIOD_M15:
      ai_8 = 0;
      return;
   case PERIOD_M30:
      if ((Minute() > 28 && Seconds() > 30) || gi_160) ai_0 = 1;
      else ai_0 = 0;
      if ((Minute() < 5 && Seconds() < 10) || gi_160) ai_4 = 1;
      else ai_4 = 0;
      ai_8 = 0;
      return;
   case PERIOD_H1:
      if ((Minute() > 58 && Seconds() > 30) || gi_160) ai_0 = 1;
      else ai_0 = 0;
      if ((Minute() < 10 && Seconds() < 10) || gi_160) ai_4 = 1;
      else ai_4 = 0;
      ai_8 = 1;
      return;
   case PERIOD_H4:
      if ((MathMod(Hour(), 4) == 3.0 && Minute() > 55 && Seconds() > 30) || gi_160) ai_0 = 1;
      else ai_0 = 0;
      if ((MathMod(Hour(), 4) == 0.0 && Minute() < 10 && Seconds() < 10) || gi_160) ai_4 = 1;
      else ai_4 = 0;
      ai_8 = 2;
      return;
   case PERIOD_D1:
      if ((Hour() == 23 && Minute() > 55 && Seconds() > 30) || gi_160) ai_0 = 1;
      else ai_0 = 0;
      if ((Hour() == 0 && Minute() < 10 && Seconds() < 10) || gi_160) ai_4 = 1;
      else ai_4 = 0;
      ai_8 = 3;
      return;
   case PERIOD_W1:
      if ((DayOfWeek() == 5 && Hour() == 19 && Minute() > 55 && Seconds() > 30) || gi_160) ai_0 = 1;
      else ai_0 = 0;
      if ((DayOfWeek() == 0 && Hour() == 20 && Minute() < 10 && Seconds() < 10) || gi_160) ai_4 = 1;
      else ai_4 = 0;
      ai_8 = 4;
      return;
   case PERIOD_MN1:
      if ((Day() >= 28 && Hour() == 23 && Minute() > 55 && Seconds() > 30) || gi_160) ai_0 = 1;
      else ai_0 = 0;
      if ((Day() == 0 && Hour() == 0 && Minute() < 10 && Seconds() < 10) || gi_160) ai_4 = 1;
      else ai_4 = 0;
      ai_8 = 5;
      return;
   }
   ai_0 = 0;
   ai_4 = 0;
   ai_8 = 0;
}

double CalRange(int ai_0, bool ai_4 = FALSE) {
   int li_12 = 0;
   if (ai_4) li_12 = 1;
   double ld_24 = 0;
   for (int li_8 = ai_0 - li_12; li_8 <= ai_0 + 1; li_8++) ld_24 += MathAbs(High[li_8] - Low[li_8]);
   double ld_ret_16 = ld_24 / 2.0;
   return (ld_ret_16);
}

void clearmarks(double &ada_0[], double &ada_4[], double &ada_8[], double &ada_12[], double &ada_16[], double &ada_20[]) {
   for (int l_index_24 = 0; l_index_24 <= Bars - 1; l_index_24++) {
      ada_0[l_index_24] = 0;
      ada_4[l_index_24] = 0;
      ada_8[l_index_24] = 0;
      ada_12[l_index_24] = 0;
      ada_16[l_index_24] = 0;
      ada_20[l_index_24] = 0;
   }
}

void CheckNPB(int ai_0, double &ada_4[], int &ai_8, bool ai_12 = FALSE) {
   double ld_16;
   double ld_24;
   double ld_32;
   if (CheckPinBars) {
      ld_16 = High[ai_0] - Low[ai_0];
      if (ld_16 == 0.0) ld_16 = 0.0001;
      ld_24 = High[ai_0] - MathMax(Open[ai_0], Close[ai_0]);
      ld_32 = MathAbs(Open[ai_0] - Close[ai_0]);
      if (ld_24 / ld_16 > Min_Nose_Ratio / 100.0 && ld_32 / ld_16 < Max_Body_Ratio / 100.0 && High[ai_0] - (High[ai_0 + 1]) >= ld_16 / 3.0 || (High[ai_0] - (High[ai_0 +
         1]) >= ld_16 / 4.0 && ld_32 / ld_16 < 0.2) && Low[ai_0] < Low[ai_0 + 1]) {
         if (History) ada_4[ai_0] = High[ai_0] + CalRange(ai_0, ai_12) / 10.0;
         if (Alerts && !ai_8 && !gi_160 && !ai_12) {
            Alert("PriceAction AHA on ", Symbol(), " " + gs_184 + ": Negative Pin Bar!! ");
            SendMail("PriceAction AHA: Pin Bar on " + Symbol() + " " + gs_184 + "!!", "PriceAction AHA: Negative Pin bar found on " + Symbol() + " " + gs_184 + "!!");
            ai_8 = 1;
         }
      }
      if (ai_12 && !(ld_24 / ld_16 > Min_Nose_Ratio / 100.0 && ld_32 / ld_16 < Max_Body_Ratio / 100.0 && High[ai_0] - (High[ai_0 + 1]) >= ld_16 / 3.0 || (High[ai_0] - (High[ai_0 +
         1]) >= ld_16 / 4.0 && ld_32 / ld_16 < 0.2) && Low[ai_0] < Low[ai_0 + 1]) || High[ai_0] < High[ai_0 - 1]) ada_4[ai_0] = 0;
      if (ai_12) ai_8 = 0;
   }
}

void CheckPPB(int ai_0, double &ada_4[], int &ai_8, bool ai_12 = FALSE) {
   double ld_16;
   double ld_24;
   double ld_32;
   if (CheckPinBars) {
      ld_16 = High[ai_0] - Low[ai_0];
      if (ld_16 == 0.0) ld_16 = 0.00001;
      ld_24 = MathMin(Open[ai_0], Close[ai_0]) - Low[ai_0];
      ld_32 = MathAbs(Open[ai_0] - Close[ai_0]);
      if (ld_24 / ld_16 > Min_Nose_Ratio / 100.0 && ld_32 / ld_16 < Max_Body_Ratio / 100.0 && Low[ai_0 + 1] - Low[ai_0] >= ld_16 / 3.0 || (Low[ai_0 + 1] - Low[ai_0] >= ld_16 / 4.0 &&
         ld_32 / ld_16 < 0.2) && High[ai_0] < High[ai_0 + 1]) {
         if (History) ada_4[ai_0] = Low[ai_0] - CalRange(ai_0, ai_12) / 10.0;
         if (Alerts && !ai_8 && !gi_160 && !ai_12) {
            Alert("PriceAction AHA on ", Symbol(), " " + gs_184 + ": Positive Pin Bar!! ");
            SendMail("PriceAction AHA: Pin Bar on " + Symbol() + " " + gs_184 + "!!", "PriceAction AHA: Positive Pin bar found on " + Symbol() + " " + gs_184 + "!!");
            ai_8 = 1;
         }
      }
      if (ai_12 && !(ld_24 / ld_16 > Min_Nose_Ratio / 100.0 && ld_32 / ld_16 < Max_Body_Ratio / 100.0 && Low[ai_0 + 1] - Low[ai_0] >= ld_16 / 3.0 || (Low[ai_0 + 1] - Low[ai_0] >= ld_16 / 4.0 &&
         ld_32 / ld_16 < 0.2) && High[ai_0] < High[ai_0 + 1]) || Low[ai_0] > Low[ai_0 - 1]) ada_4[ai_0] = 0;
      if (ai_12) ai_8 = 0;
   }
}

void CheckBullB(int ai_0, double &ada_4[], int &ai_8, bool ai_12 = FALSE) {
   if (CheckDoubleBarHighLows) {
      if (MathAbs(Low[ai_0] - (Low[ai_0 + 1])) <= gi_180 * Point && Close[ai_0] > High[ai_0 + 1]) {
         if (History) ada_4[ai_0] = Low[ai_0] - CalRange(ai_0, ai_12) / 10.0;
         if (Alerts && !ai_8 && !gi_160 && !ai_12) {
            Alert("PriceAction AHA on ", Symbol(), " " + gs_184 + ": DBLHC!! ");
            SendMail("PriceAction AHA: DBLHC on " + Symbol() + " " + gs_184 + "!!", "PriceAction AHA: DBLHC found on " + Symbol() + " " + gs_184 + "!!");
            ai_8 = 1;
         }
      }
      if (ai_12 && !(MathAbs(Low[ai_0] - (Low[ai_0 + 1])) <= gi_180 * Point && Close[ai_0] > High[ai_0 + 1])) ada_4[ai_0] = 0;
      if (ai_12) ai_8 = 0;
   }
   if (CheckOutsideBars) {
      if (Low[ai_0] < Low[ai_0 + 1] && Close[ai_0] > High[ai_0 + 1]) {
         if (History) ada_4[ai_0] = Low[ai_0] - CalRange(ai_0, ai_12) / 10.0;
         if (Alerts && !ai_8 && !gi_160 && !ai_12) {
            Alert("PriceAction AHA on ", Symbol(), " " + gs_184 + ": BUOB!! ");
            SendMail("PriceAction AHA: BUOB on " + Symbol() + " " + gs_184 + "!!", "PriceAction AHA: BUOB found on " + Symbol() + " " + gs_184 + "!!");
            ai_8 = 1;
         }
      }
      if (ai_12 && !(Low[ai_0] < Low[ai_0 + 1] && Close[ai_0] > High[ai_0 + 1])) ada_4[ai_0] = 0;
      if (ai_12) ai_8 = 0;
   }
}

void CheckBearB(int ai_0, double &ada_4[], int &ai_8, bool ai_12 = FALSE) {
   if (CheckDoubleBarHighLows) {
      if (MathAbs(High[ai_0] - (High[ai_0 + 1])) <= gi_180 * Point && Close[ai_0] < Low[ai_0 + 1]) {
         if (History) ada_4[ai_0] = High[ai_0] + CalRange(ai_0, ai_12) / 10.0;
         if (Alerts && !ai_8 && !gi_160 && !ai_12) {
            Alert("PriceAction AHA on ", Symbol(), " " + gs_184 + ": DBHLC!! ");
            SendMail("PriceAction AHA: DBHLC on " + Symbol() + " " + gs_184 + "!!", "PriceAction AHA: DBHLC found on " + Symbol() + " " + gs_184 + "!!");
            ai_8 = 1;
         }
      }
      if (ai_12 && !(MathAbs(High[ai_0] - (High[ai_0 + 1])) <= gi_180 * Point && Close[ai_0] < Low[ai_0 + 1])) ada_4[ai_0] = 0;
      if (ai_12) ai_8 = 0;
   }
   if (CheckOutsideBars) {
      if (Close[ai_0] < Low[ai_0 + 1] && High[ai_0] > High[ai_0 + 1]) {
         if (History) ada_4[ai_0] = High[ai_0] + CalRange(ai_0, ai_12) / 10.0;
         if (Alerts && !ai_8 && !gi_160 && !ai_12) {
            Alert("PriceAction AHA on ", Symbol(), " " + gs_184 + ": BEOB!! ");
            SendMail("PriceAction AHA: BEOB on " + Symbol() + " " + gs_184 + "!!", "PriceAction AHA: BEOB found on " + Symbol() + " " + gs_184 + "!!");
            ai_8 = 1;
         }
      }
      if (ai_12 && !(Close[ai_0] < Low[ai_0 + 1] && High[ai_0] > High[ai_0 + 1])) ada_4[ai_0] = 0;
      if (ai_12) ai_8 = 0;
   }
}

void CheckI4B(int ai_0, double &ada_4[], double &ada_8[], bool ai_12 = FALSE) {
   int li_20;
   int li_24;
   int li_28;
   int li_32;
   double ld_36;
   double ld_44;
   double ld_52;
   double ld_60;
   int l_day_of_week_16 = TimeDayOfWeek(iTime(NULL, 0, ai_0));
   if (CheckI4Bars) {
      if (Period() == PERIOD_D1) {
         switch (l_day_of_week_16) {
         case 4:
         case 5:
            li_20 = ai_0;
            li_24 = ai_0 + 1;
            li_28 = ai_0 + 2;
            li_32 = ai_0 + 3;
            break;
         case 3:
            li_20 = ai_0;
            li_24 = ai_0 + 1;
            li_28 = ai_0 + 2;
            li_32 = ai_0 + 4;
            break;
         case 2:
            li_20 = ai_0;
            li_24 = ai_0 + 1;
            li_28 = ai_0 + 3;
            li_32 = ai_0 + 4;
            break;
         case 1:
            li_20 = ai_0;
            li_24 = ai_0 + 2;
            li_28 = ai_0 + 3;
            li_32 = ai_0 + 4;
            break;
     
            li_20 = ai_0;
            li_24 = ai_0;
            li_28 = ai_0;
            li_32 = ai_0;
         }
      } else {
         li_20 = ai_0;
         li_24 = ai_0 + 1;
         li_28 = ai_0 + 2;
         li_32 = ai_0 + 3;
      }
      ld_36 = High[li_20] - Low[li_20];
      ld_44 = High[li_24] - Low[li_24];
      ld_52 = High[li_28] - Low[li_28];
      ld_60 = High[li_32] - Low[li_32];
      if (ld_36 < ld_44 && ld_36 < ld_52 && ld_36 < ld_60 && High[li_20] < High[li_24] && Low[li_20] > Low[li_24] && Period() == PERIOD_D1 || Period() == PERIOD_H4) {
         ada_4[ai_0] = High[ai_0] + CalRange(ai_0, ai_12) / 10.0;
         ada_8[ai_0] = Low[ai_0] - CalRange(ai_0, ai_12) / 10.0;
      }
   }
}

void CheckM15(int &ai_0, int &ai_4, int &ai_8) {
   double ld_88;
   double ld_96;
   double ld_104;
   double ld_112;
   double ld_120;
   if (Period() == PERIOD_M15) return;
   if (MathMod(Minute(), 15) < 2.0) {
      ai_0 = 0;
      ai_4 = 0;
      ai_8 = 0;
      return;
   }
   if (MathMod(Minute(), 15) >= 2.0 && MathMod(Minute(), 15) < 13.0) return;
   int l_timeframe_12 = 15;
   string ls_16 = "M15";
   double l_ihigh_24 = iHigh(NULL, l_timeframe_12, 0);
   double l_ihigh_32 = iHigh(NULL, l_timeframe_12, 1);
   double l_ilow_40 = iLow(NULL, l_timeframe_12, 0);
   double l_ilow_48 = iLow(NULL, l_timeframe_12, 1);
   double l_iopen_56 = iOpen(NULL, l_timeframe_12, 0);
   double l_iopen_64 = iOpen(NULL, l_timeframe_12, 1);
   double l_iclose_72 = iClose(NULL, l_timeframe_12, 0);
   double l_iclose_80 = iClose(NULL, l_timeframe_12, 1);
   if (CheckPinBars && !ai_0) {
      ld_88 = l_ihigh_24 - l_ilow_40;
      if (ld_88 == 0.0) ld_88 = 0.0001;
      ld_96 = MathAbs(l_iopen_56 - l_iclose_72);
      ld_112 = l_ihigh_24 - MathMax(l_iopen_56, l_iclose_72);
      ld_120 = MathMin(l_iopen_56, l_iclose_72) - l_ilow_40;
      if (ld_112 >= ld_120) {
         ld_104 = ld_112;
         if (ld_104 / ld_88 > Min_Nose_Ratio / 100.0 && ld_96 / ld_88 < Max_Body_Ratio / 100.0 && l_ihigh_24 - l_ihigh_32 >= ld_88 / 3.0 || (l_ihigh_24 - l_ihigh_32 >= ld_88 / 4.0 &&
            ld_96 / ld_88 < 0.2) && l_ilow_40 > l_ilow_48) {
            if (Alerts) {
               Alert("PriceAction AHA on ", Symbol(), " " + ls_16 + ": Negative Pin Bar!! ");
               SendMail("PriceAction AHA: Pin Bar on " + Symbol() + " " + ls_16 + "!!", "PriceAction AHA: Negative Pin bar found on " + Symbol() + " " + ls_16 + "!!");
            }
            ai_0 = 1;
         }
      } else {
         if (ld_112 <= ld_120) {
            ld_104 = ld_120;
            if (ld_104 / ld_88 > Min_Nose_Ratio / 100.0 && ld_96 / ld_88 < Max_Body_Ratio / 100.0 && l_ilow_48 - l_ilow_40 >= ld_88 / 3.0 || (l_ilow_48 - l_ilow_40 >= ld_88 / 4.0 &&
               ld_96 / ld_88 < 0.2) && l_ihigh_24 < l_ihigh_32) {
               if (Alerts) {
                  Alert("PriceAction AHA on ", Symbol(), " " + ls_16 + ": Positive Pin Bar!! ");
                  SendMail("PriceAction AHA: Pin Bar on " + Symbol() + " " + ls_16 + "!!", "PriceAction AHA: Positive Pin bar found on " + Symbol() + " " + ls_16 + "!!");
               }
               ai_0 = 1;
            }
         }
      }
   }
   if (CheckDoubleBarHighLows && !ai_4) {
      if (MathAbs(l_ilow_40 - l_ilow_48) <= 0.0 && l_iclose_72 > l_ihigh_32) {
         if (Alerts) {
            Alert("PriceAction AHA on ", Symbol(), " " + ls_16 + ": DBLHC!! ");
            SendMail("PriceAction AHA: DBLHC on " + Symbol() + " " + ls_16 + "!!", "PriceAction AHA: DBLHC found on " + Symbol() + " " + ls_16 + "!!");
         }
         ai_4 = 1;
      } else {
         if (MathAbs(l_ihigh_24 - l_ihigh_32) <= 0.0 && l_iclose_72 < l_ilow_48) {
            if (Alerts) {
               Alert("PriceAction AHA on ", Symbol(), " " + ls_16 + ": DBHLC!! ");
               SendMail("PriceAction AHA: DBHLC on " + Symbol() + " " + ls_16 + "!!", "PriceAction AHA: DBHLC found on " + Symbol() + " " + ls_16 + "!!");
            }
            ai_4 = 1;
         }
      }
   }
   if (CheckOutsideBars && !ai_8) {
      if (l_ilow_40 < l_ilow_48 && l_iclose_72 > l_ihigh_32) {
         if (Alerts) {
            Alert("PriceAction AHA on ", Symbol(), " " + ls_16 + ": BUOB!! ");
            SendMail("PriceAction AHA: BUOB on " + Symbol() + " " + ls_16 + "!!", "PriceAction AHA: BUOB found on " + Symbol() + " " + ls_16 + "!!");
         }
         ai_8 = 1;
      } else {
         if (l_iclose_72 < l_ilow_48 && l_ihigh_24 > l_ihigh_32) {
            if (Alerts) {
               Alert("PriceAction AHA on ", Symbol(), " " + ls_16 + ": BEOB!! ");
               SendMail("PriceAction AHA: BEOB on " + Symbol() + " " + ls_16 + "!!", "PriceAction AHA: BEOB found on " + Symbol() + " " + ls_16 + "!!");
            }
            ai_8 = 1;
         }
      }
   }
}

void CheckM30(int &ai_0, int &ai_4, int &ai_8) {
   double ld_88;
   double ld_96;
   double ld_104;
   double ld_112;
   double ld_120;
   if (Period() == PERIOD_M30) return;
   if (MathMod(Minute(), 30) < 2.0) {
      ai_0 = 0;
      ai_4 = 0;
      ai_8 = 0;
      return;
   }
   if (MathMod(Minute(), 30) >= 2.0 && MathMod(Minute(), 30) < 28.0) return;
   int l_timeframe_12 = 30;
   string ls_16 = "M30";
   double l_ihigh_24 = iHigh(NULL, l_timeframe_12, 0);
   double l_ihigh_32 = iHigh(NULL, l_timeframe_12, 1);
   double l_ilow_40 = iLow(NULL, l_timeframe_12, 0);
   double l_ilow_48 = iLow(NULL, l_timeframe_12, 1);
   double l_iopen_56 = iOpen(NULL, l_timeframe_12, 0);
   double l_iopen_64 = iOpen(NULL, l_timeframe_12, 1);
   double l_iclose_72 = iClose(NULL, l_timeframe_12, 0);
   double l_iclose_80 = iClose(NULL, l_timeframe_12, 1);
   if (CheckPinBars && !ai_0) {
      ld_88 = l_ihigh_24 - l_ilow_40;
      if (ld_88 == 0.0) ld_88 = 0.0001;
      ld_96 = MathAbs(l_iopen_56 - l_iclose_72);
      ld_112 = l_ihigh_24 - MathMax(l_iopen_56, l_iclose_72);
      ld_120 = MathMin(l_iopen_56, l_iclose_72) - l_ilow_40;
      if (ld_112 >= ld_120) {
         ld_104 = ld_112;
         if (ld_104 / ld_88 > Min_Nose_Ratio / 100.0 && ld_96 / ld_88 < Max_Body_Ratio / 100.0 && l_ihigh_24 - l_ihigh_32 >= ld_88 / 3.0 || (l_ihigh_24 - l_ihigh_32 >= ld_88 / 4.0 &&
            ld_96 / ld_88 < 0.2) && l_ilow_40 > l_ilow_48) {
            if (Alerts) {
               Alert("PriceAction AHA on ", Symbol(), " " + ls_16 + ": Negative Pin Bar!! ");
               SendMail("PriceAction AHA: Pin Bar on " + Symbol() + " " + ls_16 + "!!", "PriceAction AHA: Negative Pin bar found on " + Symbol() + " " + ls_16 + "!!");
            }
            ai_0 = 1;
         }
      } else {
         if (ld_112 <= ld_120) {
            ld_104 = ld_120;
            if (ld_104 / ld_88 > Min_Nose_Ratio / 100.0 && ld_96 / ld_88 < Max_Body_Ratio / 100.0 && l_ilow_48 - l_ilow_40 >= ld_88 / 3.0 || (l_ilow_48 - l_ilow_40 >= ld_88 / 4.0 &&
               ld_96 / ld_88 < 0.2) && l_ihigh_24 < l_ihigh_32) {
               if (Alerts) {
                  Alert("PriceAction AHA on ", Symbol(), " " + ls_16 + ": Positive Pin Bar!! ");
                  SendMail("PriceAction AHA: Pin Bar on " + Symbol() + " " + ls_16 + "!!", "PriceAction AHA: Positive Pin bar found on " + Symbol() + " " + ls_16 + "!!");
               }
               ai_0 = 1;
            }
         }
      }
   }
   if (CheckDoubleBarHighLows && !ai_4) {
      if (MathAbs(l_ilow_40 - l_ilow_48) <= 0.0 && l_iclose_72 > l_ihigh_32) {
         if (Alerts) {
            Alert("PriceAction AHA on ", Symbol(), " " + ls_16 + ": DBLHC!! ");
            SendMail("PriceAction AHA: DBLHC on " + Symbol() + " " + ls_16 + "!!", "PriceAction AHA: DBLHC found on " + Symbol() + " " + ls_16 + "!!");
         }
         ai_4 = 1;
      } else {
         if (MathAbs(l_ihigh_24 - l_ihigh_32) <= 0.0 && l_iclose_72 < l_ilow_48) {
            if (Alerts) {
               Alert("PriceAction AHA on ", Symbol(), " " + ls_16 + ": DBHLC!! ");
               SendMail("PriceAction AHA: DBHLC on " + Symbol() + " " + ls_16 + "!!", "PriceAction AHA: DBHLC found on " + Symbol() + " " + ls_16 + "!!");
            }
            ai_4 = 1;
         }
      }
   }
   if (CheckOutsideBars && !ai_8) {
      if (l_ilow_40 < l_ilow_48 && l_iclose_72 > l_ihigh_32) {
         if (Alerts) {
            Alert("PriceAction AHA on ", Symbol(), " " + ls_16 + ": BUOB!! ");
            SendMail("PriceAction AHA: BUOB on " + Symbol() + " " + ls_16 + "!!", "PriceAction AHA: BUOB found on " + Symbol() + " " + ls_16 + "!!");
         }
         ai_8 = 1;
      } else {
         if (l_iclose_72 < l_ilow_48 && l_ihigh_24 > l_ihigh_32) {
            if (Alerts) {
               Alert("PriceAction AHA on ", Symbol(), " " + ls_16 + ": BEOB!! ");
               SendMail("PriceAction AHA: BEOB on " + Symbol() + " " + ls_16 + "!!", "PriceAction AHA: BEOB found on " + Symbol() + " " + ls_16 + "!!");
            }
            ai_8 = 1;
         }
      }
   }
}

void CheckH1(int &ai_0, int &ai_4, int &ai_8) {
   double ld_88;
   double ld_96;
   double ld_104;
   double ld_112;
   double ld_120;
   if (Period() == PERIOD_H1) return;
   if (Minute() < 2) {
      ai_0 = 0;
      ai_4 = 0;
      ai_8 = 0;
      return;
   }
   if (Minute() >= 2 && Minute() < 55) return;
   int l_timeframe_12 = 60;
   string ls_16 = "H1";
   double l_ihigh_24 = iHigh(NULL, l_timeframe_12, 0);
   double l_ihigh_32 = iHigh(NULL, l_timeframe_12, 1);
   double l_ilow_40 = iLow(NULL, l_timeframe_12, 0);
   double l_ilow_48 = iLow(NULL, l_timeframe_12, 1);
   double l_iopen_56 = iOpen(NULL, l_timeframe_12, 0);
   double l_iopen_64 = iOpen(NULL, l_timeframe_12, 1);
   double l_iclose_72 = iClose(NULL, l_timeframe_12, 0);
   double l_iclose_80 = iClose(NULL, l_timeframe_12, 1);
   if (CheckPinBars && !ai_0) {
      ld_88 = l_ihigh_24 - l_ilow_40;
      if (ld_88 == 0.0) ld_88 = 0.0001;
      ld_96 = MathAbs(l_iopen_56 - l_iclose_72);
      ld_112 = l_ihigh_24 - MathMax(l_iopen_56, l_iclose_72);
      ld_120 = MathMin(l_iopen_56, l_iclose_72) - l_ilow_40;
      if (ld_112 >= ld_120) {
         ld_104 = ld_112;
         if (ld_104 / ld_88 > Min_Nose_Ratio / 100.0 && ld_96 / ld_88 < Max_Body_Ratio / 100.0 && l_ihigh_24 - l_ihigh_32 >= ld_88 / 3.0 || (l_ihigh_24 - l_ihigh_32 >= ld_88 / 4.0 &&
            ld_96 / ld_88 < 0.2) && l_ilow_40 > l_ilow_48) {
            if (Alerts) {
               Alert("PriceAction AHA on ", Symbol(), " " + ls_16 + ": Negative Pin Bar!! ");
               SendMail("PriceAction AHA: Pin Bar on " + Symbol() + " " + ls_16 + "!!", "PriceAction AHA: Negative Pin bar found on " + Symbol() + " " + ls_16 + "!!");
            }
            ai_0 = 1;
         }
      } else {
         if (ld_112 <= ld_120) {
            ld_104 = ld_120;
            if (ld_104 / ld_88 > Min_Nose_Ratio / 100.0 && ld_96 / ld_88 < Max_Body_Ratio / 100.0 && l_ilow_48 - l_ilow_40 >= ld_88 / 3.0 || (l_ilow_48 - l_ilow_40 >= ld_88 / 4.0 &&
               ld_96 / ld_88 < 0.2) && l_ihigh_24 < l_ihigh_32) {
               if (Alerts) {
                  Alert("PriceAction AHA on ", Symbol(), " " + ls_16 + ": Positive Pin Bar!! ");
                  SendMail("PriceAction AHA: Pin Bar on " + Symbol() + " " + ls_16 + "!!", "PriceAction AHA: Positive Pin bar found on " + Symbol() + " " + ls_16 + "!!");
               }
               ai_0 = 1;
            }
         }
      }
   }
   if (CheckDoubleBarHighLows && !ai_4) {
      if (MathAbs(l_ilow_40 - l_ilow_48) <= 0.0 && l_iclose_72 > l_ihigh_32) {
         if (Alerts) {
            Alert("PriceAction AHA on ", Symbol(), " " + ls_16 + ": DBLHC!! ");
            SendMail("PriceAction AHA: DBLHC on " + Symbol() + " " + ls_16 + "!!", "PriceAction AHA: DBLHC found on " + Symbol() + " " + ls_16 + "!!");
         }
         ai_4 = 1;
      } else {
         if (MathAbs(l_ihigh_24 - l_ihigh_32) <= 0.0 && l_iclose_72 < l_ilow_48) {
            if (Alerts) {
               Alert("PriceAction AHA on ", Symbol(), " " + ls_16 + ": DBHLC!! ");
               SendMail("PriceAction AHA: DBHLC on " + Symbol() + " " + ls_16 + "!!", "PriceAction AHA: DBHLC found on " + Symbol() + " " + ls_16 + "!!");
            }
            ai_4 = 1;
         }
      }
   }
   if (CheckOutsideBars && !ai_8) {
      if (l_ilow_40 < l_ilow_48 && l_iclose_72 > l_ihigh_32) {
         if (Alerts) {
            Alert("PriceAction AHA on ", Symbol(), " " + ls_16 + ": BUOB!! ");
            SendMail("PriceAction AHA: BUOB on " + Symbol() + " " + ls_16 + "!!", "PriceAction AHA: BUOB found on " + Symbol() + " " + ls_16 + "!!");
         }
         ai_8 = 1;
      } else {
         if (l_iclose_72 < l_ilow_48 && l_ihigh_24 > l_ihigh_32) {
            if (Alerts) {
               Alert("PriceAction AHA on ", Symbol(), " " + ls_16 + ": BEOB!! ");
               SendMail("PriceAction AHA: BEOB on " + Symbol() + " " + ls_16 + "!!", "PriceAction AHA: BEOB found on " + Symbol() + " " + ls_16 + "!!");
            }
            ai_8 = 1;
         }
      }
   }
}

void CheckH4(int &ai_0, int &ai_4, int &ai_8, int &ai_12) {
   double ld_92;
   double ld_100;
   double ld_108;
   double ld_116;
   double ld_124;
   double ld_132;
   double ld_140;
   double ld_148;
   double ld_156;
   if (Period() == PERIOD_H4) return;
   if (MathMod(Hour(), 4) == 0.0 && Minute() < 2) {
      ai_0 = 0;
      ai_4 = 0;
      ai_8 = 0;
      ai_12 = 0;
      return;
   }
   if (!(MathMod(Hour(), 4) == 3.0 && Minute() > 50)) return;
   int l_timeframe_16 = 240;
   string ls_20 = "H4";
   double l_ihigh_28 = iHigh(NULL, l_timeframe_16, 0);
   double l_ihigh_36 = iHigh(NULL, l_timeframe_16, 1);
   double l_ilow_44 = iLow(NULL, l_timeframe_16, 0);
   double l_ilow_52 = iLow(NULL, l_timeframe_16, 1);
   double l_iopen_60 = iOpen(NULL, l_timeframe_16, 0);
   double l_iopen_68 = iOpen(NULL, l_timeframe_16, 1);
   double l_iclose_76 = iClose(NULL, l_timeframe_16, 0);
   double l_iclose_84 = iClose(NULL, l_timeframe_16, 1);
   if (CheckPinBars && !ai_0) {
      ld_92 = l_ihigh_28 - l_ilow_44;
      if (ld_92 == 0.0) ld_92 = 0.0001;
      ld_100 = MathAbs(l_iopen_60 - l_iclose_76);
      ld_116 = l_ihigh_28 - MathMax(l_iopen_60, l_iclose_76);
      ld_124 = MathMin(l_iopen_60, l_iclose_76) - l_ilow_44;
      if (ld_116 >= ld_124) {
         ld_108 = ld_116;
         if (ld_108 / ld_92 > Min_Nose_Ratio / 100.0 && ld_100 / ld_92 < Max_Body_Ratio / 100.0 && l_ihigh_28 - l_ihigh_36 >= ld_92 / 3.0 || (l_ihigh_28 - l_ihigh_36 >= ld_92 / 4.0 &&
            ld_100 / ld_92 < 0.2) && l_ilow_44 > l_ilow_52) {
            if (Alerts) {
               Alert("PriceAction AHA on ", Symbol(), " " + ls_20 + ": Negative Pin Bar!! ");
               SendMail("PriceAction AHA: Pin Bar on " + Symbol() + " " + ls_20 + "!!", "PriceAction AHA: Negative Pin bar found on " + Symbol() + " " + ls_20 + "!!");
            }
            ai_0 = 1;
         }
      } else {
         if (ld_116 <= ld_124) {
            ld_108 = ld_124;
            if (ld_108 / ld_92 > Min_Nose_Ratio / 100.0 && ld_100 / ld_92 < Max_Body_Ratio / 100.0 && l_ilow_52 - l_ilow_44 >= ld_92 / 3.0 || (l_ilow_52 - l_ilow_44 >= ld_92 / 4.0 &&
               ld_100 / ld_92 < 0.2) && l_ihigh_28 < l_ihigh_36) {
               if (Alerts) {
                  Alert("PriceAction AHA on ", Symbol(), " " + ls_20 + ": Positive Pin Bar!! ");
                  SendMail("PriceAction AHA: Pin Bar on " + Symbol() + " " + ls_20 + "!!", "PriceAction AHA: Positive Pin bar found on " + Symbol() + " " + ls_20 + "!!");
               }
               ai_0 = 1;
            }
         }
      }
   }
   if (CheckDoubleBarHighLows && !ai_4) {
      if (MathAbs(l_ilow_44 - l_ilow_52) <= 0.0 && l_iclose_76 > l_ihigh_36) {
         if (Alerts) {
            Alert("PriceAction AHA on ", Symbol(), " " + ls_20 + ": DBLHC!! ");
            SendMail("PriceAction AHA: DBLHC on " + Symbol() + " " + ls_20 + "!!", "PriceAction AHA: DBLHC found on " + Symbol() + " " + ls_20 + "!!");
         }
         ai_4 = 1;
      } else {
         if (MathAbs(l_ihigh_28 - l_ihigh_36) <= 0.0 && l_iclose_76 < l_ilow_52) {
            if (Alerts) {
               Alert("PriceAction AHA on ", Symbol(), " " + ls_20 + ": DBHLC!! ");
               SendMail("PriceAction AHA: DBHLC on " + Symbol() + " " + ls_20 + "!!", "PriceAction AHA: DBHLC found on " + Symbol() + " " + ls_20 + "!!");
            }
            ai_4 = 1;
         }
      }
   }
   if (CheckOutsideBars && !ai_8) {
      if (l_ilow_44 < l_ilow_52 && l_iclose_76 > l_ihigh_36) {
         if (Alerts) {
            Alert("PriceAction AHA on ", Symbol(), " " + ls_20 + ": BUOB!! ");
            SendMail("PriceAction AHA: BUOB on " + Symbol() + " " + ls_20 + "!!", "PriceAction AHA: BUOB found on " + Symbol() + " " + ls_20 + "!!");
         }
         ai_8 = 1;
      } else {
         if (l_iclose_76 < l_ilow_52 && l_ihigh_28 > l_ihigh_36) {
            if (Alerts) {
               Alert("PriceAction AHA on ", Symbol(), " " + ls_20 + ": BEOB!! ");
               SendMail("PriceAction AHA: BEOB on " + Symbol() + " " + ls_20 + "!!", "PriceAction AHA: BEOB found on " + Symbol() + " " + ls_20 + "!!");
            }
            ai_8 = 1;
         }
      }
   }
   if (CheckI4Bars && !ai_12) {
      ld_132 = l_ihigh_28 - l_ilow_44;
      ld_140 = l_ihigh_36 - l_ilow_52;
      ld_148 = iHigh(NULL, l_timeframe_16, 2) - iLow(NULL, l_timeframe_16, 2);
      ld_156 = iHigh(NULL, l_timeframe_16, 3) - iLow(NULL, l_timeframe_16, 3);
      if (ld_132 < ld_140 && ld_132 < ld_148 && ld_132 < ld_156 && l_ihigh_28 < l_ihigh_36 && l_ilow_44 > l_ilow_52) {
         if (Alerts) {
            Alert("PriceAction AHA on ", Symbol(), " " + ls_20 + ": I4B!! ");
            SendMail("PriceAction AHA: I4B on " + Symbol() + " " + ls_20 + "!!", "PriceAction AHA: I4B found on " + Symbol() + " " + ls_20 + "!!");
         }
         ai_12 = 1;
      }
   }
}

void CheckD1(int &ai_0, int &ai_4, int &ai_8, int &ai_12) {
   int li_32;
   int li_36;
   int li_40;
   int li_44;
   double ld_48;
   double ld_56;
   double ld_64;
   double ld_72;
   double ld_148;
   double ld_156;
   double ld_164;
   double ld_172;
   double ld_180;
   if (Period() == PERIOD_D1) return;
   int l_timeframe_16 = 1440;
   string ls_20 = "D1";
   int l_day_of_week_28 = TimeDayOfWeek(iTime(NULL, l_timeframe_16, 0));
   if (l_day_of_week_28 == 0 || (Hour() == 0 && Minute() < 10)) {
      ai_0 = 0;
      ai_4 = 0;
      ai_8 = 0;
      ai_12 = 0;
      return;
   }
   if (!((Hour() >= 23 && Minute() > 50) || (l_day_of_week_28 == 5 && Hour() >= 19 && Minute() > 50))) return;
   switch (l_day_of_week_28) {
   case 4:
   case 5:
      li_32 = 0;
      li_36 = 1;
      li_40 = 2;
      li_44 = 3;
      break;
   case 3:
      li_32 = 0;
      li_36 = 1;
      li_40 = 2;
      li_44 = 4;
      break;
   case 2:
      li_32 = 0;
      li_36 = 1;
      li_40 = 3;
      li_44 = 4;
      break;
   case 1:
      li_32 = 0;
      li_36 = 2;
      li_40 = 3;
      li_44 = 4;
      break;
   default:
      break;
   default:
      return;
   }
   double l_ihigh_84 = iHigh(NULL, l_timeframe_16, li_32);
   double l_ihigh_92 = iHigh(NULL, l_timeframe_16, li_36);
   double l_ilow_100 = iLow(NULL, l_timeframe_16, li_32);
   double l_ilow_108 = iLow(NULL, l_timeframe_16, li_36);
   double l_iopen_116 = iOpen(NULL, l_timeframe_16, li_32);
   double l_iopen_124 = iOpen(NULL, l_timeframe_16, li_36);
   double l_iclose_132 = iClose(NULL, l_timeframe_16, li_32);
   double l_iclose_140 = iClose(NULL, l_timeframe_16, li_36);
   if (CheckPinBars && !ai_0) {
      ld_148 = l_ihigh_84 - l_ilow_100;
      if (ld_148 == 0.0) ld_148 = 0.0001;
      ld_156 = MathAbs(l_iopen_116 - l_iclose_132);
      ld_172 = l_ihigh_84 - MathMax(l_iopen_116, l_iclose_132);
      ld_180 = MathMin(l_iopen_116, l_iclose_132) - l_ilow_100;
      if (ld_172 >= ld_180) {
         ld_164 = ld_172;
         if (ld_164 / ld_148 > Min_Nose_Ratio / 100.0 && ld_156 / ld_148 < Max_Body_Ratio / 100.0 && l_ihigh_84 - l_ihigh_92 >= ld_148 / 3.0 || (l_ihigh_84 - l_ihigh_92 >= ld_148 / 4.0 &&
            ld_156 / ld_148 < 0.2) && l_ilow_100 > l_ilow_108) {
            if (Alerts) {
               Alert("PriceAction AHA on ", Symbol(), " " + ls_20 + ": Negative Pin Bar!! ");
               SendMail("PriceAction AHA: Pin Bar on " + Symbol() + " " + ls_20 + "!!", "PriceAction AHA: Negative Pin bar found on " + Symbol() + " " + ls_20 + "!!");
            }
            ai_0 = 1;
         }
      } else {
         if (ld_172 <= ld_180) {
            ld_164 = ld_180;
            if (ld_164 / ld_148 > Min_Nose_Ratio / 100.0 && ld_156 / ld_148 < Max_Body_Ratio / 100.0 && l_ilow_108 - l_ilow_100 >= ld_148 / 3.0 || (l_ilow_108 - l_ilow_100 >= ld_148 / 4.0 &&
               ld_156 / ld_148 < 0.2) && l_ihigh_84 < l_ihigh_92) {
               if (Alerts) {
                  Alert("PriceAction AHA on ", Symbol(), " " + ls_20 + ": Positive Pin Bar!! ");
                  SendMail("PriceAction AHA: Pin Bar on " + Symbol() + " " + ls_20 + "!!", "PriceAction AHA: Positive Pin bar found on " + Symbol() + " " + ls_20 + "!!");
               }
               ai_0 = 1;
            }
         }
      }
   }
   if (CheckDoubleBarHighLows && !ai_4) {
      if (MathAbs(l_ilow_100 - l_ilow_108) <= 0.0 && l_iclose_132 > l_ihigh_92) {
         if (Alerts) {
            Alert("PriceAction AHA on ", Symbol(), " " + ls_20 + ": DBLHC!! ");
            SendMail("PriceAction AHA: DBLHC on " + Symbol() + " " + ls_20 + "!!", "PriceAction AHA: DBLHC found on " + Symbol() + " " + ls_20 + "!!");
         }
         ai_4 = 1;
      } else {
         if (MathAbs(l_ihigh_84 - l_ihigh_92) <= 0.0 && l_iclose_132 < l_ilow_108) {
            if (Alerts) {
               Alert("PriceAction AHA on ", Symbol(), " " + ls_20 + ": DBHLC!! ");
               SendMail("PriceAction AHA: DBHLC on " + Symbol() + " " + ls_20 + "!!", "PriceAction AHA: DBHLC found on " + Symbol() + " " + ls_20 + "!!");
            }
            ai_4 = 1;
         }
      }
   }
   if (CheckOutsideBars && !ai_8) {
      if (l_ilow_100 < l_ilow_108 && l_iclose_132 > l_ihigh_92) {
         if (Alerts) {
            Alert("PriceAction AHA on ", Symbol(), " " + ls_20 + ": BUOB!! ");
            SendMail("PriceAction AHA: BUOB on " + Symbol() + " " + ls_20 + "!!", "PriceAction AHA: BUOB found on " + Symbol() + " " + ls_20 + "!!");
         }
         ai_8 = 1;
      } else {
         if (l_iclose_132 < l_ilow_108 && l_ihigh_84 > l_ihigh_92) {
            if (Alerts) {
               Alert("PriceAction AHA on ", Symbol(), " " + ls_20 + ": BEOB!! ");
               SendMail("PriceAction AHA: BEOB on " + Symbol() + " " + ls_20 + "!!", "PriceAction AHA: BEOB found on " + Symbol() + " " + ls_20 + "!!");
            }
            ai_8 = 1;
         }
      }
   }
   if (CheckI4Bars && !ai_12) {
      ld_48 = l_ihigh_84 - l_ilow_100;
      ld_56 = l_ihigh_92 - l_ilow_108;
      ld_64 = iHigh(NULL, l_timeframe_16, li_40) - iLow(NULL, l_timeframe_16, li_40);
      ld_72 = iHigh(NULL, l_timeframe_16, li_44) - iLow(NULL, l_timeframe_16, li_44);
      if (ld_48 < ld_56 && ld_48 < ld_64 && ld_48 < ld_72 && l_ihigh_84 < l_ihigh_92 && l_ilow_100 > l_ilow_108) {
         if (Alerts) {
            Alert("PriceAction AHA on ", Symbol(), " " + ls_20 + ": I4B!! ");
            SendMail("PriceAction AHA: I4B on " + Symbol() + " " + ls_20 + "!!", "PriceAction AHA: I4B found on " + Symbol() + " " + ls_20 + "!!");
         }
         ai_12 = 1;
      }
   }
}

void CheckW1(int &ai_0, int &ai_4, int &ai_8, int &ai_12) {
   double ld_96;
   double ld_104;
   double ld_112;
   double ld_120;
   double ld_128;
   double ld_136;
   double ld_144;
   double ld_152;
   double ld_160;
   if (Period() == PERIOD_W1) return;
   int l_timeframe_16 = 10080;
   string ls_20 = "W1";
   int l_day_of_week_28 = TimeDayOfWeek(iTime(NULL, PERIOD_D1, 0));
   if (l_day_of_week_28 == 0 && Hour() <= 23 && Minute() < 2) {
      ai_0 = 0;
      ai_4 = 0;
      ai_8 = 0;
      ai_12 = 0;
      return;
   }
   if (!(l_day_of_week_28 == 5 && Hour() == 19 && Minute() < 50)) return;
   double l_ihigh_32 = iHigh(NULL, l_timeframe_16, 0);
   double l_ihigh_40 = iHigh(NULL, l_timeframe_16, 1);
   double l_ilow_48 = iLow(NULL, l_timeframe_16, 0);
   double l_ilow_56 = iLow(NULL, l_timeframe_16, 1);
   double l_iopen_64 = iOpen(NULL, l_timeframe_16, 0);
   double l_iopen_72 = iOpen(NULL, l_timeframe_16, 1);
   double l_iclose_80 = iClose(NULL, l_timeframe_16, 0);
   double l_iclose_88 = iClose(NULL, l_timeframe_16, 1);
   if (CheckPinBars && !ai_0) {
      ld_96 = l_ihigh_32 - l_ilow_48;
      if (ld_96 == 0.0) ld_96 = 0.0001;
      ld_104 = MathAbs(l_iopen_64 - l_iclose_80);
      ld_120 = l_ihigh_32 - MathMax(l_iopen_64, l_iclose_80);
      ld_128 = MathMin(l_iopen_64, l_iclose_80) - l_ilow_48;
      if (ld_120 >= ld_128) {
         ld_112 = ld_120;
         if (ld_112 / ld_96 > Min_Nose_Ratio / 100.0 && ld_104 / ld_96 < Max_Body_Ratio / 100.0 && l_ihigh_32 - l_ihigh_40 >= ld_96 / 3.0 || (l_ihigh_32 - l_ihigh_40 >= ld_96 / 4.0 &&
            ld_104 / ld_96 < 0.2) && l_ilow_48 > l_ilow_56) {
            if (Alerts) {
               Alert("PriceAction AHA on ", Symbol(), " " + ls_20 + ": Negative Pin Bar!! ");
               SendMail("PriceAction AHA: Pin Bar on " + Symbol() + " " + ls_20 + "!!", "PriceAction AHA: Negative Pin bar found on " + Symbol() + " " + ls_20 + "!!");
            }
            ai_0 = 1;
         }
      } else {
         if (ld_120 <= ld_128) {
            ld_112 = ld_128;
            if (ld_112 / ld_96 > Min_Nose_Ratio / 100.0 && ld_104 / ld_96 < Max_Body_Ratio / 100.0 && l_ilow_56 - l_ilow_48 >= ld_96 / 3.0 || (l_ilow_56 - l_ilow_48 >= ld_96 / 4.0 &&
               ld_104 / ld_96 < 0.2) && l_ihigh_32 < l_ihigh_40) {
               if (Alerts) {
                  Alert("PriceAction AHA on ", Symbol(), " " + ls_20 + ": Positive Pin Bar!! ");
                  SendMail("PriceAction AHA: Pin Bar on " + Symbol() + " " + ls_20 + "!!", "PriceAction AHA: Positive Pin bar found on " + Symbol() + " " + ls_20 + "!!");
               }
               ai_0 = 1;
            }
         }
      }
   }
   if (CheckDoubleBarHighLows && !ai_4) {
      if (MathAbs(l_ilow_48 - l_ilow_56) <= 0.0 && l_iclose_80 > l_ihigh_40) {
         if (Alerts) {
            Alert("PriceAction AHA on ", Symbol(), " " + ls_20 + ": DBLHC!! ");
            SendMail("PriceAction AHA: DBLHC on " + Symbol() + " " + ls_20 + "!!", "PriceAction AHA: DBLHC found on " + Symbol() + " " + ls_20 + "!!");
         }
         ai_4 = 1;
      } else {
         if (MathAbs(l_ihigh_32 - l_ihigh_40) <= 0.0 && l_iclose_80 < l_ilow_56) {
            if (Alerts) {
               Alert("PriceAction AHA on ", Symbol(), " " + ls_20 + ": DBHLC!! ");
               SendMail("PriceAction AHA: DBHLC on " + Symbol() + " " + ls_20 + "!!", "PriceAction AHA: DBHLC found on " + Symbol() + " " + ls_20 + "!!");
            }
            ai_4 = 1;
         }
      }
   }
   if (CheckOutsideBars && !ai_8) {
      if (l_ilow_48 < l_ilow_56 && l_iclose_80 > l_ihigh_40) {
         if (Alerts) {
            Alert("PriceAction AHA on ", Symbol(), " " + ls_20 + ": BUOB!! ");
            SendMail("PriceAction AHA: BUOB on " + Symbol() + " " + ls_20 + "!!", "PriceAction AHA: BUOB found on " + Symbol() + " " + ls_20 + "!!");
         }
         ai_8 = 1;
      } else {
         if (l_iclose_80 < l_ilow_56 && l_ihigh_32 > l_ihigh_40) {
            if (Alerts) {
               Alert("PriceAction AHA on ", Symbol(), " " + ls_20 + ": BEOB!! ");
               SendMail("PriceAction AHA: BEOB on " + Symbol() + " " + ls_20 + "!!", "PriceAction AHA: BEOB found on " + Symbol() + " " + ls_20 + "!!");
            }
            ai_8 = 1;
         }
      }
   }
   if (CheckI4Bars && !ai_12) {
      ld_136 = l_ihigh_32 - l_ilow_48;
      ld_144 = l_ihigh_40 - l_ilow_56;
      ld_152 = iHigh(NULL, l_timeframe_16, 2) - iLow(NULL, l_timeframe_16, 2);
      ld_160 = iHigh(NULL, l_timeframe_16, 3) - iLow(NULL, l_timeframe_16, 3);
      if (ld_136 < ld_144 && ld_136 < ld_152 && ld_136 < ld_160 && l_ihigh_32 < l_ihigh_40 && l_ilow_48 > l_ilow_56) {
         if (Alerts) {
            Alert("PriceAction AHA on ", Symbol(), " " + ls_20 + ": I4B!! ");
            SendMail("PriceAction AHA: I4B on " + Symbol() + " " + ls_20 + "!!", "PriceAction AHA: I4B found on " + Symbol() + " " + ls_20 + "!!");
         }
         ai_12 = 1;
      }
   }
}

void CheckMN1(int &ai_0, int &ai_4, int &ai_8, int &ai_12) {
   double ld_96;
   double ld_104;
   double ld_112;
   double ld_120;
   double ld_128;
   double ld_136;
   double ld_144;
   double ld_152;
   double ld_160;
   if (Period() == PERIOD_MN1) return;
   int l_timeframe_16 = 43200;
   string ls_20 = "MN1";
   int l_day_28 = TimeDay(iTime(NULL, PERIOD_D1, 0));
   if (l_day_28 == 0 || l_day_28 >= 28 && Hour() == 0 && Minute() < 2) {
      ai_0 = 0;
      ai_4 = 0;
      ai_8 = 0;
      ai_12 = 0;
      return;
   }
   if (!(l_day_28 >= 28 && Hour() == 23 && Minute() > 50)) return;
   double l_ihigh_32 = iHigh(NULL, l_timeframe_16, 0);
   double l_ihigh_40 = iHigh(NULL, l_timeframe_16, 1);
   double l_ilow_48 = iLow(NULL, l_timeframe_16, 0);
   double l_ilow_56 = iLow(NULL, l_timeframe_16, 1);
   double l_iopen_64 = iOpen(NULL, l_timeframe_16, 0);
   double l_iopen_72 = iOpen(NULL, l_timeframe_16, 1);
   double l_iclose_80 = iClose(NULL, l_timeframe_16, 0);
   double l_iclose_88 = iClose(NULL, l_timeframe_16, 1);
   if (CheckPinBars && !ai_0) {
      ld_96 = l_ihigh_32 - l_ilow_48;
      if (ld_96 == 0.0) ld_96 = 0.0001;
      ld_104 = MathAbs(l_iopen_64 - l_iclose_80);
      ld_120 = l_ihigh_32 - MathMax(l_iopen_64, l_iclose_80);
      ld_128 = MathMin(l_iopen_64, l_iclose_80) - l_ilow_48;
      if (ld_120 >= ld_128) {
         ld_112 = ld_120;
         if (ld_112 / ld_96 > Min_Nose_Ratio / 100.0 && ld_104 / ld_96 < Max_Body_Ratio / 100.0 && l_ihigh_32 - l_ihigh_40 >= ld_96 / 3.0 || (l_ihigh_32 - l_ihigh_40 >= ld_96 / 4.0 &&
            ld_104 / ld_96 < 0.2) && l_ilow_48 > l_ilow_56) {
            if (Alerts) {
               Alert("PriceAction AHA on ", Symbol(), " " + ls_20 + ": Negative Pin Bar!! ");
               SendMail("PriceAction AHA: Pin Bar on " + Symbol() + " " + ls_20 + "!!", "PriceAction AHA: Negative Pin bar found on " + Symbol() + " " + ls_20 + "!!");
            }
            ai_0 = 1;
         }
      } else {
         if (ld_120 <= ld_128) {
            ld_112 = ld_128;
            if (ld_112 / ld_96 > Min_Nose_Ratio / 100.0 && ld_104 / ld_96 < Max_Body_Ratio / 100.0 && l_ilow_56 - l_ilow_48 >= ld_96 / 3.0 || (l_ilow_56 - l_ilow_48 >= ld_96 / 4.0 &&
               ld_104 / ld_96 < 0.2) && l_ihigh_32 < l_ihigh_40) {
               if (Alerts) {
                  Alert("PriceAction AHA on ", Symbol(), " " + ls_20 + ": Positive Pin Bar!! ");
                  SendMail("PriceAction AHA: Pin Bar on " + Symbol() + " " + ls_20 + "!!", "PriceAction AHA: Positive Pin bar found on " + Symbol() + " " + ls_20 + "!!");
               }
               ai_0 = 1;
            }
         }
      }
   }
   if (CheckDoubleBarHighLows && !ai_4) {
      if (MathAbs(l_ilow_48 - l_ilow_56) <= 0.0 && l_iclose_80 > l_ihigh_40) {
         if (Alerts) {
            Alert("PriceAction AHA on ", Symbol(), " " + ls_20 + ": DBLHC!! ");
            SendMail("PriceAction AHA: DBLHC on " + Symbol() + " " + ls_20 + "!!", "PriceAction AHA: DBLHC found on " + Symbol() + " " + ls_20 + "!!");
         }
         ai_4 = 1;
      } else {
         if (MathAbs(l_ihigh_32 - l_ihigh_40) <= 0.0 && l_iclose_80 < l_ilow_56) {
            if (Alerts) {
               Alert("PriceAction AHA on ", Symbol(), " " + ls_20 + ": DBHLC!! ");
               SendMail("PriceAction AHA: DBHLC on " + Symbol() + " " + ls_20 + "!!", "PriceAction AHA: DBHLC found on " + Symbol() + " " + ls_20 + "!!");
            }
            ai_4 = 1;
         }
      }
   }
   if (CheckOutsideBars && !ai_8) {
      if (l_ilow_48 < l_ilow_56 && l_iclose_80 > l_ihigh_40) {
         if (Alerts) {
            Alert("PriceAction AHA on ", Symbol(), " " + ls_20 + ": BUOB!! ");
            SendMail("PriceAction AHA: BUOB on " + Symbol() + " " + ls_20 + "!!", "PriceAction AHA: BUOB found on " + Symbol() + " " + ls_20 + "!!");
         }
         ai_8 = 1;
      } else {
         if (l_iclose_80 < l_ilow_56 && l_ihigh_32 > l_ihigh_40) {
            if (Alerts) {
               Alert("PriceAction AHA on ", Symbol(), " " + ls_20 + ": BEOB!! ");
               SendMail("PriceAction AHA: BEOB on " + Symbol() + " " + ls_20 + "!!", "PriceAction AHA: BEOB found on " + Symbol() + " " + ls_20 + "!!");
            }
            ai_8 = 1;
         }
      }
   }
   if (CheckI4Bars && !ai_12) {
      ld_136 = l_ihigh_32 - l_ilow_48;
      ld_144 = l_ihigh_40 - l_ilow_56;
      ld_152 = iHigh(NULL, l_timeframe_16, 2) - iLow(NULL, l_timeframe_16, 2);
      ld_160 = iHigh(NULL, l_timeframe_16, 3) - iLow(NULL, l_timeframe_16, 3);
      if (ld_136 < ld_144 && ld_136 < ld_152 && ld_136 < ld_160 && l_ihigh_32 < l_ihigh_40 && l_ilow_48 > l_ilow_56) {
         if (Alerts) {
            Alert("PriceAction AHA on ", Symbol(), " " + ls_20 + ": I4B!! ");
            SendMail("PriceAction AHA: I4B on " + Symbol() + " " + ls_20 + "!!", "PriceAction AHA: I4B found on " + Symbol() + " " + ls_20 + "!!");
         }
         ai_12 = 1;
      }
   }
}

int start() {
   bool li_4 = FALSE;
   bool li_8 = FALSE;
   CheckTime(li_4, li_8, gi_180);
   if (gi_160 && History) {
      for (int li_0 = Bars - 1; li_0 >= 1; li_0--) {
         CheckPPB(li_0, g_ibuf_136, gi_164, 1);
         CheckNPB(li_0, g_ibuf_140, gi_168, 1);
         CheckI4B(li_0, g_ibuf_144, g_ibuf_148, 1);
         CheckBullB(li_0, g_ibuf_152, gi_164, 1);
         CheckBearB(li_0, g_ibuf_156, gi_168, 1);
      }
   }
   if (li_4) {
      CheckPPB(0, g_ibuf_136, gi_164);
      CheckNPB(0, g_ibuf_140, gi_168);
      CheckI4B(0, g_ibuf_144, g_ibuf_148);
      CheckBullB(0, g_ibuf_152, gi_164);
      CheckBearB(0, g_ibuf_156, gi_168);
   }
   if (li_8) {
      CheckPPB(1, g_ibuf_136, gi_164, 1);
      CheckNPB(1, g_ibuf_140, gi_168, 1);
      CheckI4B(1, g_ibuf_144, g_ibuf_148, 1);
      CheckBullB(1, g_ibuf_152, gi_164, 1);
      CheckBearB(1, g_ibuf_156, gi_168, 1);
   }
   if (SearchM15) CheckM15(gi_192, gi_196, gi_212);
   if (SearchM30) CheckM30(gi_204, gi_208, gi_212);
   if (SearchH1) CheckH1(gi_216, gi_220, gi_224);
   if (SearchH4) CheckH4(gi_228, gi_232, gi_236, gi_240);
   if (SearchD1) CheckD1(gi_244, gi_248, gi_252, gi_256);
   if (SearchW1) CheckW1(gi_260, gi_264, gi_268, gi_272);
   if (SearchMN1) CheckMN1(gi_276, gi_280, gi_284, gi_288);
   gi_160 = FALSE;
   return (0);
}