
#property copyright "Copyright © 2009, TradeWays"
#property link      "http://www.tradeways.org"

#property indicator_separate_window
#property indicator_minimum 0.0
#property indicator_maximum 5.0
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red

extern int MoveLength = 14;
extern int BoxLevel = 1;
double gd_84;
double gd_92;
double g_ibuf_100[];
double g_ibuf_104[];
double gda_unused_108[];
double gda_unused_112[];
double gda_unused_116[];
double g_ibuf_120[];
double g_ibuf_124[];
double g_ibuf_128[];

int init() {
   IndicatorBuffers(5);
   SetIndexStyle(0, DRAW_ARROW);
   SetIndexArrow(0, 110);
   SetIndexBuffer(0, g_ibuf_104);
   SetIndexStyle(1, DRAW_ARROW);
   SetIndexArrow(1, 110);
   SetIndexBuffer(1, g_ibuf_100);
   SetIndexBuffer(2, g_ibuf_120);
   SetIndexBuffer(3, g_ibuf_124);
   SetIndexBuffer(4, g_ibuf_128);
   SetIndexEmptyValue(2, 0.0);
   SetIndexEmptyValue(3, 0.0);
   SetIndexEmptyValue(4, 0.0);
   SetIndexLabel(0, "");
   SetIndexLabel(1, "");
   IndicatorShortName("#PalladaSE_SessionMovement (" + MoveLength + ")");
   return (0);
}

int deinit() {
   return (0);
}

int start() {
   double ld_20;
   double ld_28;
   double ld_36;
   double ld_44;
   double ld_52;
   //if (TimeCurrent() > StrToTime("2009.04.20")) {
   //   Alert("New version available! Download it using re-activated link from Plimus");
   //   return;
   //}
   int li_0 = IndicatorCounted();
   if (li_0 < 0) return (-1);
   if (li_0 > 0) li_0--;
   int li_8 = Bars - li_0;
   li_8 = MathMin(li_8, Bars - 2);
   double ld_12 = 1.0 / MoveLength;
   for (int li_4 = li_8; li_4 >= 0; li_4--) {
      ld_20 = MathMax(High[li_4], Close[li_4 + 1]) - MathMin(Low[li_4], Close[li_4 + 1]);
      ld_28 = High[li_4] - (High[li_4 + 1]);
      ld_36 = Low[li_4 + 1] - Low[li_4];
      ld_44 = 0.0;
      ld_52 = 0.0;
      if (ld_28 > ld_36 && ld_28 > 0.0) ld_44 = ld_28;
      if (ld_36 > ld_28 && ld_36 > 0.0) ld_52 = ld_36;
      g_ibuf_120[li_4] = g_ibuf_120[li_4 + 1] + ld_12 * (ld_44 - (g_ibuf_120[li_4 + 1]));
      g_ibuf_124[li_4] = g_ibuf_124[li_4 + 1] + ld_12 * (ld_52 - (g_ibuf_124[li_4 + 1]));
      g_ibuf_128[li_4] = g_ibuf_128[li_4 + 1] + ld_12 * (ld_20 - (g_ibuf_128[li_4 + 1]));
      gd_84 = 0.0;
      gd_92 = 0.0;
      if (g_ibuf_128[li_4] > 0.0) {
         gd_84 = 100.0 * g_ibuf_120[li_4] / g_ibuf_128[li_4];
         gd_92 = 100.0 * g_ibuf_124[li_4] / g_ibuf_128[li_4];
      }
      g_ibuf_100[li_4] = EMPTY_VALUE;
      g_ibuf_104[li_4] = EMPTY_VALUE;
      if (gd_92 > gd_84) g_ibuf_100[li_4] = BoxLevel;
      if (gd_92 < gd_84) g_ibuf_104[li_4] = BoxLevel;
   }
   return (0);
}