
#property copyright "Copyright © 2009, CompassFX"
#property link      "http://www.compassfx.com"

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Red
#property indicator_color2 DodgerBlue
#property indicator_color3 Red
#property indicator_color4 DodgerBlue

extern string CustomIndicator = "Synergy Average Price Bars";
extern string Copyright = "© 2009, CompassFX";
extern string WebAddress = "www.compassfx.com";
double gibuf100[];
double gibuf104[];
double gibuf108[];
double gibuf112[];
int gi116 = 0;

int init() {
   SetIndexStyle(0, DRAW_HISTOGRAM, STYLE_SOLID, 1, Red);
   SetIndexBuffer(0, gibuf100);
   SetIndexLabel(0, "HA0");
   SetIndexStyle(1, DRAW_HISTOGRAM, STYLE_SOLID, 1, DodgerBlue);
   SetIndexBuffer(1, gibuf104);
   SetIndexLabel(1, "HA1");
   SetIndexStyle(2, DRAW_HISTOGRAM, STYLE_SOLID, 3, Red);
   SetIndexBuffer(2, gibuf108);
   SetIndexLabel(2, "HAOpen");
   SetIndexStyle(3, DRAW_HISTOGRAM, STYLE_SOLID, 3, DodgerBlue);
   SetIndexBuffer(3, gibuf112);
   SetIndexLabel(3, "HAClose");
   SetIndexDrawBegin(0, 10);
   SetIndexDrawBegin(1, 10);
   SetIndexDrawBegin(2, 10);
   SetIndexDrawBegin(3, 10);
   SetIndexBuffer(0, gibuf100);
   SetIndexBuffer(1, gibuf104);
   SetIndexBuffer(2, gibuf108);
   SetIndexBuffer(3, gibuf112);
   return (0);
}

int deinit() {
   return (0);
}

int start() {
   double ld0;
   double ld8;
   double ld16;
   double ld24;
   if (Bars <= 10) return (0);
   gi116 = IndicatorCounted();
   if (gi116 < 0) return (-1);
   if (gi116 > 0) gi116--;
   for (int li32 = Bars - gi116 - 1; li32 >= 0; li32--) {
      ld24 = NormalizeDouble((Open[li32] + High[li32] + Low[li32] + Close[li32]) / 4.0, Digits);
      ld24 = (ld24 + Close[li32]) / 2.0;
      ld0 = (gibuf108[li32 + 1] + (gibuf112[li32 + 1])) / 2.0;
      ld8 = MathMax(High[li32], MathMax(ld0, ld24));
      ld16 = MathMin(Low[li32], MathMin(ld0, ld24));
      if (ld0 < ld24) {
         gibuf100[li32] = ld16;
         gibuf104[li32] = ld8;
      } else {
         gibuf100[li32] = ld8;
         gibuf104[li32] = ld16;
      }
      gibuf108[li32] = ld0;
      gibuf112[li32] = ld24;
   }
   return (0);
}

