//+------------------------------------------------------------------+
//|                                                          ROC.mq4 |
//|                                    Copyright © 2006, Robert Hill |
//+------------------------------------------------------------------+

#property  copyright "Copyright © 2006, Robert Hill"
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 3
#property  indicator_color1  Red
#property  indicator_color2  Lime




//---- indicator parameters
extern int Bar=200;
extern bool Histo=false;

extern string     _________________Set_Ema1;
extern int MaPeriod1 = 10;
extern ENUM_MA_METHOD MaMethod   = MODE_LWMA;
extern ENUM_APPLIED_PRICE MaPrice = PRICE_CLOSE;
extern string    __________________Set_Ema2;
extern int MaPeriod2              = 50;

extern string    ___________________Set_Ema3;
extern int MaPeriod3              = 50;
extern string    ___________________Set_Ema4;
extern int MaPeriod4             = 200;





//---- indicator buffers
double Ema[];
double Ema2[];
double  trend[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- drawing settings

  SetIndexBuffer(0, Ema);
  SetIndexBuffer(1, Ema2);
  SetIndexBuffer(2, trend);


SetIndexStyle(0, DRAW_LINE);if(Histo)SetIndexStyle(0, DRAW_HISTOGRAM,0,2);
SetIndexStyle(1, DRAW_LINE);if(Histo)SetIndexStyle(1, DRAW_HISTOGRAM,0,2);
SetLevelValue(0,  0);
//---- indicator buffers mapping
 
   
   
   
   
      

 
//---- initialization done
   return(0);
}
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence                           |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   
   int countUp, countDn,count;
   
   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 = MathMin(Bars - counted_bars,Bars-1);
   
   countUp = 0;
   countDn = 0;   
   count = 0;  
   int i;
   

   for(i=Bar; i>=0; i--)
     {
       
          Ema[i] = iMA(NULL,0,MaPeriod1,0,MaMethod,MaPrice,i)/Point- iMA(NULL,0,MaPeriod2,0,MaMethod,MaPrice,i)/Point;;
          Ema2[i] =iMA(NULL,0,MaPeriod3,0,MaMethod,MaPrice,i)/Point- iMA(NULL,0,MaPeriod4,0,MaMethod,MaPrice,i)/Point;
           
      
           
               if(Ema[i] >0 && Ema[i+1] <0&&  Ema2[i]>0  ) trend[i] = 1;
         else if( Ema[i] <0 && Ema[i+1] >0 &&  Ema2[i]<0 ) trend[i] = -1;
            
             
             
           if(trend[i] == 1) countUp++; ;

          if (trend[i] == -1)  countDn++;;  
             
             
             
             
             
             
        
         
         
  
         
         
         
         
         
         
         
      


    }

Comment (countUp+"    "+countDn);   
        
           
        
   // if (  sig>LevelUp &&  Ema[0]  >0  )         ChartSetInteger(0,CHART_COLOR_BACKGROUND,Green );
  // else if (  sig<LevelDn &&  Ema [0] <0 )     ChartSetInteger(0,CHART_COLOR_BACKGROUND,Yellow);
  // else                      ChartSetInteger(0,CHART_COLOR_BACKGROUND,NULL);
   
   
   
   
   
   
   
   
   
   
  
     
//---- done
   return(0);
    }   
//+------------------------------------------------------------------+


   
   
   
   
   
   
   
   
   







