Navigation:Home > Content >

PrevDayAndFloatingPivot_Alert.mq4

Time: 2015-08-11 | Download file:PrevDayAndFloatingPivot_Alert.mq4

/*
   Generated by EX4-TO-MQ4 decompiler V4.0.224.1 []
   Website: http://purebeam.biz
   E-mail : [email protected]
*/
#property copyright "Copyright © 2006, [email protected]"
#property link      "http://www.metatrader.org"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 DodgerBlue

extern bool PivAlert = TRUE;
extern bool PivSound = TRUE;
double g_ibuf_84[];
double g_ibuf_88[];
string gs_92 = "";

int init() {
   SetIndexStyle(0, DRAW_LINE);
   SetIndexBuffer(0, g_ibuf_84);
   SetIndexStyle(1, DRAW_LINE);
   SetIndexBuffer(1, g_ibuf_88);
   SetIndexLabel(0, "Previous Day Pivot");
   SetIndexLabel(1, "Floating current pivot");
   return (0);
}

int deinit() {
   return (0);
}

int TodaysBarShift(int ai_0) {
   int l_datetime_4 = iTime(NULL, Period(), ai_0);
   int l_shift_8 = iBarShift(NULL, PERIOD_D1, l_datetime_4, FALSE);
   int l_datetime_12 = iTime(NULL, PERIOD_D1, l_shift_8);
   if (l_datetime_12 > l_datetime_4) l_shift_8++;
   return (l_shift_8);
}

int PreviousNonSundayBarShift(int ai_0) {
   int li_4 = TodaysBarShift(ai_0);
   int li_ret_8 = li_4 + 1;
   int l_datetime_12 = iTime(NULL, PERIOD_D1, li_ret_8);
   if (TimeDayOfWeek(l_datetime_12) == 0) li_ret_8++;
   return (li_ret_8);
}

void TodaysHighestLowest(double &ad_0, double &ad_8, int ai_16) {
   double ld_36;
   double ld_44;
   int l_datetime_20 = iTime(NULL, Period(), ai_16);
   int li_24 = TodaysBarShift(ai_16);
   int l_datetime_28 = iTime(NULL, PERIOD_D1, li_24);
   ad_0 = High[ai_16];
   ad_8 = Low[ai_16];
   int li_32 = ai_16 + 1;
   while (iTime(NULL, Period(), li_32) >= l_datetime_28) {
      ld_36 = High[li_32];
      ld_44 = Low[li_32];
      ad_0 = MathMax(ad_0, ld_36);
      ad_8 = MathMin(ad_8, ld_44);
      li_32++;
      if (li_32 - ai_16 > 24) {
         Print("Shit!");
         return;
      }
   }
}

int start() {
   int li_12;
   int li_16;
   double ld_20;
   double ld_28;
   double ld_36;
   double ld_44;
   string ls_52;
   int l_ind_counted_0 = IndicatorCounted();
   int li_4 = Bars - l_ind_counted_0;
   for (int li_8 = li_4; li_8 >= 0; li_8--) {
      li_12 = PreviousNonSundayBarShift(li_8);
      li_16 = TodaysBarShift(li_8);
      ld_20 = (iHigh(NULL, PERIOD_D1, li_12) + iLow(NULL, PERIOD_D1, li_12) + iClose(NULL, PERIOD_D1, li_12) + iOpen(NULL, PERIOD_D1, li_16)) / 4.0;
      TodaysHighestLowest(ld_28, ld_36, li_8);
      ld_44 = 0.33333 * (ld_28 + ld_36 + Close[li_8]);
      g_ibuf_84[li_8] = ld_20;
      g_ibuf_88[li_8] = ld_44;
   }
   if (PivAlert == TRUE) {
      ls_52 = "";
      if (g_ibuf_88[1] - g_ibuf_84[1] > 0.0 && g_ibuf_88[0] - g_ibuf_84[0] < 0.0) ls_52 = "down";
      if (g_ibuf_88[1] - g_ibuf_84[1] < 0.0 && g_ibuf_88[0] - g_ibuf_84[0] > 0.0) ls_52 = "up";
      if (ls_52 != gs_92) {
         Alert(Symbol(), " M", Period(), " Pivot direction has changed ", ls_52);
         gs_92 = ls_52;
         if (PivSound == TRUE) PlaySound("alert2.wav");
      }
   }
   return (0);
}

Recommend