Author: Copyright � Roman Shiredchenko, 2009
ravi_base

This tool is a custom technical indicator designed for the MetaTrader platform to help traders visualize relative price momentum and trends. Instead of plotting the raw price of an asset, it calculates a specific percentage-based relationship between two different moving averages, providing a clearer picture of how the current price trend is behaving relative to its longer-term historical average.

How the Logic Works

The indicator operates by comparing two distinct "Simple Moving Averages" (SMA) simultaneously:

  • Short-Term Trend: It tracks a fast-moving average based on a small number of previous data points (defaulting to 7 periods). This reacts quickly to recent price fluctuations.
  • Long-Term Trend: It tracks a much slower-moving average based on a larger window of historical data (defaulting to 65 periods). This represents the broader, underlying direction of the market.

The Calculation Process

The core logic follows these steps to generate the visual line you see on your screen:

  1. Data Gathering: The script scans through your price history (up to a user-defined limit of 5,000 bars) to identify the current values for both the short-term and long-term averages.
  2. Difference Analysis: It calculates the mathematical difference between these two averages. By subtracting the long-term value from the short-term value, the tool identifies how far the "current" price has strayed from its "average" path.
  3. Percentage Conversion: To make this data easy to read, the script converts that difference into a percentage. It takes the difference, multiplies it by 100, and divides it by the long-term average value.
  4. Visual Output: The resulting figure is plotted on a separate window as a solid blue line.

What This Means for the Trader

By viewing this percentage-based line rather than raw price bars, you can more easily identify:

  • Trend Strength: When the line moves significantly above or below the zero level, it indicates how aggressively the price is pushing in one direction.
  • Overextension: Significant spikes in the percentage may suggest that the price is moving too far, too fast, relative to its historical norm.
  • Momentum Shifts: When the line crosses back toward the center, it signals a loss of momentum in the current trend.

In summary, this script acts as a "momentum thermometer," showing you not just where the price is, but how much energy is behind its current movement compared to its historical behavior.

Indicators Used
Moving average indicator
9 Views
0 Downloads
0 Favorites
ravi_base
//--------------------------------------------------------------------
// ravi.mq4 
//--------------------------------------------------------------- 1 --
#property copyright "Copyright © Roman Shiredchenko, 2009"
//--------------------------------------------------------------------
#property indicator_separate_window 
#property indicator_buffers 1      // Êîëè÷åñòâî áóôåðîâ
#property indicator_color1  Blue    // Öâåò ëèíèè 0 áóôåðà

#property  indicator_level1  1
#property  indicator_level2  -1
//--------------------------------------------------------------- 2 --
//---- indicator parameters 

extern int History    =5000;      // Êîëè÷.áàðîâ â ðàñ÷¸òíîé èñòîðèè
extern int Period1=7; 
extern int Period2=65; 

double
   Line_0[];                        // Èíä. ìàññèâ  ravi 
    
//--------------------------------------------------------------- 4 --

int init()                          // Ñïåöèàëüíàÿ ôóíêöèÿ init()
  {
   SetIndexBuffer(0,Line_0);        // Íàçíà÷åíèå ìàññèâà áóôåðó
   SetIndexStyle (0,DRAW_LINE,STYLE_SOLID,2);// Ñòèëü ëèíèè
   
   IndicatorShortName("ravi_base");
//--------------------------------------------------------------- 5 --
   
   return;                          // Âûõîä èç ñïåö. ôóíêöèè init()
  }

//--------------------------------------------------------------- 8 --
int start()                         // Ñïåöèàëüíàÿ ôóíêöèÿ start()
  {
//--------------------------------------------------------------- 9 --
  
   double
   SMA1,  SMA2;                  // 2 ÌÀ äëÿ ðàñ÷åòà çíà÷åíèé èíäèêàòîðà 
                                 // ôîðìyëà (SMA1-SMA2)*100)/SMA2; 
                             
   int
   i,                            // Èíäåêñ áàðà
   n,                            // Ôîðìàëüí. ïàðàìåòð(èíäåêñ áàðà)
   Counted_bars;                 // Êîëè÷åñòâî ïðîñ÷èòàííûõ áàðîâ 

//-------------------------------------------------------------- 10 --
   Counted_bars=IndicatorCounted(); // Êîëè÷åñòâî ïðîñ÷èòàííûõ áàðîâ 
   i=Bars-Counted_bars-1;           // Èíäåêñ ïåðâîãî íåïîñ÷èòàííîãî
   if (i>History-1)                 // Åñëè ìíîãî áàðîâ òî ..
      i=History-1;                  // ..ðàññ÷èòûâàòü çàäàííîå êîëè÷.
//-------------------------------------------------------------- 11 --
   while(i>=0)                      // Öèêë ïî íåïîñ÷èòàííûì áàðàì
     {
      //-------------------------------------------------------- 12 --
        
      SMA1=iMA(NULL,0,Period1,0,MODE_SMA,PRICE_CLOSE,i); // Çíà÷åíèå  ÌÀ1
      SMA2=iMA(NULL,0,Period2,0,MODE_SMA,PRICE_CLOSE,i); // Çíà÷åíèå  ÌÀ2
      
      Line_0[i] =0; 
      if (SMA2>0) Line_0[i] = ((SMA1-SMA2)*100)/SMA2;    //  Èíäèê. ìàññèâ ëèíèè ravi
     
      //-------------------------------------------------------- 13 --
      i--;                          // Ðàñ÷¸ò èíäåêñà ñëåäóþùåãî áàðà
      //-------------------------------------------------------- 14 --
     }
   return;                          // Âûõîä èç ñïåö. ô-èè start()
  }
//-------------------------------------------------------------- 15 --

Comments