/*
   Generated by EX4-TO-MQ4 decompiler V4.0.225.1g []
   Website: http://purebeam.biz
   E-mail : purebeam@gmail.com
*/
#property copyright "Copyright © 2004, Mr KAY Software"
#property link      ""

#property indicator_separate_window
#property indicator_levelcolor Gray
#property indicator_levelstyle 0
#property indicator_buffers 8
#property indicator_color1 Red
#property indicator_color2 Fuchsia
#property indicator_color3 Yellow
#property indicator_color4 Goldenrod
#property indicator_color5 Blue
#property indicator_color6 Aqua
#property indicator_color7 Lime
#property indicator_color8 Red
#property indicator_width1 2
#property indicator_style2 2
#property indicator_width3 2
#property indicator_style4 2

int g_timeframe_76 = PERIOD_M1;
int g_timeframe_80 = PERIOD_M5;
int gi_84 = 15;
int gi_88 = 30;
int gi_92 = 60;
int gi_96 = 240;
int gi_100 = 1440;
int gi_104 = 10080;
int gi_108 = 43200;
extern string MACD_Setting = "Enter Period for Fast, Slow & Signal";
extern int fastMA = 12;
extern int SlowMA = 26;
extern int SignalPeriod = 9;
extern string Display = "Text Location";
extern int TextDist = 12;
double g_ibuf_144[];
double g_ibuf_148[];
double g_ibuf_152[];
double g_ibuf_156[];
double g_ibuf_160[];
double g_ibuf_164[];
double g_ibuf_168[];
double g_ibuf_172[];
int g_period_176;
string gs_180;

int init() {
   if (Period() == g_timeframe_76) {
      g_timeframe_76 = Period();
      g_period_176 = g_timeframe_80;
   }
   if (Period() == g_timeframe_80) {
      g_timeframe_76 = Period();
      g_timeframe_80 = gi_84;
      g_period_176 = gi_84 / Period();
   }
   if (Period() == gi_84) {
      g_timeframe_76 = Period();
      g_timeframe_80 = gi_88;
      g_period_176 = gi_88 / Period();
   }
   if (Period() == gi_88) {
      g_timeframe_76 = Period();
      g_timeframe_80 = gi_92;
      g_period_176 = gi_92 / Period();
   }
   if (Period() == gi_92) {
      g_timeframe_76 = Period();
      g_timeframe_80 = gi_96;
      g_period_176 = gi_96 / Period();
   }
   if (Period() == gi_96) {
      g_timeframe_76 = Period();
      g_timeframe_80 = gi_100;
      g_period_176 = gi_100 / Period();
   }
   if (Period() == gi_100) {
      g_timeframe_76 = Period();
      g_timeframe_80 = gi_104;
      g_period_176 = gi_104 / Period();
   }
   if (Period() == gi_104) {
      g_timeframe_76 = Period();
      g_timeframe_80 = gi_108;
      g_period_176 = gi_108 / Period();
   }
   SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2, Red);
   SetIndexBuffer(0, g_ibuf_144);
   SetIndexStyle(1, DRAW_LINE, STYLE_DOT, 0, Fuchsia);
   SetIndexBuffer(1, g_ibuf_148);
   SetIndexStyle(2, DRAW_NONE);
   SetIndexBuffer(2, g_ibuf_152);
   SetIndexStyle(3, DRAW_NONE);
   SetIndexBuffer(3, g_ibuf_156);
   SetIndexStyle(4, DRAW_LINE, STYLE_SOLID, 2, Blue);
   SetIndexBuffer(4, g_ibuf_160);
   SetIndexStyle(5, DRAW_LINE, STYLE_DOT, 0, Aqua);
   SetIndexBuffer(5, g_ibuf_164);
   SetIndexStyle(6, DRAW_HISTOGRAM, STYLE_SOLID, 3, Lime);
   SetIndexBuffer(6, g_ibuf_168);
   SetIndexStyle(7, DRAW_HISTOGRAM, STYLE_SOLID, 3, Red);
   SetIndexBuffer(7, g_ibuf_172);
   SetIndexLabel(0, "Main " + g_timeframe_76 + "m");
   SetIndexLabel(1, "Signal " + g_timeframe_76 + "m");
   SetIndexLabel(2, "Main " + g_timeframe_80 + "m");
   SetIndexLabel(3, "Signal " + g_timeframe_80 + "m");
   SetIndexLabel(6, "Diff Main to Signal " + g_timeframe_80 + "m");
   SetIndexLabel(7, "Diff Main to Signal " + g_timeframe_80 + "m");
   IndicatorShortName("KAY Dual TimeFrame_Macd " + g_timeframe_76 + "m " + g_timeframe_80 + "m ");
   gs_180 = "KAY Dual TimeFrame_Macd " + g_timeframe_76 + "m " + g_timeframe_80 + "m ";
   return (0);
}

int deinit() {
   ObjectsDeleteAll();
   return (0);
}

int start() {
   int li_0 = IndicatorCounted();
   if (li_0 > 0) li_0--;
   int li_4 = Bars - li_0;
   if (Period() == g_timeframe_76) {
      g_timeframe_76 = Period();
      g_period_176 = g_timeframe_80;
   }
   if (Period() == g_timeframe_80) {
      g_timeframe_76 = Period();
      g_timeframe_80 = gi_84;
      g_period_176 = gi_84 / Period();
   }
   if (Period() == gi_84) {
      g_timeframe_76 = Period();
      g_timeframe_80 = gi_88;
      g_period_176 = gi_88 / Period();
   }
   if (Period() == gi_88) {
      g_timeframe_76 = Period();
      g_timeframe_80 = gi_92;
      g_period_176 = gi_92 / Period();
   }
   if (Period() == gi_92) {
      g_timeframe_76 = Period();
      g_timeframe_80 = gi_96;
      g_period_176 = gi_96 / Period();
   }
   if (Period() == gi_96) {
      g_timeframe_76 = Period();
      g_timeframe_80 = gi_100;
      g_period_176 = gi_100 / Period();
   }
   if (Period() == gi_100) {
      g_timeframe_76 = Period();
      g_timeframe_80 = gi_104;
      g_period_176 = gi_104 / Period();
   }
   if (Period() == gi_104) {
      g_timeframe_76 = Period();
      g_timeframe_80 = gi_108;
      g_period_176 = gi_108 / Period();
   }
   for (int li_8 = li_4; li_8 >= 0; li_8--) {
      g_ibuf_144[li_8] = iMACD(NULL, g_timeframe_76, fastMA, SlowMA, SignalPeriod, PRICE_CLOSE, MODE_MAIN, iBarShift(NULL, g_timeframe_76, Time[li_8]));
      g_ibuf_148[li_8] = iMACD(NULL, g_timeframe_76, fastMA, SlowMA, SignalPeriod, PRICE_CLOSE, MODE_SIGNAL, iBarShift(NULL, g_timeframe_76, Time[li_8]));
      g_ibuf_152[li_8] = iMACD(NULL, g_timeframe_80, fastMA, SlowMA, SignalPeriod, PRICE_CLOSE, MODE_MAIN, iBarShift(NULL, g_timeframe_80, Time[li_8]));
      g_ibuf_156[li_8] = iMACD(NULL, g_timeframe_80, fastMA, SlowMA, SignalPeriod, PRICE_CLOSE, MODE_SIGNAL, iBarShift(NULL, g_timeframe_80, Time[li_8]));
   }
   for (li_8 = li_4; li_8 >= 0; li_8--) {
      g_ibuf_160[li_8] = iMAOnArray(g_ibuf_152, 0, g_period_176, 0, MODE_SMA, li_8);
      g_ibuf_164[li_8] = iMAOnArray(g_ibuf_156, 0, g_period_176, 0, MODE_SMA, li_8);
      if (g_ibuf_160[li_8] - g_ibuf_164[li_8] >= g_ibuf_160[li_8 + 1] - (g_ibuf_164[li_8 + 1])) {
         g_ibuf_168[li_8] = g_ibuf_160[li_8] - g_ibuf_164[li_8];
         g_ibuf_172[li_8] = 0.0;
      } else {
         g_ibuf_172[li_8] = g_ibuf_160[li_8] - g_ibuf_164[li_8];
         g_ibuf_168[li_8] = 0.0;
      }
   }
   if (iMACD(NULL, g_timeframe_76, fastMA, SlowMA, SignalPeriod, PRICE_CLOSE, MODE_MAIN, iBarShift(NULL, g_timeframe_76, Time[0])) >= iMACD(NULL, g_timeframe_76, fastMA, SlowMA, SignalPeriod, PRICE_CLOSE, MODE_SIGNAL, iBarShift(NULL, g_timeframe_76, Time[0]))) {
      Arrow("Macd" + g_timeframe_76 + "m", Time[0] + 60 * Period() * 2, WindowPriceMin(WindowFind(gs_180)) + 0.8 * (WindowPriceMax(WindowFind(gs_180)) - WindowPriceMin(WindowFind(gs_180))), 233, 2, Red);
      Text("Macd_TF_" + g_timeframe_76 + "m", Time[0] + 60 * Period() * TextDist, WindowPriceMin(WindowFind(gs_180)) + 0.8 * (WindowPriceMax(WindowFind(gs_180)) - WindowPriceMin(WindowFind(gs_180))), 10, Red);
   } else {
      Arrow("Macd" + g_timeframe_76 + "m", Time[0] + 60 * Period() * 2, WindowPriceMin(WindowFind(gs_180)) + 0.8 * (WindowPriceMax(WindowFind(gs_180)) - WindowPriceMin(WindowFind(gs_180))), 234, 2, Red);
      Text("Macd_TF_" + g_timeframe_76 + "m", Time[0] + 60 * Period() * TextDist, WindowPriceMin(WindowFind(gs_180)) + 0.8 * (WindowPriceMax(WindowFind(gs_180)) - WindowPriceMin(WindowFind(gs_180))), 10, Red);
   }
   if (iMACD(NULL, g_timeframe_80, fastMA, SlowMA, SignalPeriod, PRICE_CLOSE, MODE_MAIN, iBarShift(NULL, g_timeframe_80, Time[0])) >= iMACD(NULL, g_timeframe_80, fastMA, SlowMA, SignalPeriod, PRICE_CLOSE, MODE_SIGNAL, iBarShift(NULL, g_timeframe_80, Time[0]))) {
      Arrow("Macd" + g_timeframe_80 + "m", Time[0] + 60 * Period() * 2, WindowPriceMin(WindowFind(gs_180)) + 0.6 * (WindowPriceMax(WindowFind(gs_180)) - WindowPriceMin(WindowFind(gs_180))), 233, 2, Blue);
      Text("Macd_TF_" + g_timeframe_80 + "m", Time[0] + 60 * Period() * TextDist, WindowPriceMin(WindowFind(gs_180)) + 0.6 * (WindowPriceMax(WindowFind(gs_180)) - WindowPriceMin(WindowFind(gs_180))), 10, Blue);
   } else {
      Arrow("Macd" + g_timeframe_80 + "m", Time[0] + 60 * Period() * 2, WindowPriceMin(WindowFind(gs_180)) + 0.6 * (WindowPriceMax(WindowFind(gs_180)) - WindowPriceMin(WindowFind(gs_180))), 234, 2, Blue);
      Text("Macd_TF_" + g_timeframe_80 + "m", Time[0] + 60 * Period() * TextDist, WindowPriceMin(WindowFind(gs_180)) + 0.6 * (WindowPriceMax(WindowFind(gs_180)) - WindowPriceMin(WindowFind(gs_180))), 10, Blue);
   }
   return (0);
}

double Arrow(string a_name_0, int a_datetime_8, double a_price_12, int ai_20, int a_width_24, color a_color_28) {
   double ld_ret_32 = ObjectCreate(a_name_0, OBJ_ARROW, WindowFind(gs_180), a_datetime_8, a_price_12);
   ObjectSet(a_name_0, OBJPROP_TIME1, a_datetime_8);
   ObjectSet(a_name_0, OBJPROP_PRICE1, a_price_12);
   ObjectSet(a_name_0, OBJPROP_ARROWCODE, ai_20);
   ObjectSet(a_name_0, OBJPROP_WIDTH, a_width_24);
   ObjectSet(a_name_0, OBJPROP_COLOR, a_color_28);
   return (ld_ret_32);
}

double Text(string a_name_0, int a_datetime_8, double a_price_12, int a_fontsize_20, color a_color_24) {
   double ld_ret_28 = ObjectCreate(a_name_0, OBJ_TEXT, WindowFind(gs_180), a_datetime_8, a_price_12);
   ObjectSet(a_name_0, OBJPROP_TIME1, a_datetime_8);
   ObjectSet(a_name_0, OBJPROP_PRICE1, a_price_12);
   ObjectSetText(a_name_0, "" + a_name_0, a_fontsize_20, "verdana", a_color_24);
   return (ld_ret_28);
}