/*
   Generated by EX4-TO-MQ4 decompiler V4.0.224.1 []
   Website: http://purebeam.biz
   E-mail : purebeam@gmail.com
*/
#property copyright "Copyright © 2008,FXDB, LLC"
#property link      "http://www.ForexDealButler.com"

#property indicator_chart_window

extern int RSLength = 30;
extern int MaxBars = 0;
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[];

int init() {
   IndicatorBuffers(8);
   IndicatorShortName("FDB_DynamicRS_filter");
   SetIndexBuffer(0, g_ibuf_84);
   SetIndexBuffer(1, g_ibuf_88);
   SetIndexBuffer(2, g_ibuf_92);
   SetIndexBuffer(3, g_ibuf_100);
   SetIndexBuffer(4, g_ibuf_104);
   SetIndexBuffer(5, g_ibuf_108);
   SetIndexBuffer(6, g_ibuf_112);
   SetIndexBuffer(7, g_ibuf_96);
   SetIndexStyle(0, DRAW_NONE);
   SetIndexStyle(1, DRAW_NONE);
   SetIndexStyle(2, DRAW_NONE);
   SetIndexStyle(3, DRAW_NONE);
   SetIndexStyle(4, DRAW_NONE);
   SetIndexStyle(5, DRAW_NONE);
   SetIndexStyle(6, DRAW_NONE);
   SetIndexStyle(7, DRAW_NONE);
   return (0);
}

int start() {
   double l_high_0;
   double l_low_8;
   double l_high_16;
   double l_low_24;
   int li_32 = IndicatorCounted();
   if (li_32 < 0) return (-1);
   if (li_32 > 0) li_32--;
   int li_36 = Bars - li_32;
   if (li_36 > MaxBars) li_36 = MaxBars;
   for (int li_40 = li_36; li_40 >= 0; li_40--) {
      g_ibuf_100[li_40] = High[iHighest(NULL, 0, MODE_HIGH, 5, li_40)];
      g_ibuf_104[li_40] = Low[iLowest(NULL, 0, MODE_LOW, 5, li_40)];
      g_ibuf_108[li_40] = (g_ibuf_100[li_40] + g_ibuf_104[li_40] + Close[li_40]) / 3.0;
   }
   for (int li_44 = li_36; li_44 >= 0; li_44--) {
      l_high_0 = High[iHighest(NULL, 0, MODE_HIGH, RSLength, li_44)];
      l_low_8 = Low[iLowest(NULL, 0, MODE_LOW, RSLength, li_44)];
      g_ibuf_112[li_44] = iMAOnArray(g_ibuf_108, 0, 25, 0, MODE_SMA, li_44);
      if (g_ibuf_108[li_44 + 1] >= g_ibuf_112[li_44 + 1] && g_ibuf_108[li_44] <= g_ibuf_112[li_44]) l_high_16 = l_high_0;
      if (g_ibuf_108[li_44 + 1] <= g_ibuf_112[li_44 + 1] && g_ibuf_108[li_44] >= g_ibuf_112[li_44]) l_low_24 = l_low_8;
      g_ibuf_84[li_44] = (l_high_16 + l_low_24) / 2.0;
      g_ibuf_88[li_44] = l_high_16;
      g_ibuf_92[li_44] = l_low_24;
   }
   for (int li_48 = MaxBars; li_48 >= 0; li_48--) {
      if (Close[li_48 + 1] > g_ibuf_88[li_48 + 1]) g_ibuf_96[li_48] = 1;
      else {
         if (Close[li_48 + 1] < g_ibuf_92[li_48 + 1]) g_ibuf_96[li_48] = 2;
         else g_ibuf_96[li_48] = 0;
      }
   }
   return (0);
}
