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

#property indicator_separate_window
#property indicator_buffers 6
#property indicator_color1 Black
#property indicator_color2 Black
#property indicator_color3 Black
#property indicator_color4 Black
#property indicator_color5 Black
#property indicator_color6 Black

extern int VolumeMAPeriods = 14;
extern color VolumeMAColor = DodgerBlue;
extern color DownVolumColor = LightSalmon;
extern color LowerCloseColor = Red;
extern color HigherCloseColor = Blue;
extern color SameCloseColor = Black;
int gi_100 = 0;
int gi_104 = 0;
int gi_108 = 1304208000;
bool gi_112 = FALSE;
double gda_116[];
double gda_120[];
double gda_124[];
double gda_128[];
double gda_132[];
double gda_136[];


int init() {
   
   initBuffer(gda_116, "Tick Volume", DRAW_NONE, 0, EMPTY_VALUE, 0, CLR_NONE, 0);
   initBuffer(gda_120, "Tick Volume MA", DRAW_LINE, 0, EMPTY_VALUE, 2, VolumeMAColor, 0);
   initBuffer(gda_124, "", DRAW_HISTOGRAM, 0, EMPTY_VALUE, 3, DownVolumColor, 0);
   initBuffer(gda_128, "", DRAW_HISTOGRAM, 0, EMPTY_VALUE, 3, LowerCloseColor, 0);
   initBuffer(gda_132, "", DRAW_HISTOGRAM, 0, EMPTY_VALUE, 3, HigherCloseColor, 0);
   initBuffer(gda_136, "", DRAW_HISTOGRAM, 0, EMPTY_VALUE, 3, SameCloseColor, 0);
   IndicatorBuffers(gi_100);
   IndicatorDigits(0);
   IndicatorShortName("TradeGuider VSA Volume");
   
   gi_112 = TRUE;
   gi_104 = VolumeMAPeriods;
   return (0);
}

int deinit() {
   return (0);
}

int start() {
   int li_0 = Bars - IndicatorCounted();
   if (gi_112 == FALSE) return (0);
   for (int li_4 = li_0; li_4 >= 0; li_4--) {
      gda_116[li_4] = Volume[li_4];
      gda_120[li_4] = CalcMA(li_4);
      if (Volume[li_4] < Volume[li_4 + 1] && Volume[li_4] < Volume[li_4 + 2]) {
         gda_124[li_4] = Volume[li_4];
         gda_128[li_4] = EMPTY_VALUE;
         gda_132[li_4] = EMPTY_VALUE;
         gda_136[li_4] = EMPTY_VALUE;
      } else {
         if (Close[li_4] < Close[li_4 + 1]) {
            gda_124[li_4] = EMPTY_VALUE;
            gda_128[li_4] = Volume[li_4];
            gda_132[li_4] = EMPTY_VALUE;
            gda_136[li_4] = EMPTY_VALUE;
         } else {
            if (Close[li_4] > Close[li_4 + 1]) {
               gda_128[li_4] = EMPTY_VALUE;
               gda_124[li_4] = EMPTY_VALUE;
               gda_132[li_4] = Volume[li_4];
               gda_136[li_4] = EMPTY_VALUE;
            } else {
               gda_128[li_4] = EMPTY_VALUE;
               gda_124[li_4] = EMPTY_VALUE;
               gda_132[li_4] = EMPTY_VALUE;
               gda_136[li_4] = Volume[li_4];
            }
         }
      }
   }
   return (0);
}

double CalcMA(int ai_0) {
   double ld_ret_4 = 0.0;
   for (int li_12 = ai_0; li_12 < ai_0 + VolumeMAPeriods; li_12++) ld_ret_4 += Volume[li_12];
   ld_ret_4 /= VolumeMAPeriods;
   return (ld_ret_4);
}

void initBuffer(double ada_0[], string as_4 = "", int ai_12 = 12, int ai_16 = 0, int a_style_20 = -1, int ai_24 = -1, color a_color_28 = -1, int ai_32 = 0) {
   SetIndexBuffer(gi_100, ada_0);
   SetIndexLabel(gi_100, as_4);
   SetIndexEmptyValue(gi_100, EMPTY_VALUE);
   SetIndexDrawBegin(gi_100, gi_104);
   SetIndexShift(gi_100, ai_32);
   SetIndexStyle(gi_100, ai_12, a_style_20, ai_24, a_color_28);
   SetIndexArrow(gi_100, ai_16);
   gi_100++;
}