//+------------------------------------------------------------------+
//|                                                     ma total.mq4 |
//|                                                            ....h |
//|                                                 hayseedville.com |
//+------------------------------------------------------------------+
#property copyright "....h"
#property link      "hayseedville.com"

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_color2 White


extern int       periods    = 21;
extern int       method     =  3;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_HISTOGRAM,0,4);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_HISTOGRAM,0,4);
   SetIndexBuffer(1,ExtMapBuffer2);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   double ma1;
   double ma2;
   int limit;
   
   
   int counted_bars = IndicatorCounted();
   //---- check for possible errors
   if (counted_bars<0) return(-1);
   
   //---- last counted bar will be recounted
   if (counted_bars>0) counted_bars--;
   
   limit = Bars - counted_bars;

    for(int i=limit; i>=0; i--)
    {
    ma1 = iMA(NULL,0,periods,0,method, 0,i);
    ma2 = iMA(NULL,0,periods,0,method, 0,i+1);
    
    
    ExtMapBuffer2[i] = ma1; 
    ExtMapBuffer1[i] = ma2; 
       
    if(ma1 >= ma2)
    {
    ExtMapBuffer2[i] = EMPTY_VALUE;
    }
    else
    if(ma1 < ma2) 
    {
    ExtMapBuffer1[i] = EMPTY_VALUE;
    }
    else 
    {
    ExtMapBuffer1[i]=EMPTY_VALUE;
    ExtMapBuffer2[i]=EMPTY_VALUE;
    }
    }    
    
    
    return(0);
   }
//+------------------------------------------------------------------+



