//+------------------------------------------------------------------+
//|                                                   MA_squeeze.mq4 |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, Milan Volf"

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Blue
#property indicator_color2 Brown
#property indicator_color3 Brown
#property indicator_color4 Blue
#property indicator_width1 1
#property indicator_width2 1
//---- indicator parameters
extern int    MA1=20;
extern int    MA2=50;
//---- buffers
double ma1[],ma2[],bull[],bear[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_HISTOGRAM,2);
   SetIndexBuffer(0,ma1);
   SetIndexLabel(0,"MA"+MA1);
   SetIndexStyle(1,DRAW_HISTOGRAM,2);
   SetIndexBuffer(1,ma2);
   SetIndexLabel(1,"MA"+MA2);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,bull);
   SetIndexLabel(2,NULL);
   SetIndexStyle(3,DRAW_LINE);
   SetIndexBuffer(3,bear);
   SetIndexLabel(3,NULL);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Bollinger Bands                                                  |
//+------------------------------------------------------------------+
int start()
  {
   int    i,k,counted_bars=IndicatorCounted();
   double D;
//----
   int limit=Bars-counted_bars;
   if(counted_bars>0) limit++;
   for(i=0; i<limit; i++){
      ma1[i]=iMA(NULL,0,MA1,0,MODE_EMA,PRICE_CLOSE,i);
      ma2[i]=iMA(NULL,0,MA2,0,MODE_EMA,PRICE_CLOSE,i);
      D=ma1[i]-ma2[i];
      bull[i]=ma1[i];
      bear[i]=ma2[i];
  }
//----
   return(0);
  }
//+------------------------------------------------------------------+