ROC2





//+------------------------------------------------------------------+
//|                                                          ROC.mq4 |
//|                                    Copyright © 2006, Robert Hill |
//+------------------------------------------------------------------+

#property  copyright "Copyright © 2006, Robert Hill"
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 8
#property  indicator_color1  Red
#property  indicator_color2  White
#property  indicator_color3  Lime
#property  indicator_color4  Blue
#property  indicator_color5  Yellow
#property  indicator_color6  Goldenrod
#property  indicator_color7  Magenta
#property  indicator_color8  Beige
//---- indicator parameters
extern int RPeriod = 10;
extern int RPeriod2 = 0;
extern int RPeriod3 = 0;
extern int RPeriod4 = 0;
extern int RPeriod5 = 0;
extern int RPeriod6 = 0;
extern int RPeriod7 = 0;
extern int RPeriod8 = 0;
extern bool UsePercent = false;
//---- indicator buffers
double RateOfChange[];
double RateOfChange2[];
double RateOfChange3[];
double RateOfChange4[];
double RateOfChange5[];
double RateOfChange6[];
double RateOfChange7[];
double RateOfChange8[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- drawing settings
   SetIndexStyle(0, DRAW_LINE);
   SetIndexDrawBegin(0, RPeriod);
   
   SetIndexStyle(1, DRAW_LINE);
   SetIndexDrawBegin(0, RPeriod2);
   
   SetIndexStyle(2, DRAW_LINE);
   SetIndexDrawBegin(0, RPeriod3);
   
   SetIndexStyle(3, DRAW_LINE);
   SetIndexDrawBegin(0, RPeriod4);
   
   SetIndexStyle(4, DRAW_LINE);
   SetIndexDrawBegin(0, RPeriod5);
   
   SetIndexStyle(5, DRAW_LINE);
   SetIndexDrawBegin(0, RPeriod6);
   
   SetIndexStyle(6, DRAW_LINE);
   SetIndexDrawBegin(0, RPeriod7);
   
   SetIndexStyle(7, DRAW_LINE);
   SetIndexDrawBegin(0, RPeriod8);

   IndicatorDigits(Digits + 1);
//---- indicator buffers mapping
   if(!SetIndexBuffer(0, RateOfChange))
       Print("cannot set indicator buffers!");

   SetIndexBuffer(1, RateOfChange2);
   SetIndexBuffer(2, RateOfChange3);
   SetIndexBuffer(3, RateOfChange4);
   SetIndexBuffer(4, RateOfChange5);
   SetIndexBuffer(5, RateOfChange6);
   SetIndexBuffer(6, RateOfChange7);
   SetIndexBuffer(7, RateOfChange8);

//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("ROC(" + RPeriod + ") (" + RPeriod2 + ") (" + RPeriod3 + ") (" + RPeriod4 + ") (" + RPeriod5 + ") (" + RPeriod6 + ") (" + RPeriod7 + ") (" + RPeriod8 + ")");
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence                           |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   double ROC, CurrentClose, PrevClose;
   double ROC2, PrevClose2;
   double ROC3, PrevClose3;
   double ROC4, PrevClose4;
   double ROC5, PrevClose5;
   double ROC6, PrevClose6;
   double ROC7, PrevClose7;
   double ROC8, PrevClose8;
   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 - RPeriod;
//---- ROC calculation
   for(int i = 0; i < limit; i++)
     {
       CurrentClose = iClose(NULL, 0, i);
       PrevClose = iClose(NULL, 0, i + RPeriod);
       ROC = CurrentClose - PrevClose;

       if(RPeriod2>0)
       {
       PrevClose2 = iClose(NULL, 0, i + RPeriod2);
       ROC2 = CurrentClose - PrevClose2;
       }

       if(RPeriod3>0)
       {
       PrevClose3 = iClose(NULL, 0, i + RPeriod3);
       ROC3 = CurrentClose - PrevClose3;
       }
       
       if(RPeriod4>0)
       {
       PrevClose4 = iClose(NULL, 0, i + RPeriod4);
       ROC4 = CurrentClose - PrevClose4;
       }

       if(RPeriod5>0)
       {
       PrevClose5 = iClose(NULL, 0, i + RPeriod5);
       ROC5 = CurrentClose - PrevClose5;
       }
       
       if(RPeriod6>0)
       {
       PrevClose6 = iClose(NULL, 0, i + RPeriod6);
       ROC6 = CurrentClose - PrevClose6;
       }
       
       if(RPeriod7>0)
       {
       PrevClose7 = iClose(NULL, 0, i + RPeriod7);
       ROC7 = CurrentClose - PrevClose7;
       }
       
       if(RPeriod8>0)
       {
       PrevClose8 = iClose(NULL, 0, i + RPeriod8);
       ROC8 = CurrentClose - PrevClose8;
       }

       //----
       if(UsePercent)
         {
           if(PrevClose != 0)
               RateOfChange[i] = 100 * ROC / PrevClose;

           if(RPeriod2>0)
           {
           if(PrevClose2 != 0)
               RateOfChange2[i] = 100 * ROC2 / PrevClose2;
           }    
               
           if(RPeriod3>0)
           {
           if(PrevClose3 != 0)
               RateOfChange3[i] = 100 * ROC3 / PrevClose3;
           }
           
           if(RPeriod4>0)
           {
           if(PrevClose4 != 0)
               RateOfChange4[i] = 100 * ROC4 / PrevClose4;
           }
           
           if(RPeriod5>0)
           {
           if(PrevClose5 != 0)
               RateOfChange5[i] = 100 * ROC5 / PrevClose5;
           }
           
           if(RPeriod6>0)
           {
           if(PrevClose6 != 0)
               RateOfChange6[i] = 100 * ROC6 / PrevClose6;
           }
           
           if(RPeriod7>0)
           {
           if(PrevClose7 != 0)
               RateOfChange7[i] = 100 * ROC7 / PrevClose7;
           }
           
           if(RPeriod8>0)
           {
           if(PrevClose8 != 0)
               RateOfChange8[i] = 100 * ROC8 / PrevClose8;
           }
                      
         }
       else {
           RateOfChange[i] = ROC;
           RateOfChange2[i] = ROC2;
           RateOfChange3[i] = ROC3;
           RateOfChange4[i] = ROC4;
           RateOfChange5[i] = ROC5;
           RateOfChange6[i] = ROC6;
           RateOfChange7[i] = ROC7;
           RateOfChange8[i] = ROC8;                                                       
           }
     } 
     

                 
//---- done
   return(0);
  }
//+------------------------------------------------------------------+



Sample





Analysis



Market Information Used:

Series array that contains close prices for each bar


Indicator Curves created:

Implements a curve of type DRAW_LINE


Indicators Used:



Custom Indicators Used:

Order Management characteristics:

Other Features: