Navigation´╝ÜHome > Content >

KorDynamicFibonacci_v.0.2.3.mq4

Time: 2017-04-03 | Download file:KorDynamicFibonacci_v.0.2.3.mq4


#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Black
#property indicator_color2 Black
#property indicator_color3 Black

string gsa_76[50000][2];
string gsa_80[50000][2];
string gsa_84[50000][2];
string gsa_unused_88[50000][2];
double g_ibuf_92[];
double gda_unused_96[];
double gda_unused_100[];
int g_index_104;
int g_index_108;
int g_index_112;
int gi_unused_120 = 0;
double gd_unused_124 = 0.0;
double gd_unused_132 = 0.0;
double gd_unused_140 = 0.0;
double gd_unused_148 = 0.0;
int gi_unused_156 = 50;
extern string separator1 = "************************ Main Params ***";
extern int iextMaxBars = 10000;
extern int ZigZagMin = 100;
extern int ZigZagMax = 500;
extern int ZigZagStep = 10;
extern bool bextDrawFiboLines = TRUE;
extern bool bextMT4AlertON = FALSE;
int gi_unused_192 = 100;
int gi_196 = 150;
int gi_200 = 12;
extern string separator2 = "************************ Calculation deltas ***";
extern double dextMaxDeviation = 0.05;
extern string separator4 = "******************** Patterns ON/OFF ***";
extern string FiboLevelsStr = "0.0; 0.382; 0.500; 0.618; 1.00; 1.500; 2.00; 2.500; 3.00; 3.500; 4.00; 4.500; 5.00;";
double gda_236[30];
int gi_240;
extern string separator10 = "************************ Colors ***";
int gi_252 = 13828244;
extern color cextFiboLineColor = Red;
extern color cextFiboRelationLine = Chocolate;
extern color cextFiboRelationTextDesc = RoyalBlue;
extern color cextNonFiboRelationLine = C'0x41,0x41,0x41';
extern color cextNonFiboRelationTextDesc = DimGray;
extern int iextPatLineSize = 1;
extern string separator11 = "************************ Other Colors ***";
extern color extBackgroundColor = Black;
extern color extTextColor = White;
bool gi_296 = FALSE;
int gia_300[] = {8388736, 25600, 5197615, 32896, 255, 8421376, 8388608, 128, 8519755, 7346457, 9109504, 3107669, 1262987, 2263842, 2330219, 5737262, 755384, 9125192, 2970272, 13434880, 2763429, 13749760, 6908265, 11186720, 13828244, 2237106, 8721863, 7451452, 1993170, 3937500, 11829830, 2139610, 10156544, 64636, 10526303, 13382297, 3329434, 3329330, 17919, 36095, 42495, 55295, 65535, 65407, 65280, 8388352, 16776960, 16760576, 16711680, 16711935, 255, 8421504, 9470064, 4163021, 14822282, 10061943, 9639167, 13422920, 16748574, 13688896, 14772545, 13458026, 7059389, 6053069, 13850042, 3145645, 11193702, 9419919, 4678655, 9408444, 14053594, 14381203, 9662683, 5275647, 15570276, 11119017, 6333684, 15624315, 9221330, 8034025, 8894686, 11823615, 7504122, 15631086, 8421616, 15453831, 8036607, 14524637, 9234160, 9498256, 13959039, 12632256, 16436871, 14599344, 15128749, 10025880, 14204888, 15130800, 11200750, 15658671, 13882323, 11788021, 11394815, 11920639, 12695295, 14474460, 12180223, 13353215, 12903679, 13826810, 13495295, 13499135, 14480885, 14150650, 14020607, 14481663, 14745599, 16777184, 15134970, 16443110, 14804223, 15136253, 16119285, 15660543, 15794175, 15794160, 16775408, 16118015, 16449525, 16448255, 16777215};
int g_time_304 = 0;
int g_datetime_308 = 0;
extern int iextRefreshRate = 10;

int HL_CleanArrays() {
   for (int l_index_0 = 0; l_index_0 <= 50000; l_index_0++) {
      gsa_76[l_index_0][0] = 0;
      gsa_76[l_index_0][1] = 0;
      gsa_80[l_index_0][0] = 0;
      gsa_80[l_index_0][1] = 0;
      gsa_84[l_index_0][0] = 0;
      gsa_84[l_index_0][1] = 0;
   }
   return (0);
}

void HL_Calculate(int ai_0, int ai_4, int ai_unused_8, int ai_12) {
   double l_low_40;
   double l_high_48;
   int li_56 = -1;
   gi_unused_120 = 0;
   g_index_104 = 0;
   g_index_108 = 0;
   g_index_112 = 0;
   int li_60 = ai_0;
   int li_16 = li_60;
   double l_low_24 = Low[li_60];
   int li_20 = li_60;
   double l_high_32 = High[li_60];
   DrawPriceArrow(li_16, Time[li_16], l_low_24, Lime, "Buy");
   DrawPriceArrow(li_20, Time[li_20], l_high_32, Lime, "Sell");
   for (int li_64 = li_60; li_64 >= 0; li_64--) {
      l_low_40 = Low[li_64];
      l_high_48 = High[li_64];
      if (l_high_48 - l_low_24 > ai_12 * Point && li_56 == -1 || li_56 == 1) {
         gsa_80[g_index_104][0] = TimeToStr(Time[li_16], TIME_DATE|TIME_SECONDS);
         gsa_80[g_index_104][1] = DoubleToStr(l_low_24, 4);
         g_index_104++;
         gsa_84[g_index_112][0] = TimeToStr(Time[li_16], TIME_DATE|TIME_SECONDS);
         gsa_84[g_index_112][1] = DoubleToStr(l_low_24, 4);
         g_index_112++;
         l_low_24 = l_low_40;
         li_16 = li_64;
         l_high_32 = l_high_48;
         li_20 = li_64;
         if (li_56 == -1) gi_unused_120 = 1;
         li_56 = 0;
      } else {
         if (l_high_32 - l_low_40 > ai_12 * Point && li_56 == -1 || li_56 == 0) {
            gsa_76[g_index_108][0] = TimeToStr(Time[li_20], TIME_DATE|TIME_SECONDS);
            gsa_76[g_index_108][1] = DoubleToStr(l_high_32, 4);
            g_index_108++;
            gsa_84[g_index_112][0] = TimeToStr(Time[li_20], TIME_DATE|TIME_SECONDS);
            gsa_84[g_index_112][1] = DoubleToStr(l_high_32, 4);
            g_index_112++;
            l_high_32 = l_high_48;
            li_20 = li_64;
            l_low_24 = l_low_40;
            li_16 = li_64;
            if (li_56 == -1) gi_unused_120 = -1;
            li_56 = 1;
         }
      }
      if (l_low_40 < l_low_24) {
         l_low_24 = l_low_40;
         li_16 = li_64;
      }
      if (l_high_48 > l_high_32) {
         l_high_32 = l_high_48;
         li_20 = li_64;
      }
   }
   if (li_56 == 1) {
      gsa_84[g_index_112][0] = TimeToStr(Time[li_16], TIME_DATE|TIME_SECONDS);
      gsa_84[g_index_112][1] = DoubleToStr(l_low_24, 4);
      g_index_112++;
   } else {
      if (li_56 == 0) {
         gsa_84[g_index_112][0] = TimeToStr(Time[li_20], TIME_DATE|TIME_SECONDS);
         gsa_84[g_index_112][1] = DoubleToStr(l_high_32, 4);
         g_index_112++;
      }
   }
   if (ai_4 <= g_index_112) {
   }
}

void DrawPriceArrow(int ai_0, int a_datetime_4, double a_price_8, color a_color_16, string as_20) {
   string l_name_28 = "ZZ_START_" + "arraw_" + as_20 + ai_0;
   ObjectDelete(l_name_28);
   ObjectCreate(l_name_28, OBJ_ARROW, 0, a_datetime_4, a_price_8);
   ObjectSet(l_name_28, OBJPROP_WIDTH, 5);
   if (as_20 == "Buy") ObjectSet(l_name_28, OBJPROP_ARROWCODE, SYMBOL_ARROWUP);
   else
      if (as_20 == "Sell") ObjectSet(l_name_28, OBJPROP_ARROWCODE, SYMBOL_ARROWDOWN);
   ObjectSet(l_name_28, OBJPROP_COLOR, a_color_16);
}

void HL_InitZZLine(color a_color_0) {
   SetIndexStyle(0, DRAW_SECTION, STYLE_SOLID, 1, a_color_0);
   SetIndexLabel(0, "ZZLine");
   SetIndexBuffer(0, g_ibuf_92);
   SetIndexEmptyValue(0, 0.0);
}

string PeriodDesc(int ai_0) {
   switch (ai_0) {
   case 1:
      return ("M1");
   case 5:
      return ("M5");
   case 15:
      return ("M15");
   case 30:
      return ("M30");
   case 60:
      return ("H1");
   case 240:
      return ("H4");
   case 1440:
      return ("D1");
   case 10080:
      return ("W1");
   case 43200:
      return ("MN");
   }
   return ("Unknown Period");
}

int DropObjects(string as_0) {
   string l_name_8;
   bool l_bool_28;
   int l_error_32;
   int l_objs_total_16 = ObjectsTotal();
   int li_24 = 0;
   for (int l_count_20 = 0; l_count_20 < l_objs_total_16; l_count_20++) {
      l_name_8 = ObjectName(li_24);
      if (StringFind(l_name_8, as_0) >= 0) {
         l_bool_28 = ObjectDelete(l_name_8);
         if (l_bool_28 == FALSE) {
            l_error_32 = GetLastError();
            Alert("ERROR,res:::::::::", l_error_32);
         }
      } else li_24++;
   }
   return (0);
}

int ParseInputString2Doubles(string as_0, double &ada_8[]) {
   int li_16;
   int l_index_20 = 0;
   int li_12 = 0;
   for (int li_24 = 0; li_24 < StringLen(as_0); li_24++) {
      if (StringGetChar(as_0, li_24) == ';') {
         li_16 = li_24;
         ada_8[l_index_20] = StrToDouble(StringSubstr(as_0, li_12, li_16 - li_12));
         l_index_20++;
         if (l_index_20 == 30) return (l_index_20);
         li_12 = li_24 + 1;
      }
   }
   return (l_index_20);
}

void init() {
   HL_InitZZLine(gi_252);
   if (iextMaxBars > 50000) {
      Alert("ERROR:", "korDynamicFibo", ":", Symbol(), ":", PeriodDesc(Period()), ":", "Specified iextMaxBars number:", iextMaxBars, " in not supported, allowed:[0,", 50000, "] ...changing to max value...");
      iextMaxBars = 50000;
   }
   HL_CleanArrays();
   gi_240 = ParseInputString2Doubles(FiboLevelsStr, gda_236);
   gi_296 = TRUE;
}

void deinit() {
   Comment("");
   DropObjects("korDynamicFibo" + "0.1.4c");
   DropObjects("ZZ_START_");
   DropObjects("ZZ_POINT_");
   DropObjects("ZZ_LINE_");
   DropObjects("HAR_O_");
   DropObjects("HAR_S_");
}

void start() {
   double l_str2dbl_8;
   double l_str2dbl_16;
   double l_str2dbl_24;
   int l_str2time_36;
   int l_str2time_40;
   int l_str2time_44;
   int l_index_52;
   if (Time[0] > g_time_304 || TimeCurrent() > g_datetime_308 + iextRefreshRate) {
      g_time_304 = Time[0];
      g_datetime_308 = TimeCurrent();
      DropObjects("F_");
      l_index_52 = 0;
      if (gi_296 == TRUE) {
         HL_CleanArrays();
         for (int li_48 = ZigZagMin; li_48 < ZigZagMax; li_48 += ZigZagStep) {
            HL_Calculate(iextMaxBars, gi_200, gi_196, li_48);
            if (l_str2time_36 != StrToTime(gsa_84[g_index_112 - 3][0]) || l_str2dbl_8 != StrToDouble(gsa_84[g_index_112 - 3][1]) || l_str2time_40 != StrToTime(gsa_84[g_index_112 - 2][0]) ||
               l_str2dbl_16 != StrToDouble(gsa_84[g_index_112 - 2][1]) || l_str2time_44 != StrToTime(gsa_84[g_index_112 - 1][0]) || l_str2dbl_24 != StrToDouble(gsa_84[g_index_112 - 1][1])) {
               l_str2time_36 = StrToTime(gsa_84[g_index_112 - 3][0]);
               l_str2dbl_8 = StrToDouble(gsa_84[g_index_112 - 3][1]);
               l_str2time_40 = StrToTime(gsa_84[g_index_112 - 2][0]);
               l_str2dbl_16 = StrToDouble(gsa_84[g_index_112 - 2][1]);
               l_str2time_44 = StrToTime(gsa_84[g_index_112 - 1][0]);
               l_str2dbl_24 = StrToDouble(gsa_84[g_index_112 - 1][1]);
               Draw_Pattern_Fibo(li_48, 1, l_str2time_36, l_str2dbl_8, l_str2time_40, l_str2dbl_16, l_str2time_44, l_str2dbl_24, gia_300[l_index_52], l_index_52);
               Draw_Fibo_Box(l_str2dbl_8, l_str2dbl_16, l_str2dbl_24, gia_300[l_index_52], l_index_52);
               l_index_52++;
            }
         }
      }
   }
}

int Draw_Pattern_Fibo(int ai_0, int ai_4, int ai_8, double ad_12, int ai_20, double ad_24, int ai_32, double ad_36, int ai_44, int ai_unused_48) {
   if (ad_12 - ad_24 == 0.0) return (0);
   string l_dbl2str_52 = DoubleToStr((ad_36 - ad_24) / (ad_12 - ad_24), 3);
   if (bextDrawFiboLines) {
      DrawLine(ai_0, ai_4, ai_8, ad_12, ai_20, ad_24, ai_44, "AB", "Fibo", iextPatLineSize);
      DrawLine(ai_0, ai_4, ai_20, ad_24, ai_32, ad_36, ai_44, "BC", "Fibo", iextPatLineSize);
   }
   DrawRelationLine(ai_0, ai_4, ai_8, ad_12, ai_32, ad_36, l_dbl2str_52, ai_44, "relAC", "Fibo");
   return (0);
}

void DrawLine(int ai_0, int ai_4, int a_datetime_8, double a_price_12, int a_datetime_20, double a_price_24, color a_color_32, string as_36, string as_unused_44, int a_width_52) {
   string l_name_56 = "F_" + "line_" + ai_0 + "_" + ai_4 + "_" + as_36;
   ObjectDelete(l_name_56);
   ObjectCreate(l_name_56, OBJ_TREND, 0, a_datetime_8, a_price_12, a_datetime_20, a_price_24);
   ObjectSet(l_name_56, OBJPROP_COLOR, a_color_32);
   ObjectSet(l_name_56, OBJPROP_STYLE, STYLE_SOLID);
   ObjectSet(l_name_56, OBJPROP_WIDTH, a_width_52);
   ObjectSet(l_name_56, OBJPROP_BACK, TRUE);
   ObjectSet(l_name_56, OBJPROP_RAY, FALSE);
}

void DrawRelationLine(int ai_0, int ai_4, int a_datetime_8, double a_price_12, int a_datetime_20, double a_price_24, string as_32, color a_color_40, string as_unused_44, string as_unused_52) {
   string l_name_96;
   string l_name_104;
   int l_shift_112;
   int l_shift_116;
   int li_120;
   double ld_60 = dextMaxDeviation;
   double ld_68 = 1000;
   double l_str2dbl_76 = StrToDouble(as_32);
   string l_dbl2str_84 = "";
   for (int l_index_92 = 0; l_index_92 < gi_240; l_index_92++) {
      if (l_str2dbl_76 >= gda_236[l_index_92] * (1.0 - ld_60) && l_str2dbl_76 <= gda_236[l_index_92] * (ld_60 + 1.0) && MathAbs(l_str2dbl_76 - gda_236[l_index_92]) < ld_68) {
         l_dbl2str_84 = DoubleToStr(gda_236[l_index_92], 3);
         ld_68 = MathAbs(l_str2dbl_76 - gda_236[l_index_92]);
      }
   }
   if (StringLen(l_dbl2str_84) > 0) {
      l_name_96 = "F_" + "relline_" + ai_0 + "_" + ai_4;
      ObjectDelete(l_name_96);
      ObjectCreate(l_name_96, OBJ_TREND, 0, a_datetime_8, a_price_12, a_datetime_20, a_price_24);
      ObjectSet(l_name_96, OBJPROP_WIDTH, 1);
      ObjectSet(l_name_96, OBJPROP_BACK, TRUE);
      ObjectSet(l_name_96, OBJPROP_RAY, FALSE);
      l_name_104 = "F_" + "linedesc_" + ai_0 + "_" + ai_4;
      ObjectDelete(l_name_104);
      l_shift_112 = iBarShift(Symbol(), Period(), a_datetime_8);
      l_shift_116 = iBarShift(Symbol(), Period(), a_datetime_20);
      li_120 = (l_shift_112 + l_shift_116) / 2;
      ObjectCreate(l_name_104, OBJ_TEXT, 0, Time[li_120], MathAbs(a_price_12 + a_price_24) / 2.0);
      ObjectSet(l_name_104, OBJPROP_ANGLE, 0);
      ObjectSetText(l_name_104, as_32 + " ( " + l_dbl2str_84 + " )", 7, "Tahoma", cextFiboRelationTextDesc);
      ObjectSet(l_name_96, OBJPROP_STYLE, STYLE_DOT);
      ObjectSet(l_name_96, OBJPROP_COLOR, a_color_40);
      if (bextMT4AlertON) Alert(Symbol() + " " + PeriodDesc(Period()) + " Fibo: " + as_32 + " ( " + l_dbl2str_84 + " )");
   }
}

void Draw_Fibo_Box(double a_price_0, double a_price_8, double a_price_16, int a_color_24, int ai_28) {
   int l_datetime_36;
   double l_price_40;
   string l_name_48 = "F_" + "fibo_line1_" + ai_28;
   int li_56 = 60 * (5 * Period());
   ObjectDelete(l_name_48);
   int l_datetime_32 = Time[0] + li_56 + 60 * (10 * ai_28 * Period());
   ObjectCreate(l_name_48, OBJ_TREND, 0, l_datetime_32, a_price_0, l_datetime_32, a_price_8);
   ObjectSet(l_name_48, OBJPROP_COLOR, a_color_24);
   ObjectSet(l_name_48, OBJPROP_STYLE, STYLE_DOT);
   ObjectSet(l_name_48, OBJPROP_WIDTH, 1);
   ObjectSet(l_name_48, OBJPROP_BACK, TRUE);
   ObjectSet(l_name_48, OBJPROP_RAY, FALSE);
   l_name_48 = "F_" + "fibo_line2_" + ai_28;
   ObjectDelete(l_name_48);
   l_datetime_32 = Time[0] + li_56 + 60 * (10 * ai_28 * Period());
   ObjectCreate(l_name_48, OBJ_TREND, 0, l_datetime_32, a_price_0, l_datetime_32, a_price_16);
   ObjectSet(l_name_48, OBJPROP_COLOR, a_color_24);
   ObjectSet(l_name_48, OBJPROP_STYLE, STYLE_DOT);
   ObjectSet(l_name_48, OBJPROP_WIDTH, 1);
   ObjectSet(l_name_48, OBJPROP_BACK, TRUE);
   ObjectSet(l_name_48, OBJPROP_RAY, FALSE);
   for (int l_index_60 = 0; l_index_60 < gi_240; l_index_60++) {
      l_name_48 = "F_" + "fibo_relline" + ai_28 + "_" + gda_236[l_index_60];
      ObjectDelete(l_name_48);
      l_datetime_32 = Time[0] + li_56 + 60 * (10 * ai_28 * Period());
      l_datetime_36 = Time[0] + li_56 + 60 * (10 * (ai_28 + 1) * Period());
      l_price_40 = a_price_8 + (a_price_0 - a_price_8) * gda_236[l_index_60];
      ObjectCreate(l_name_48, OBJ_TREND, 0, l_datetime_32, l_price_40, l_datetime_36, l_price_40);
      ObjectSet(l_name_48, OBJPROP_COLOR, a_color_24);
      ObjectSet(l_name_48, OBJPROP_STYLE, STYLE_DOT);
      ObjectSet(l_name_48, OBJPROP_WIDTH, 1);
      ObjectSet(l_name_48, OBJPROP_BACK, TRUE);
      ObjectSet(l_name_48, OBJPROP_RAY, FALSE);
      l_name_48 = "F_" + "fibo_relline_desc" + ai_28 + "_" + DoubleToStr(gda_236[l_index_60], 4);
      ObjectDelete(l_name_48);
      ObjectCreate(l_name_48, OBJ_TEXT, 0, l_datetime_32 + (l_datetime_36 - l_datetime_32) / 2, l_price_40);
      ObjectSetText(l_name_48, DoubleToStr(100.0 * gda_236[l_index_60], 1), 7, "Tahoma", a_color_24);
   }
}

Recommend