//+------------------------------------------------------------------+
//|                                                 Accumulation.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
// 
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"

// ***********************************************                     modified by CODEMUNCHER@GMAIL.COM

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 LightSeaGreen
#property indicator_color2 OrangeRed
#property indicator_color3 DodgerBlue

extern int    MAperiod = 5;
extern int    MAtype   = 1;
extern double MA_Style = STYLE_DOT ;
extern color  MA_Color = OrangeRed ;
  

extern int    MAperiod2 = 50;
extern int    MAtype2   = 1;
extern double MA_Style2 = STYLE_DOT ;
extern color  MA_Color2 = DodgerBlue ;

//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];

double XX, YY;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorShortName("cm_A/D2");
   
//---- indicators

   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
   
   SetIndexStyle(1,DRAW_LINE,MA_Style, 1, MA_Color);
   SetIndexBuffer(1,ExtMapBuffer2);  
   
   SetIndexStyle(2,DRAW_LINE,MA_Style2, 1, MA_Color2);
   SetIndexBuffer(2,ExtMapBuffer3);   
    
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Accumulation/Distribution                                        |
//+------------------------------------------------------------------+
int start()
  {
  
  
   int limit,i,counted_bars=IndicatorCounted();
//----
   limit=Bars-counted_bars-1;
   
   i = limit;
   
   while(i>=0)
     {
      double high =High[i];
      double low  =Low[i];
      double open =Open[i];
      double close=Close[i];
      ExtMapBuffer1[i]=(close-low)-(high-close);
      if(ExtMapBuffer1[i]!=0)
        {
         double diff=high-low;
         if(0==diff)
            ExtMapBuffer1[i]=0;
         else
           {
            ExtMapBuffer1[i]/=diff;
            ExtMapBuffer1[i]*=Volume[i];
           }
        }
      if(i<Bars-1) ExtMapBuffer1[i]+= NormalizeDouble( ExtMapBuffer1[i+1], Digits ) ;
      i--;
     }
     
     
  for(i = limit ; i >= 0; i--) 
  { 
   XX               = iMAOnArray(ExtMapBuffer1,Bars,MAperiod,0,MAtype,i);   
   ExtMapBuffer2[i] = NormalizeDouble(XX, Digits ) ;  
   
   YY               = iMAOnArray(ExtMapBuffer1,Bars,MAperiod2,0,MAtype2,i);   
   ExtMapBuffer3[i] = NormalizeDouble(YY, Digits ) ;    
  }     
     
     
//----
   return(0);
  }
//+------------------------------------------------------------------+