ROC2

This tool is designed as a multi-layered momentum indicator for the MetaTrader platform. Its primary purpose is to measure how quickly the price of an asset is changing over specific periods, allowing traders to visualize the speed and direction of market movement.

Core Functionality

The script calculates what is known as the "Rate of Change" (ROC). In simple terms, it looks at the current price and compares it to a previous price from a set number of bars back in time. By subtracting the old price from the new one, the tool identifies whether the market is moving up or down and by how much.

Key Features

  • Multi-Layered Analysis: Unlike basic indicators that only show one timeframe, this script can track up to eight different periods simultaneously. This allows you to observe short-term volatility alongside long-term trends on a single chart.
  • Customizable Timeframes: You can independently set the "lookback" period for each of the eight lines. For example, you could set one line to track changes over the last 10 bars (short-term) and another to track changes over 100 bars (long-term).
  • Flexible Calculation Modes: The tool offers two ways to display this data:
    • Absolute Change: Shows the raw numerical difference between the current price and the past price.
    • Percentage Change: When enabled, the tool converts these differences into a percentage. This is particularly useful for comparing different assets (like gold vs. currency pairs) because it standardizes the movement into a relative gain or loss.
  • Visual Clarity: Each of the eight possible data lines is assigned a unique color, making it easy to distinguish between different timeframes at a glance in a separate indicator window.

How It Helps Traders

By using this script, a trader can quickly identify "momentum." If all the lines are moving upward together, it suggests strong buying pressure. If some lines are moving up while others are flat or down, it may indicate that the trend is losing steam or that a reversal might be approaching. It essentially acts as a speedometer for the market.

Price Data Components
Series array that contains close prices for each bar
Miscellaneous
Implements a curve of type %1
12 Views
0 Downloads
0 Favorites
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);
  }
//+------------------------------------------------------------------+

Comments