#property copyright "Copyright © 2008, Group Three LLC"
#property link      ""

#property indicator_separate_window
#property indicator_minimum 0.0
#property indicator_maximum 9.0
#property indicator_buffers 3
#property indicator_color1 MediumBlue
#property indicator_color2 Maroon
#property indicator_color3 LightGreen

extern color FontColor = Black;
string gsa_80[16] = {"EURUSDm", "GBPUSDm", "AUDJPYm", "USDJPYm", "USDCHFm", "USDCADm", "EURJPYm", "EURGBPm", "EURCHFm", "EURAUDm", "GBPJPYm", "GBPCHFm", "NZDCHFm", "NZDJPYm", "NZDUSDm", "CHFJPYm"};
string gsa_84[8] = {"USD", "EUR", "GBP", "CHF", "CAD", "AUD", "JPY", "NZD"};
int gi_unused_92 = 0;
double g_ibuf_96[];
double g_ibuf_100[];
double g_ibuf_104[];
int g_str_len_108;
int g_period_112;
string g_symbol_116;
string gs_124;
string gs_132;
string gs_140;
string gs_dummy_148;
string gs_dummy_156;

int init() {
   double ld_52;
   double ld_60;
   int li_8 = 4;
   int li_12 = 80;
   int li_16 = 12;
   double ld_20 = 4.0;
   double ld_28 = 3.0;
   string ls_44 = "******";
   if (IsDllsAllowed() == FALSE) {
      Alert("Allow for DLL calls in the \'properties-->common\' popup window");
      ld_52 = 0;
      ld_60 = 1 / ld_52;
      return (0);
   }
   int l_timeframe_4 = Period();
   g_period_112 = 1440 / l_timeframe_4;
   if (l_timeframe_4 >= PERIOD_D1) g_period_112 = 6;
   if (l_timeframe_4 < PERIOD_H1 && l_timeframe_4 >= PERIOD_M15) g_period_112 = 12;
   if (l_timeframe_4 < PERIOD_M15 && l_timeframe_4 >= PERIOD_M5) g_period_112 = 36;
   if (l_timeframe_4 <= PERIOD_M1) g_period_112 = 60;
   int li_0 = g_period_112;
   gs_124 = Symbol();
   g_str_len_108 = StringLen(gs_124);
   gs_132 = StringSubstr(gs_124, 0, 3);
   gs_140 = StringSubstr(gs_124, 3, 3);
   IndicatorBuffers(3);
   SetIndexBuffer(0, g_ibuf_96);
   SetIndexBuffer(1, g_ibuf_100);
   SetIndexBuffer(2, g_ibuf_104);
   SetIndexStyle(0, DRAW_LINE, EMPTY, 2);
   SetIndexStyle(1, DRAW_LINE, EMPTY, 2);
   SetIndexStyle(2, DRAW_HISTOGRAM);
   IndicatorDigits(2);
   SetIndexDrawBegin(0, li_0);
   SetIndexDrawBegin(1, li_0);
   SetIndexDrawBegin(2, li_0);
   SetIndexLabel(0, gs_132);
   SetIndexLabel(1, gs_140);
   SetIndexLabel(2, "Spread");
   SetLevelValue(0, ld_20);
   SetLevelValue(1, ld_28);
   string l_str_concat_36 = StringConcatenate(gs_132, "  ", gs_140, "   (Spread)");
   IndicatorShortName(l_str_concat_36);
   createObj("zera", li_8, li_12 + li_16, gsa_84[0], 9, "Arial", FontColor);
   createObj("zerb", li_8, li_12 + li_16 << 1, DoubleToStr(0.0, 2), 9, "Arial", FontColor);
   createObj("one", li_8, li_12 + 3 * li_16, ls_44, 9, "Arial", FontColor);
   createObj("onea", li_8, li_12 + li_16 << 2, gsa_84[1], 9, "Arial", FontColor);
   createObj("oneb", li_8, li_12 + 5 * li_16, DoubleToStr(0.0, 2), 9, "Arial", FontColor);
   createObj("two", li_8, li_12 + 6 * li_16, ls_44, 9, "Arial", FontColor);
   createObj("twoa", li_8, li_12 + 7 * li_16, gsa_84[2], 9, "Arial", FontColor);
   createObj("twob", li_8, li_12 + li_16 << 3, DoubleToStr(0.0, 2), 9, "Arial", FontColor);
   createObj("thr", li_8, li_12 + 9 * li_16, ls_44, 9, "Arial", FontColor);
   createObj("thra", li_8, li_12 + 10 * li_16, gsa_84[3], 9, "Arial", FontColor);
   createObj("thrb", li_8, li_12 + 11 * li_16, DoubleToStr(0.0, 2), 9, "Arial", FontColor);
   createObj("fou", li_8, li_12 + 12 * li_16, ls_44, 9, "Arial", FontColor);
   createObj("foua", li_8, li_12 + 13 * li_16, gsa_84[4], 9, "Arial", FontColor);
   createObj("foub", li_8, li_12 + 14 * li_16, DoubleToStr(0.0, 2), 9, "Arial", FontColor);
   createObj("fiv", li_8, li_12 + 15 * li_16, ls_44, 9, "Arial", FontColor);
   createObj("fiva", li_8, li_12 + li_16 << 4, gsa_84[5], 9, "Arial", FontColor);
   createObj("fivb", li_8, li_12 + 17 * li_16, DoubleToStr(0.0, 2), 9, "Arial", FontColor);
   createObj("six", li_8, li_12 + 18 * li_16, ls_44, 9, "Arial", FontColor);
   createObj("sixa", li_8, li_12 + 19 * li_16, gsa_84[6], 9, "Arial", FontColor);
   createObj("sixb", li_8, li_12 + 20 * li_16, DoubleToStr(0.0, 2), 9, "Arial", FontColor);
   createObj("sev", li_8, li_12 + 21 * li_16, ls_44, 9, "Arial", FontColor);
   createObj("seva", li_8, li_12 + 22 * li_16, gsa_84[7], 9, "Arial", FontColor);
   createObj("sevb", li_8, li_12 + 23 * li_16, DoubleToStr(0.0, 2), 9, "Arial", FontColor);
   return (0);
}

int deinit() {
   ObjectsDeleteAll();
   Comment(" ");
   return (0);
}

void IsLicenseValid() {
   int li_8;
   int li_0 = 0;
   int li_4 = 0;
   if (li_4 == -1) Comment("Connecting to the server...");
   if (li_4 == 1) {
      Comment("Invalid License. Please contact Quantum");
      li_8 = 1 / li_0;
   }
}

int start() {
   int li_8 = IndicatorCounted();
   IsLicenseValid();
   if (li_8 > 0) li_8--;
   int li_4 = Bars - 1;
   for (int li_0 = MathMin(li_4 - li_8, 200); li_0 >= 0; li_0--) QuITS(li_0);
   return (0);
}

void QuITS(int a_shift_0) {
   double lda_16[8];
   double l_istochastic_20;
   double lda_44[16];
   double lda_48[16];
   int lia_60[8];
   int li_8 = findCy(gs_132);
   int li_12 = findCy(gs_140);
   for (int l_index_4 = 0; l_index_4 < 16; l_index_4++) {
      g_symbol_116 = StringSubstr(gsa_80[l_index_4], 0, g_str_len_108);
      l_istochastic_20 = iStochastic(g_symbol_116, 0, g_period_112, 2, 2, MODE_SMA, 1, MODE_SIGNAL, a_shift_0);
      lda_44[l_index_4] = 9.0 * l_istochastic_20 / 100.0;
      lda_48[l_index_4] = 9 - lda_44[l_index_4];
   }
   double ld_28 = (lda_44[3] + lda_44[4] + lda_44[5] + lda_48[0] + lda_48[1] + lda_48[14]) / 6.0;
   lda_16[0] = NormalizeDouble(ld_28, 2);
   ld_28 = (lda_44[0] + lda_44[6] + lda_44[7] + lda_44[8] + lda_44[9]) / 5.0;
   lda_16[1] = NormalizeDouble(ld_28, 2);
   ld_28 = (lda_44[1] + lda_44[10] + lda_44[11] + lda_48[7]) / 4.0;
   lda_16[2] = NormalizeDouble(ld_28, 2);
   ld_28 = (lda_44[15] + lda_48[4] + lda_48[8] + lda_48[11] + lda_48[12]) / 5.0;
   lda_16[3] = NormalizeDouble(ld_28, 2);
   ld_28 = lda_48[5] / 1.0;
   lda_16[4] = NormalizeDouble(ld_28, 2);
   ld_28 = (lda_44[2] + lda_48[9]) / 2.0;
   lda_16[5] = NormalizeDouble(ld_28, 2);
   ld_28 = (lda_48[3] + lda_48[6] + lda_48[10] + lda_48[2] + lda_48[15] + lda_48[13]) / 6.0;
   lda_16[6] = NormalizeDouble(ld_28, 2);
   ld_28 = (lda_44[14] + lda_44[13] + lda_44[12]) / 3.0;
   lda_16[7] = NormalizeDouble(ld_28, 2);
   g_ibuf_96[a_shift_0] = lda_16[li_8];
   g_ibuf_100[a_shift_0] = lda_16[li_12];
   g_ibuf_104[a_shift_0] = MathAbs(lda_16[li_8] - lda_16[li_12]);
   for (int l_index_64 = 0; l_index_64 < 8; l_index_64++) {
      lia_60[l_index_64] = FontColor;
      if (l_index_64 == li_8) lia_60[l_index_64] = 13434880;
      if (l_index_64 == li_12) lia_60[l_index_64] = 255;
   }
   string l_dbl2str_52 = DoubleToStr(lda_16[0], 2);
   ObjectSetText("zerb", l_dbl2str_52, 9, "Arial", lia_60[0]);
   l_dbl2str_52 = DoubleToStr(lda_16[1], 2);
   ObjectSetText("oneb", l_dbl2str_52, 9, "Arial", lia_60[1]);
   l_dbl2str_52 = DoubleToStr(lda_16[2], 2);
   ObjectSetText("twob", l_dbl2str_52, 9, "Arial", lia_60[2]);
   l_dbl2str_52 = DoubleToStr(lda_16[3], 2);
   ObjectSetText("thrb", l_dbl2str_52, 9, "Arial", lia_60[3]);
   l_dbl2str_52 = DoubleToStr(lda_16[4], 2);
   ObjectSetText("foub", l_dbl2str_52, 9, "Arial", lia_60[4]);
   l_dbl2str_52 = DoubleToStr(lda_16[5], 2);
   ObjectSetText("fivb", l_dbl2str_52, 9, "Arial", lia_60[5]);
   l_dbl2str_52 = DoubleToStr(lda_16[6], 2);
   ObjectSetText("sixb", l_dbl2str_52, 9, "Arial", lia_60[6]);
   l_dbl2str_52 = DoubleToStr(lda_16[7], 2);
   ObjectSetText("sevb", l_dbl2str_52, 9, "Arial", lia_60[7]);
}

int findCy(string as_0) {
   if (as_0 == "USD") return (0);
   if (as_0 == "EUR") return (1);
   if (as_0 == "GBP") return (2);
   if (as_0 == "CHF") return (3);
   if (as_0 == "CAD") return (4);
   if (as_0 == "AUD") return (5);
   if (as_0 == "JPY") return (6);
   if (as_0 == "NZD") return (7);
   return (0);
}

void createObj(string a_name_0, int a_x_8, int a_y_12, string a_text_16, int a_fontsize_24, string a_fontname_28, color a_color_36 = -1) {
   ObjectCreate(a_name_0, OBJ_LABEL, 0, 0, 0);
   ObjectSet(a_name_0, OBJPROP_CORNER, 1);
   ObjectSet(a_name_0, OBJPROP_XDISTANCE, a_x_8);
   ObjectSet(a_name_0, OBJPROP_YDISTANCE, a_y_12);
   ObjectSetText(a_name_0, a_text_16, a_fontsize_24, a_fontname_28, a_color_36);
}