//+------------------------------------------------------------------+
//|                                                    MA-Median.mq4 |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2012, zznbrm"

//---- indicator settings
#property indicator_chart_window
#property  indicator_buffers 1 
#property indicator_color1 White
#property indicator_width1 1

//---- input parameters
extern int eintPeriod = 14;
extern int eintMethod = MODE_SMA;

//---- indicator buffers
double gadblMA[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{   
   IndicatorDigits( Digits );
    
   //---- name for DataWindow and indicator subwindow label
   IndicatorShortName( "MA-Median(" + eintPeriod + ")" );
         
   SetIndexBuffer( 0, gadblMA );
   SetIndexStyle( 0, DRAW_LINE );
   SetIndexLabel( 0, "MA-Median(" + eintPeriod + ")" );
      
   return( 0 );
}

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{
   return( 0 );
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   int counted_bars = IndicatorCounted();
   
   if (counted_bars < 0) return (-1);
   if (counted_bars > 0) counted_bars--;
   int intLimit = Bars - counted_bars;
   
   double dblOpen, dblClose;
   
   for( int inx = intLimit; inx >= 0; inx-- )
   {
      dblOpen = iMA( Symbol(), Period(), eintPeriod, 0, eintMethod, PRICE_OPEN, inx );
      dblClose = iMA( Symbol(), Period(), eintPeriod, 0, eintMethod, PRICE_CLOSE, inx );
      
      gadblMA[inx] = ( dblOpen + dblClose ) * 0.5;
   }
   
   return( 0 );
}


