/*
   Generated by EX4-TO-MQ4 decompiler V4.0.224.1 []
   Website: http://purebeam.biz
   E-mail : purebeam@gmail.com
*/
#property copyright "Copyright © 2006-2009, Sergey Kravchuk. http://forextools.com.ua"
#property link      "http://forextools.com.ua"

#property indicator_separate_window
#property indicator_minimum -1.0
#property indicator_maximum 110.0
#property indicator_buffers 8
#property indicator_color1 Black
#property indicator_color2 Black
#property indicator_color3 Black
#property indicator_color4 Black
#property indicator_color5 Black
#property indicator_color6 Black
#property indicator_color7 Black
#property indicator_color8 Black

#include <WinUser32.mqh>

#import "user32.dll"
   int GetDC(int a0);
   int ReleaseDC(int a0, int a1);
#import "gdi32.dll"
   int GetPixel(int a0, int a1, int a2);
#import

double g_ibuf_76[];
double g_ibuf_80[];
double g_ibuf_84[];
double g_ibuf_88[];
double g_ibuf_92[];
double g_ibuf_96[];
double g_ibuf_100[];
double g_ibuf_104[];
double g_ibuf_108[];
double g_ibuf_112[];
double g_ibuf_116[];
double g_ibuf_120[];
double g_ibuf_124[];
double g_ibuf_128[];
double g_ibuf_132[];
double g_ibuf_136[];
double gda_unused_140[];
int gi_144 = 7;
int gia_148[];
double gda_152[];
extern int BoxWidth = 50;
extern int LookForward = 20;
extern int SearchDepth = 3000;
extern int LevelHigh = 95;
extern int LevelLow = 65;
extern bool ExactTime = TRUE;
extern bool PriceFromMA = TRUE;
extern int MAPeriod = 13;
extern int MAMethod = 2;
extern int MAPrice = 4;
int gi_196;
int g_style_200;
extern bool JoinMA = TRUE;
extern bool AverageMA = TRUE;
extern color ColorMA1 = Red;
extern color ColorMA2 = DarkOrange;
extern color ColorMA3 = Gold;
extern color ColorMA4 = LimeGreen;
extern color ColorMA5 = DeepSkyBlue;
extern color ColorMA6 = RoyalBlue;
extern color ColorMA7 = MediumVioletRed;
extern color ColorMA8 = DarkViolet;
int gia_244[8];
int g_color_248 = MintCream;
extern bool BarMode = TRUE;
extern color ColorWihteBody = MediumSeaGreen;
extern color ColorBlackBody = DarkGreen;
extern color ColorShadow = DarkGreen;
extern color ColorWihteBodyFuture = Red;
extern color ColorBlackBodyFuture = Brown;
extern int BarBodyWidth = 2;
extern string FontName = "Small Fonts";
extern int FontSize = 7;
string gs_292 = "ft.Dejavu";
bool gi_unused_300 = TRUE;
double gd_304;
double gd_312;
string gsa_320[256];
int g_acc_number_324 = 0;
int g_timeframe_328 = 0;
int gi_332 = -1;
int gi_unused_336 = 0;
string gs_unused_340 = "";
string ID_Sumbol[256];

int f0_0() 
{
   int li_0 = WindowHandle(Symbol(), Period());
   int li_4 = GetDC(li_0);
   int li_ret_8 = GetPixel(li_4, 1, 2);
   ReleaseDC(li_0, li_4);
   return (li_ret_8);
}

int deinit() 
{
   for (int li_0 = 0; li_0 < ObjectsTotal(); li_0++) 
   {
      if (StringFind(ObjectName(li_0), gs_292) == 0) 
      {
         ObjectDelete(ObjectName(li_0));
         li_0--;
      }
   }
   g_acc_number_324 = 0;
   gi_332 = 0;
   return (0);
}

int init() 
{
   if (SearchDepth > Bars) SearchDepth = Bars - 1;
   if (SearchDepth < 7 * BoxWidth) SearchDepth = 7 * BoxWidth;
   if (BoxWidth > 300) BoxWidth = 300;
   if (BoxWidth <= 10) BoxWidth = 10;
   if (LookForward <= 0 || LookForward > BoxWidth) LookForward = BoxWidth / 2;
   gia_244[0] = ColorMA1;
   gia_244[1] = ColorMA2;
   gia_244[2] = ColorMA3;
   gia_244[3] = ColorMA4;
   gia_244[4] = ColorMA5;
   gia_244[5] = ColorMA6;
   gia_244[6] = ColorMA7;
   gia_244[7] = ColorMA8;
   if (BarMode) 
   {
      SetIndexBuffer(0, g_ibuf_76);
      SetIndexBuffer(1, g_ibuf_80);
      SetIndexBuffer(2, g_ibuf_84);
      SetIndexBuffer(3, g_ibuf_100);
      SetIndexBuffer(4, g_ibuf_104);
      SetIndexBuffer(5, g_ibuf_88);
      SetIndexBuffer(6, g_ibuf_92);
      SetIndexBuffer(7, g_ibuf_96);
   } 
   else 
   {
      SetIndexBuffer(0, g_ibuf_108);
      SetIndexBuffer(1, g_ibuf_112);
      SetIndexBuffer(2, g_ibuf_116);
      SetIndexBuffer(3, g_ibuf_120);
      SetIndexBuffer(4, g_ibuf_124);
      SetIndexBuffer(5, g_ibuf_128);
      SetIndexBuffer(6, g_ibuf_132);
      SetIndexBuffer(7, g_ibuf_136);
   }
   g_color_248 = f0_0();
   int li_0 = WindowHandle(Symbol(), Period());
   if (li_0 != 0) PostMessageA(li_0, WM_COMMAND, 33324, 0);
   for (int l_index_4 = 0; l_index_4 < 256; l_index_4++) gsa_320[l_index_4] = CharToStr(l_index_4);
   Print(gsa_320[67] + gsa_320[111] + gsa_320[112] + gsa_320[121] + gsa_320[114] + gsa_320[105] + gsa_320[103] + gsa_320[104] + gsa_320[116] + gsa_320[32] + gsa_320[169] +
      gsa_320[32] + gsa_320[50] + gsa_320[48] + gsa_320[48] + gsa_320[54] + gsa_320[45] + gsa_320[50] + gsa_320[48] + gsa_320[48] + gsa_320[57] + gsa_320[44] + gsa_320[32] +
      gsa_320[83] + gsa_320[101] + gsa_320[114] + gsa_320[103] + gsa_320[101] + gsa_320[121] + gsa_320[32] + gsa_320[75] + gsa_320[114] + gsa_320[97] + gsa_320[118] + gsa_320[99] +
      gsa_320[104] + gsa_320[117] + gsa_320[107] + gsa_320[46] + gsa_320[32] + gsa_320[104] + gsa_320[116] + gsa_320[116] + gsa_320[112] + gsa_320[58] + gsa_320[47] + gsa_320[47] +
      gsa_320[102] + gsa_320[111] + gsa_320[114] + gsa_320[101] + gsa_320[120] + gsa_320[116] + gsa_320[111] + gsa_320[111] + gsa_320[108] + gsa_320[115] + gsa_320[46] +
      gsa_320[99] + gsa_320[111] + gsa_320[109] + gsa_320[46] + gsa_320[117] + gsa_320[97]);
   Print(gsa_320[72] + gsa_320[105] + gsa_320[110] + gsa_320[116] + gsa_320[33] + gsa_320[32] + gsa_320[85] + gsa_320[115] + gsa_320[101] + gsa_320[32] + gsa_320[118] +
      gsa_320[101] + gsa_320[114] + gsa_320[116] + gsa_320[105] + gsa_320[99] + gsa_320[97] + gsa_320[108] + gsa_320[32] + gsa_320[108] + gsa_320[105] + gsa_320[110] + gsa_320[101] +
      gsa_320[32] + gsa_320[119] + gsa_320[105] + gsa_320[116] + gsa_320[104] + gsa_320[32] + gsa_320[110] + gsa_320[97] + gsa_320[109] + gsa_320[101] + gsa_320[32] + gsa_320[39] +
      gsa_320[77] + gsa_320[65] + gsa_320[82] + gsa_320[75] + gsa_320[69] + gsa_320[82] + gsa_320[39] + gsa_320[32] + gsa_320[116] + gsa_320[111] + gsa_320[32] + gsa_320[97] +
      gsa_320[110] + gsa_320[97] + gsa_320[108] + gsa_320[121] + gsa_320[122] + gsa_320[101] + gsa_320[32] + gsa_320[104] + gsa_320[105] + gsa_320[115] + gsa_320[116] +
      gsa_320[111] + gsa_320[114] + gsa_320[121] + gsa_320[46]);
   for (int li_8 = 0; li_8 < 8; li_8++) SetIndexLabel(li_8, "");
   return (0);
}

int start() 
{
   int li_0;
   int li_4;
   int li_unused_8;
   string l_name_16;
   int li_24;
   int li_28;
   int li_32;
   string ls_36;
   string ls_44;
   string ls_52;
   string ls_60;
   int li_68;
   string File_name;
   int File;
   string ls_88;
   int li_104;
   int l_window_108;
   int li_116;
   //---
   if (gi_144 > 0) 
     { 
      if (!gi_332 && li_24 < BoxWidth) li_24 = BoxWidth;
      g_color_248 = f0_0();
      IndicatorShortName(gs_292);
      l_window_108 = WindowFind(gs_292);
      if (l_window_108 > WindowsTotal() || l_window_108 < 0) return (9);
      l_name_16 = gs_292 + "_" + l_window_108;
      if (BoxWidth <= 3) BoxWidth = WindowBarsPerChart() / gi_144 - gi_144;
      li_4 = BoxWidth + 3;
      
      
      for (int li_12 = 0; li_12 < ObjectsTotal(); li_12++) 
      {
         if (StringFind(ObjectName(li_12), gs_292) == 0) 
         {
            ObjectDelete(ObjectName(li_12));
            li_12--;
         }
      }
      if (BarMode) 
      {
         ArrayInitialize(g_ibuf_76, EMPTY_VALUE);
         ArrayInitialize(g_ibuf_80, EMPTY_VALUE);
         ArrayInitialize(g_ibuf_84, EMPTY_VALUE);
         ArrayInitialize(g_ibuf_100, EMPTY_VALUE);
         ArrayInitialize(g_ibuf_104, EMPTY_VALUE);
         ArrayInitialize(g_ibuf_88, EMPTY_VALUE);
         ArrayInitialize(g_ibuf_92, EMPTY_VALUE);
         ArrayInitialize(g_ibuf_96, EMPTY_VALUE);
      } 
      else 
      {
         ArrayInitialize(g_ibuf_108, EMPTY_VALUE);
         ArrayInitialize(g_ibuf_112, EMPTY_VALUE);
         ArrayInitialize(g_ibuf_116, EMPTY_VALUE);
         ArrayInitialize(g_ibuf_120, EMPTY_VALUE);
         ArrayInitialize(g_ibuf_124, EMPTY_VALUE);
         ArrayInitialize(g_ibuf_128, EMPTY_VALUE);
         ArrayInitialize(g_ibuf_132, EMPTY_VALUE);
         ArrayInitialize(g_ibuf_136, EMPTY_VALUE);
      }
      gd_304 = -10000;
      gd_312 = 10000;
      for (li_12 = 0; li_12 < 8; li_12++) SetIndexShift(li_12, (-li_24) + 1 + LookForward);
      ArrayResize(gia_148, gi_144);
      ArrayResize(gda_152, gi_144);
      f0_22692(li_24, BoxWidth, SearchDepth);
      if (BarMode) 
      {
         for (int li_112 = 0; li_112 < gi_144; li_112++) 
         {
            li_0 = gia_148[li_112] - LookForward;
            for (li_12 = 0; li_12 < BoxWidth; li_12++) f0_21240(li_0, li_12 + li_0, Symbol(), Period(), BoxWidth, li_4 * li_112 - li_0);
            l_name_16 = gs_292 + l_window_108 + li_112;
            ObjectCreate(l_name_16, OBJ_TEXT, l_window_108, Time[li_12 + li_4 * li_112 + 3 - BoxWidth / 2 - 2 + li_24 - LookForward], 110);
            ObjectSet(l_name_16, OBJPROP_BACK, FALSE);
            ObjectSetText(l_name_16, TimeToStr(Time[li_0 + LookForward]) + " - " + DoubleToStr(100.0 * gda_152[li_112], 1) + "%", FontSize, FontName, ColorShadow);
         }
         gd_304 = MathMax(gd_304, 110);
         f0_20360(0, gd_304, gd_312, gd_312, 0);
         for (li_112 = 0; li_112 < gi_144; li_112++) f0_20360(li_12 + li_4 * li_112 + 3, gd_304, gd_312, gd_312, 0);
         SetIndexStyle(0, DRAW_HISTOGRAM, STYLE_SOLID, 1, ColorShadow);
         SetIndexStyle(1, DRAW_HISTOGRAM, STYLE_SOLID, BarBodyWidth, ColorWihteBody);
         SetIndexStyle(2, DRAW_HISTOGRAM, STYLE_SOLID, BarBodyWidth, ColorBlackBody);
         SetIndexStyle(3, DRAW_HISTOGRAM, STYLE_SOLID, BarBodyWidth, ColorWihteBodyFuture);
         SetIndexStyle(4, DRAW_HISTOGRAM, STYLE_SOLID, BarBodyWidth, ColorBlackBodyFuture);
         SetIndexStyle(5, DRAW_HISTOGRAM, STYLE_SOLID, BarBodyWidth, g_color_248);
         SetIndexStyle(6, DRAW_HISTOGRAM, STYLE_SOLID, 1, ColorShadow);
         SetIndexStyle(7, DRAW_HISTOGRAM, STYLE_SOLID, BarBodyWidth, g_color_248);
      } 
      else 
      {
         for (li_112 = 0; li_112 < gi_144; li_112++) 
         {
            li_0 = gia_148[li_112] - LookForward;
            if (JoinMA) li_116 = 0;
            else li_116 = li_112;
            if (li_112 == 0) for (li_12 = 0; li_12 < BoxWidth; li_12++) f0_20656(g_ibuf_108, li_0, li_12 + li_0, Symbol(), Period(), BoxWidth, li_4 * li_116 - li_0, MAPeriod, MAMethod);
            if (li_112 == 1) for (li_12 = 0; li_12 < BoxWidth; li_12++) f0_20656(g_ibuf_112, li_0, li_12 + li_0, Symbol(), Period(), BoxWidth, li_4 * li_116 - li_0, MAPeriod, MAMethod);
            if (li_112 == 2) for (li_12 = 0; li_12 < BoxWidth; li_12++) f0_20656(g_ibuf_116, li_0, li_12 + li_0, Symbol(), Period(), BoxWidth, li_4 * li_116 - li_0, MAPeriod, MAMethod);
            if (li_112 == 3) for (li_12 = 0; li_12 < BoxWidth; li_12++) f0_20656(g_ibuf_120, li_0, li_12 + li_0, Symbol(), Period(), BoxWidth, li_4 * li_116 - li_0, MAPeriod, MAMethod);
            if (li_112 == 4) for (li_12 = 0; li_12 < BoxWidth; li_12++) f0_20656(g_ibuf_124, li_0, li_12 + li_0, Symbol(), Period(), BoxWidth, li_4 * li_116 - li_0, MAPeriod, MAMethod);
            if (li_112 == 5) for (li_12 = 0; li_12 < BoxWidth; li_12++) f0_20656(g_ibuf_128, li_0, li_12 + li_0, Symbol(), Period(), BoxWidth, li_4 * li_116 - li_0, MAPeriod, MAMethod);
            if (li_112 == 6) for (li_12 = 0; li_12 < BoxWidth; li_12++) f0_20656(g_ibuf_132, li_0, li_12 + li_0, Symbol(), Period(), BoxWidth, li_4 * li_116 - li_0, MAPeriod, MAMethod);
            if (100.0 * gda_152[li_112] >= LevelHigh) gi_196 = 2;
            if (100.0 * gda_152[li_112] <= LevelLow) g_style_200 = 2;
            else g_style_200 = 0;
            if (AverageMA && JoinMA) 
            {
               for (li_12 = 0; li_12 < BoxWidth + li_0; li_12++) g_ibuf_132[li_12] = (g_ibuf_108[li_12] + g_ibuf_112[li_12] + g_ibuf_116[li_12] + g_ibuf_120[li_12] + g_ibuf_124[li_12] + g_ibuf_128[li_12]) / 6.0;
               if (li_112 == 6) 
               {
                  gi_196 = 2;
                  g_style_200 = 0;
               } else gi_196 = 1;
            }
            SetIndexStyle(li_112, DRAW_LINE, g_style_200, gi_196, gia_244[li_112]);
            if (!(AverageMA && JoinMA && li_112 == 6)) {
               l_name_16 = gs_292 + l_window_108 + li_112;
               if (JoinMA) ObjectCreate(l_name_16, OBJ_TEXT, l_window_108, Time[BoxWidth + li_4 + 3 - BoxWidth / 2 - 2 + li_24 - LookForward], 100 - 10 * li_112);
               else ObjectCreate(l_name_16, OBJ_TEXT, l_window_108, Time[BoxWidth + li_4 * li_112 + 3 - BoxWidth / 2 - 2 + li_24 - LookForward], 110);
               ObjectSet(l_name_16, OBJPROP_BACK, FALSE);
               ObjectSetText(l_name_16, TimeToStr(Time[li_0 + LookForward]) + " - " + DoubleToStr(100.0 * gda_152[li_112], 1) + "%", FontSize, FontName, gia_244[li_112]);
            }
         }
         gd_312 = 0;
         gd_304 = 105;
         f0_20360(0, gd_304, gd_312, gd_312, 0);
         f0_20360(LookForward, gd_304, gd_312, gd_312, 0);
         if (JoinMA) f0_20360(BoxWidth + 3, gd_304, gd_312, gd_312, 0);
         else 
         {
            for (li_112 = 0; li_112 < gi_144; li_112++) 
            {
               f0_20360(li_12 + li_4 * li_112 + 3, gd_304, gd_312, gd_312, 0);
               f0_20360(li_12 + LookForward + li_4 * li_112 + 3, gd_304, gd_312, gd_312, 0);
            }
         }
         SetIndexStyle(7, DRAW_HISTOGRAM, STYLE_SOLID, 1, ColorBlackBody);
      }
   }
   return (0);
}

void f0_20360(int ai_0, double ad_4, double ad_12, double ad_20, double ad_28) 
{
   ai_0++;
   g_ibuf_76[ai_0] = ad_4;
   g_ibuf_96[ai_0] = ad_28;
   if (BarMode) 
   {
      if (ad_12 <= ad_20) 
      {
         g_ibuf_80[ai_0] = ad_20;
         g_ibuf_88[ai_0] = ad_12;
      } else {
         g_ibuf_84[ai_0] = ad_12;
         g_ibuf_88[ai_0] = ad_20;
      }
      g_ibuf_92[ai_0] = g_ibuf_88[ai_0];
      return;
   }
   g_ibuf_136[ai_0] = ad_4;
}

void f0_20656(double &ada_0[], int ai_4, int ai_8, string a_symbol_12, int a_timeframe_20, int ai_24, int ai_28, int a_period_32, int a_ma_method_36) 
{
   double ld_56;
   double l_ihigh_40 = iHigh(a_symbol_12, a_timeframe_20, iHighest(a_symbol_12, a_timeframe_20, MODE_HIGH, ai_24, ai_4));
   double l_ilow_48 = iLow(a_symbol_12, a_timeframe_20, iLowest(a_symbol_12, a_timeframe_20, MODE_LOW, ai_24, ai_4));
   if (l_ihigh_40 != l_ilow_48) {
      ld_56 = 100.0 * ((iMA(a_symbol_12, a_timeframe_20, a_period_32, 0, a_ma_method_36, MAPrice, ai_8) - l_ilow_48) / (l_ihigh_40 - l_ilow_48));
      ada_0[ai_8 + ai_28 + 3] = ld_56;
      if (gd_304 < ld_56) gd_304 = ld_56;
      if (ld_56 < gd_312) gd_312 = ld_56;
   }
}

void f0_21240(int ai_0, int ai_4, string a_symbol_8, int a_timeframe_16, int ai_20, int ai_24) 
{
   double ld_44;
   double ld_52;
   double ld_60;
   double ld_68;
   double ld_76;
   double l_ihigh_28 = iHigh(a_symbol_8, a_timeframe_16, iHighest(a_symbol_8, a_timeframe_16, MODE_HIGH, ai_20, ai_0));
   double l_ilow_36 = iLow(a_symbol_8, a_timeframe_16, iLowest(a_symbol_8, a_timeframe_16, MODE_LOW, ai_20, ai_0));
   if (l_ihigh_28 != l_ilow_36) 
   {
      ld_44 = l_ihigh_28 - l_ilow_36;
      ld_52 = 100.0 * ((iHigh(a_symbol_8, a_timeframe_16, ai_4) - l_ilow_36) / ld_44);
      ld_60 = 100.0 * ((iOpen(a_symbol_8, a_timeframe_16, ai_4) - l_ilow_36) / ld_44);
      ld_68 = 100.0 * ((iClose(a_symbol_8, a_timeframe_16, ai_4) - l_ilow_36) / ld_44);
      ld_76 = 100.0 * ((iLow(a_symbol_8, a_timeframe_16, ai_4) - l_ilow_36) / ld_44);
      ai_4++;
      ai_24 += 2;
      g_ibuf_76[ai_4 + ai_24] = ld_52;
      if (gd_304 < ld_52) gd_304 = ld_52;
      g_ibuf_96[ai_4 + ai_24] = ld_76;
      if (ld_76 < gd_312) gd_312 = ld_76;
      if ((ai_4 + ai_24) % (ai_20 + 3) < LookForward + 1) 
      {
         if (ld_60 <= ld_68) 
         {
            g_ibuf_100[ai_4 + ai_24] = ld_68;
            g_ibuf_88[ai_4 + ai_24] = ld_60;
         } else {
            g_ibuf_104[ai_4 + ai_24] = ld_60;
            g_ibuf_88[ai_4 + ai_24] = ld_68;
         }
      } 
      else 
      {
         if (ld_60 <= ld_68) 
         {
            g_ibuf_80[ai_4 + ai_24] = ld_68;
            g_ibuf_88[ai_4 + ai_24] = ld_60;
         } else {
            g_ibuf_84[ai_4 + ai_24] = ld_60;
            g_ibuf_88[ai_4 + ai_24] = ld_68;
         }
      }
      g_ibuf_92[ai_4 + ai_24] = g_ibuf_88[ai_4 + ai_24];
   }
}

int f0_22692(int ai_0, int ai_4, int ai_8) 
{
   double lda_12[];
   double lda_24[];
   double lda_28[];
   int li_ret_60;
   int l_count_64;
   double ld_40 = -999999;
   ArrayResize(lda_24, ai_4);
   ArrayResize(lda_28, ai_4);
   ArrayResize(lda_12, ai_8);
   for (int l_index_48 = 0; l_index_48 < ai_4; l_index_48++) 
   {
      if (PriceFromMA) lda_24[l_index_48] = iMA(NULL, 0, MAPeriod, 0, MAMethod, MAPrice, ai_0 + l_index_48);
      else lda_24[l_index_48] = Close[ai_0 + l_index_48];
   }
   for (int l_index_52 = ai_4; l_index_52 < ai_8; l_index_52++) 
   {
      if (MathAbs(ai_0 - l_index_52) <= ai_4 / 3) lda_12[l_index_52] = -999999;
      else 
      {
         if (ExactTime && Period() < PERIOD_H4 && TimeHour(Time[0]) != TimeHour(Time[l_index_52]) || TimeMinute(Time[0]) != TimeMinute(Time[l_index_52])) continue;
         if (ExactTime && Period() >= PERIOD_H4 && TimeDayOfWeek(Time[0]) != TimeDayOfWeek(Time[l_index_52])) continue;
         for (l_index_48 = 0; l_index_48 < ai_4; l_index_48++) {
            if (PriceFromMA) lda_28[l_index_48] = iMA(NULL, 0, MAPeriod, 0, MAMethod, MAPrice, l_index_48 + l_index_52);
            else lda_28[l_index_48] = Close[l_index_48 + l_index_52];
         }
         lda_12[l_index_52] = f0_24932(lda_24, lda_28);
         if (lda_12[l_index_52] > ld_40) 
         {
            ld_40 = lda_12[l_index_52];
            li_ret_60 = l_index_52;
         }
      }
   }
   gda_152[0] = ld_40;
   gia_148[0] = li_ret_60;
   for (l_index_48 = 1; l_index_48 < gi_144; l_index_48++) 
   {
      ld_40 = -99999;
      for (l_index_52 = 0; l_index_52 < ai_8; l_index_52++) 
      {
         if (gda_152[l_index_48 - 1] > lda_12[l_index_52] && lda_12[l_index_52] > ld_40) 
         {
            if (MathAbs(ai_0 - l_index_52) > ai_4) 
            {
               l_count_64 = 0;
               for (int l_index_56 = 0; l_index_56 < l_index_48; l_index_56++)
                  if (MathAbs(gia_148[l_index_56] - l_index_52) > ai_4 / 3) l_count_64++;
               if (l_count_64 >= l_index_48) 
               {
                  ld_40 = lda_12[l_index_52];
                  li_ret_60 = l_index_52;
               }
            }
         }
      }
      gda_152[l_index_48] = ld_40;
      gia_148[l_index_48] = li_ret_60;
   }
   return (li_ret_60);
}

double f0_24932(double ada_0[], double ada_4[], int ai_8 = 0) 
{
   double lda_12[];
   double lda_16[];
   double lda_20[];
   double lda_24[];
   double ld_44;
   double ld_52;
   int li_92;
   int li_96;
   double ld_76 = 0.0;
   if (ai_8 > 0) 
   {
      li_96 = ai_8;
      if (ArraySize(ada_0) < li_96 || ArraySize(ada_4) < li_96) return (-1);
   }
   li_96 = MathMin(ArraySize(ada_0), ArraySize(ada_4));
   ArrayResize(lda_20, li_96);
   ArrayResize(lda_12, li_96);
   ArrayCopy(lda_12, ada_0);
   ArrayResize(lda_24, li_96);
   ArrayResize(lda_16, li_96);
   ArrayCopy(lda_16, ada_4);
   ArraySort(lda_12, WHOLE_ARRAY, 0, MODE_ASCEND);
   ArraySort(lda_16, WHOLE_ARRAY, 0, MODE_ASCEND);
   lda_20[0] = 1;
   double ld_60 = 0;
   for (int l_index_84 = 1; l_index_84 < li_96; l_index_84++) 
   {
      if (lda_12[l_index_84 - 1] != lda_12[l_index_84]) lda_20[l_index_84] = l_index_84 + 1;
      else 
      {
         li_92 = 1;
         ld_52 = l_index_84;
         for (int li_88 = l_index_84; li_88 < li_96 && lda_12[li_88 - 1] == lda_12[li_88]; li_88++) 
         {
            li_92++;
            ld_52 += li_88 + 1;
         }
         ld_52 /= li_92;
         for (li_88 = l_index_84 - 1; li_88 < l_index_84 + li_92 - 1; li_88++) lda_20[li_88] = ld_52;
         ld_60 += li_92 * li_92 * li_92 - li_92;
         l_index_84 = li_88 - 1;
      }
   }
   ld_60 /= 12.0;
   lda_24[0] = 1;
   double ld_68 = 0;
   for (l_index_84 = 1; l_index_84 < li_96; l_index_84++) {
      if (lda_16[l_index_84 - 1] != lda_16[l_index_84]) lda_24[l_index_84] = l_index_84 + 1;
      else {
         li_92 = 1;
         ld_52 = l_index_84;
         for (li_88 = l_index_84; li_88 < li_96 && lda_16[li_88 - 1] == lda_16[li_88]; li_88++) 
         {
            li_92++;
            ld_52 += li_88 + 1;
         }
         ld_52 /= li_92;
         for (li_88 = l_index_84 - 1; li_88 < l_index_84 + li_92 - 1; li_88++) lda_24[li_88] = ld_52;
         ld_68 += li_92 * li_92 * li_92 - li_92;
         l_index_84 = li_88 - 1;
      }
   }
   ld_68 /= 12.0;
   for (l_index_84 = 0; l_index_84 < li_96; l_index_84++) 
   {
      ld_44 = lda_20[ArrayBsearch(lda_12, ada_0[l_index_84], WHOLE_ARRAY, 0, MODE_ASCEND)] - lda_24[ArrayBsearch(lda_16, ada_4[l_index_84], WHOLE_ARRAY, 0, MODE_ASCEND)];
      ld_76 += ld_44 * ld_44;
   }
   return (1.0 - 6.0 * (ld_76 + ld_60 + ld_68) / ((li_96 - 1) * li_96 * (li_96 + 1)));
}