//+------------------------------------------------------------------+
//|                                                    MA Filled.mq4 |
//|                                                     cja 04/2013. |
//+------------------------------------------------------------------+

#property indicator_chart_window
#property indicator_buffers 8
#property indicator_color1 Green 
#property indicator_color2 Red
#property indicator_color3 Violet
#property indicator_color4 Magenta
#property indicator_color5 Gold
#property indicator_color6 DodgerBlue
#property indicator_color7 Red 
#property indicator_color8 Green


#property indicator_style1 2
#property indicator_style2 2

#property indicator_width1 3
#property indicator_width2 3
#property indicator_width3 3
#property indicator_width4 3
#property indicator_width5 2
#property indicator_width6 2
#property indicator_width7 2
#property indicator_width8 2



extern int MA.Period    = 66;
extern int MA.Method    = 1;
extern int MA.Price     = 0;

extern int MA.Period.x  = 10;
extern int MA.Method.x  = 1;
extern int MA.Price.x   = 0;

extern int MA.Period.y  = 50;
extern int MA.Method.y  = 1;
extern int MA.Price.y   = 0;

extern int MA.Period.z  = 100;
extern int MA.Method.z  = 1;
extern int MA.Price.z   = 0;


double X[];
double Y[];
double Z[];
double MA_Buffer[];
double ribbon1[];
double ribbon2[];
double buy[];
double sell[];
//----
double myPoint;

  double SetPoint() 
   { 
   double mPoint; 
   
   if (Digits < 4) 
   mPoint = 0.01; 
   else 
   mPoint = 0.0001; 
   
   return(mPoint); 
   }
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   myPoint = SetPoint();  
  
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(0,ribbon1);
   SetIndexLabel(0,"");
   
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexBuffer(1,ribbon2);
   SetIndexLabel(1,"");
   
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,Y);
   SetIndexLabel(2,"");
   
   SetIndexStyle(3,DRAW_LINE);
   SetIndexBuffer(3,Z);
   SetIndexLabel(3,"");
 
   SetIndexStyle(4,DRAW_LINE);
   SetIndexBuffer(4,MA_Buffer);
   SetIndexLabel(4,"MA");
   
   SetIndexStyle(5,DRAW_LINE);
   SetIndexBuffer(5,X);
   SetIndexLabel(5,"");
   
   SetIndexBuffer(6,buy);
   SetIndexStyle(6,DRAW_ARROW);
   SetIndexArrow(6,234);
   SetIndexLabel(6,"");
   
   SetIndexBuffer(7,sell);
   SetIndexStyle(7,DRAW_ARROW);
   SetIndexArrow(7,233);
   SetIndexLabel(7,"");
  
   return(0);
  }
//+------------------------------------------------------------------+
//| MA Price display                                                 |
//+------------------------------------------------------------------+
int start()
  {
   int    i;
   int    counted_bars = IndicatorCounted();
   

   i = Bars-counted_bars-1;
   while( i >= 0 )
     {
     
      MA_Buffer[i] = iMA(NULL,0,MA.Period,0,MA.Method,MA.Price,i);
     
      X[i] = iMA(NULL,0,MA.Period.x,0,MA.Method.x,MA.Price.x,i);
      
      Y[i] = iMA(NULL,0,MA.Period.y,0,MA.Method.y,MA.Price.y,i);
      
      Z[i] = iMA(NULL,0,MA.Period.z,0,MA.Method.z,MA.Price.z,i);
      
      ribbon1[i] = iMA(NULL,0,MA.Period.y,0,MA.Method.y,MA.Price.y,i);
      
      ribbon2[i] = iMA(NULL,0,MA.Period.z,0,MA.Method.z,MA.Price.z,i);
      
         
     if( Z[i] < Y[i] && X[i] < Z[i] ) { ribbon1[i] = Y[i]; ribbon2[i] = Z[i];}
     if( X[i] < Y[i] && X[i] > Z[i] ) { ribbon1[i] = 0; ribbon2[i] = 0; }
     if( X[i] > Y[i] && X[i] < Z[i] ) { ribbon1[i] = 0; ribbon2[i] = 0; }
 
    
   crossCheck(i);
       i--;
       
     } 
     
   return(0);
  }

void crossCheck(int i){
   buy[i] = EMPTY_VALUE;
   sell[i] = EMPTY_VALUE;
   if(X[i+1] <= Z[i+1] && X[i] > Z[i]) sell[i] = Low[i] - myPoint*5;
   else 
      if(X[i+1] >= Z[i+1] && X[i] < Z[i]) buy[i] = High[i] + myPoint*5;
}
//+------------------------------------------------------------------+