//+------------------------------------------------------------------+
//|                                                    MyMACD_V2.mq4 |
//|                                       Copyright © 2008, TheXpert |
//|                                           theforexpert@gmail.com |
//+------------------------------------------------------------------+

#property indicator_separate_window
#property indicator_buffers 2

#property indicator_color1 SkyBlue
#property indicator_color2 FireBrick

#property indicator_width1 2
#property indicator_width2 2

extern int period=10;

double UpValue[];
double DnValue[];

int i,j;
double pt,mt;

int init(){
   if(Digits==3 || Digits==5){
      pt=Point*10;
      mt=10;
   }else{
      pt=Point;
      mt=1;
   }
   IndicatorBuffers(5);
   
   IndicatorShortName("OverFlow");

   SetIndexBuffer(0, UpValue);
   SetIndexBuffer(1, DnValue);

   SetIndexStyle(0, DRAW_HISTOGRAM);
   SetIndexStyle(1, DRAW_HISTOGRAM);

   return(0);
}

int start(){
   int limit=Bars-IndicatorCounted();
   double upbuffer,dnbuffer,hi,lo;

   for(i=limit-2;i>=0;i--){
      //double ma1=iMA(NULL,0,period,0,MODE_EMA,0,i);
      //double ma2=iMA(NULL,0,period,0,MODE_EMA,0,i+1);
      
      upbuffer=0;
      dnbuffer=0;
      
      for(j=period;j>=0;j--){
         hi=MathMax(Close[i+j],Open[i+j]);
         lo=MathMin(Close[i+j],Open[i+j]);
         upbuffer=upbuffer+(High[i+j]-hi)/pt;
         dnbuffer=dnbuffer+(Low[i+j]-lo)/pt;
      }
      
      UpValue[i]=upbuffer;
      DnValue[i]=dnbuffer;
   }
   return(0);
}