//+------------------------------------------------------------------+
//|                                           AO+EMA_zotik indicator |
//|                                                 Copyright © 2008 |
//|                                                     Zot@pisem.net|
//+------------------------------------------------------------------+

//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 3
#property  indicator_color1  Red
#property  indicator_color2  Green
#property  indicator_color3  Black
#property  indicator_width1  2
#property  indicator_width2  2
#property  indicator_width3  1
//---- indicator parameters
extern int FastSMA=3;
extern int SlowSMA=34;
extern int EMA=21;
extern int SlowEMA=55;
extern int V=34;
//---- indicator buffers
double     AOBuffer[];
double     EMABuffer[];
double     VBuffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- drawing settings
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexDrawBegin(1,EMA);
   IndicatorDigits(Digits+1);
//---- indicator buffers mapping
   SetIndexBuffer(0,AOBuffer);
   SetIndexBuffer(1,EMABuffer);
   SetIndexBuffer(2,VBuffer);
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("AO_Zotik("+FastSMA+","+SlowSMA+")/("+EMA+","+SlowEMA+")/("+V+")");
   SetIndexLabel(0,"AO");
   SetIndexLabel(1,"EMA");
   SetIndexLabel(2,"V");
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence                           |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
//---- macd counted in the 1-st buffer
   for(int i=0; i<limit; i++)
      AOBuffer[i]=iMA(NULL,0,FastSMA,0,MODE_SMA,PRICE_MEDIAN,i)-iMA(NULL,0,SlowSMA,0,MODE_SMA,PRICE_MEDIAN,i);
//---- signal line counted in the 2-nd buffer
   for(i=0; i<limit; i++)
      EMABuffer[i]=iMA(NULL,0,EMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
      //---- V line counted in the 3-d buffer
   for(i=0; i<limit; i++)
      VBuffer[i]=iMA(NULL,0,V,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,V,0,MODE_SMA,PRICE_MEDIAN,i);
//---- done
   return(0);
  }
//+------------------------------------------------------------------+