/*
   Generated by EX4-TO-MQ4 decompiler V4.0.224.1 []
   Website: http://purebeam.biz
   E-mail : purebeam@gmail.com
*/

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 White
#property indicator_color2 Red

extern int Length = 5;
extern int Method = 3;
extern int Smoothing = 1;
extern int Filter = 5;
extern bool Steady = FALSE;
double g_ibuf_96[];
double g_ibuf_100[];
double g_ibuf_104[];
double g_ibuf_108[];
double g_ibuf_112[];

int init() {
   IndicatorBuffers(5);
   SetIndexStyle(0, DRAW_HISTOGRAM);
   SetIndexBuffer(0, g_ibuf_108);
   SetIndexStyle(1, DRAW_HISTOGRAM);
   SetIndexBuffer(1, g_ibuf_112);
   SetIndexBuffer(2, g_ibuf_100);
   SetIndexBuffer(3, g_ibuf_96);
   SetIndexBuffer(4, g_ibuf_104);
   if (Length < 2) Length = 2;
   if (Method < MODE_SMA) Method = 0;
   if (Method > MODE_LWMA) Method = 3;
   if (Smoothing < 0) Smoothing = 0;
   if (Filter < 0) Filter = 0;
   string ls_0 = "VQ | " + Length + " , " + Method + " , " + Smoothing + " , " + Filter + "  | ";
   IndicatorShortName(ls_0);
   SetIndexEmptyValue(0, 0.0);
   SetIndexEmptyValue(1, 0.0);
   SetIndexEmptyValue(2, 0.0);
   SetIndexEmptyValue(3, 0.0);
   return (0);
}

int start() {
   int li_40;
   int li_44;
   int li_48;
   double l_ima_0 = 0;
   double l_ima_8 = 0;
   double l_ima_16 = 0;
   double l_ima_24 = 0;
   double l_ima_32 = 0;
   int li_52 = IndicatorCounted();
   if (li_52 < 0) return (-1);
   if (li_52 > 0) li_52--;
   if (li_52 < 1) li_40 = Bars - Length - 1;
   else li_40 = Bars - li_52;
   if (li_52 < 1) {
      li_44 = Bars - Length - 1;
      g_ibuf_100[li_44 + 1] = Close[li_44 + 1];
   }
   while (li_40 >= 0) {
      l_ima_0 = iMA(NULL, 0, Length, 0, Method, PRICE_HIGH, li_40);
      l_ima_8 = iMA(NULL, 0, Length, 0, Method, PRICE_LOW, li_40);
      l_ima_16 = iMA(NULL, 0, Length, 0, Method, PRICE_OPEN, li_40);
      l_ima_24 = iMA(NULL, 0, Length, 0, Method, PRICE_CLOSE, li_40);
      l_ima_32 = iMA(NULL, 0, Length, 0, Method, PRICE_CLOSE, li_40 + Smoothing);
      if (Steady == TRUE) {
         l_ima_24 = iMA(NULL, 0, Length, 0, Method, PRICE_MEDIAN, li_40);
         l_ima_32 = iMA(NULL, 0, Length, 0, Method, PRICE_MEDIAN, li_40 + Smoothing);
      }
      if (l_ima_0 - l_ima_8 > 0.0) {
         g_ibuf_96[li_40] = MathAbs(((l_ima_24 - l_ima_32) / MathMax(l_ima_0 - l_ima_8, MathMax(l_ima_0 - l_ima_32, l_ima_32 - l_ima_8)) + (l_ima_24 - l_ima_16) / (l_ima_0 - l_ima_8)) / 2.0) * ((l_ima_24 - l_ima_32 +
            (l_ima_24 - l_ima_16)) / 2.0);
      }
      g_ibuf_100[li_40] = g_ibuf_100[li_40 + 1] + g_ibuf_96[li_40];
      if (Filter > 0)
         if (MathAbs(g_ibuf_100[li_40] - (g_ibuf_100[li_40 + 1])) < Filter * Point) g_ibuf_100[li_40] = g_ibuf_100[li_40 + 1];
      li_40--;
   }
   if (li_52 < 1) li_48 = Bars - Length - 1;
   else li_48 = Bars - li_52;
   for (li_40 = li_48 - 1; li_40 >= 0; li_40--) {
      if (g_ibuf_100[li_40] > g_ibuf_100[li_40 + 1]) g_ibuf_104[li_40] = 1;
      if (g_ibuf_100[li_40] < g_ibuf_100[li_40 + 1]) g_ibuf_104[li_40] = -1;
      if (g_ibuf_100[li_40] == g_ibuf_100[li_40 + 1]) g_ibuf_104[li_40] = g_ibuf_104[li_40 + 1];
      if (g_ibuf_104[li_40] > 0.0) {
         g_ibuf_108[li_40] = High[li_40];
         g_ibuf_112[li_40] = Low[li_40];
      } else {
         if (g_ibuf_104[li_40] < 0.0) {
            g_ibuf_112[li_40] = High[li_40];
            g_ibuf_108[li_40] = Low[li_40];
         }
      }
   }
   return (0);
}
