//+------------------------------------------------------------------+
//|                                                      Buff MA.mq4 |
//|                      Copyright © 2007, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_chart_window
#property indicator_buffers 1

#property indicator_color1 Blue

double BUFF[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
  string short_name;
  
  IndicatorBuffers(1);
  
//---- indicator lines
  SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2,Blue);
  SetIndexBuffer(0,BUFF);
  SetIndexLabel(0,"Buff MA");
  
//---- name for DataWindow and indicator subwindow label
   short_name="Buff MA";
   IndicatorShortName(short_name);
   
//----
   SetIndexDrawBegin(0,100);     
  
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Buff MA                                                          |
//+------------------------------------------------------------------+
int start() 
  { 
   int i,counted_bars=IndicatorCounted(); 
   if(Bars<=32) return(0); 
   if(counted_bars<1) for(i=1;i<=32;i++) BUFF[Bars-i]=EMPTY_VALUE; 
   i=Bars-33; 
   if(counted_bars>=32) i=Bars-counted_bars-1; 
   while(i>=0) 
     { 
      indicate(i); 
      i--; 
     } 
   return(0); 
  } 
void indicate(int bar)
{
    double sum=0; 
    double v=0; 
    for ( int i=0; i<32; i++ ) {
        sum += Volume[ bar + i ] * Close[ bar + i ]; 
        v += Volume[ bar + i ];
    }
    BUFF[ bar ] = sum/v;
}


//+------------------------------------------------------------------+