SRVI@2_v1

The Super Relative Vigor Index (SRVI) is a technical analysis tool designed to measure the strength of price trends by comparing the internal movement of price candles against their overall volatility. Unlike standard indicators that might only look at closing prices, this script examines the relationship between the "body" of the candle (the distance between open and close) and its "range" (the distance between the high and low).

How the Logic Works

1. Data Collection and Averaging The script looks back over a specific set of time periods (defined by the user). For every point in time, it calculates two primary values:

  • Upward Movement: It examines the difference between the opening and closing prices over four consecutive candles, applying a weighted average to ensure that the most recent price action carries more significance.
  • Downward Volatility: It examines the total range (High to Low) of those same four candles, again using a weighted approach.

By dividing the upward movement by the downward volatility, the script establishes a "Vigor" ratio. This tells you how much of the market's activity is actually moving the price in a specific direction versus just oscillating back and forth with no conviction.

2. Signal Smoothing To make the data easier to read and to filter out "noise" (erratic, minor price jumps), the script calculates a Signal Line. It creates this by taking a weighted average of the Vigor Index values over several periods. This resulting line acts as a secondary trend indicator, allowing you to see the broader momentum behind the primary data.

3. Value and Gap Analysis The script goes beyond simple lines by calculating two additional "Value" components:

  • Primary Value: A calculation that combines the Vigor Index with its Signal Line to highlight significant shifts in momentum.
  • Secondary Value (Gap Logic): The script identifies the distance (the "Difference") between the main index and the signal line. It then calculates a specific offset based on whether the main index is currently above or below the signal line.

Practical Purpose

The primary goal of this logic is to provide a clearer picture of market momentum. By identifying where the price movement is strong relative to its volatility, and by visualizing the "gap" between the current vigor and its historical average (the signal), traders can better identify when a trend is gaining strength, losing steam, or entering a period of indecision.

Miscellaneous
Implements a curve of type %1
9 Views
0 Downloads
0 Favorites
SRVI@2_v1
//+------------------------------------------------------------------+
//|                                   Super Relative Vigor Index.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property  copyright "Copyright © 2005, MetaQuotes Software Corp."
#property  link      "http://www.metaquotes.net/"
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 4
#property  indicator_color1  Black
#property  indicator_color2  Black
#property  indicator_color3  Yellow
#property  indicator_color4  Red
//---- indicator parameters
extern int ExtRVIPeriod=10;
//---- indicator buffers
double     ExtRVIBuffer[];
double     ExtRVISignalBuffer[];
double     ExtRVIValue[];
double     ExtRVIValue2[];
//--------------------------------------------------------------------
double Rozdiel;
//--------------------------------------------------------------------
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicator buffers mapping
   SetIndexBuffer(0,ExtRVIBuffer);
   SetIndexBuffer(1,ExtRVISignalBuffer);
   SetIndexBuffer(2,ExtRVIValue);
   SetIndexBuffer(3,ExtRVIValue2);
//---- indicator line
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexStyle(3,DRAW_LINE);
//---- drawing settings   
   SetIndexDrawBegin(0,ExtRVIPeriod+3);   
   SetIndexDrawBegin(1,ExtRVIPeriod+7);     
   SetIndexDrawBegin(2,ExtRVIPeriod);     
   SetIndexDrawBegin(3,ExtRVIPeriod);     
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("RVI("+ExtRVIPeriod+")");
   SetIndexLabel(0,"RVI");
   SetIndexLabel(1,"RVIS");
   SetIndexLabel(2,"Value");
   SetIndexLabel(3,"Value2");
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Relativ Vigor Index                                              |
//+------------------------------------------------------------------+
int start()
  {
   int i,j,nLimit,nCountedBars;
   double dValueUp,dValueDown,dNum,dDeNum;
//----
   if(Bars<=ExtRVIPeriod+8) return(0);
//----
   nCountedBars=IndicatorCounted();
//---- check for possible errors
   if(nCountedBars<0) return(-1);
//---- last counted bar will be recounted
   nLimit=Bars-ExtRVIPeriod-4;
   if(nCountedBars>ExtRVIPeriod+4)
      nLimit=Bars-nCountedBars;
//---- RVI counted in the 1-st buffer
   for(i=0; i<=nLimit; i++)
     {
      dNum=0.0; 
      dDeNum=0.0;
      for(j=i; j<i+ExtRVIPeriod; j++)
        {
         dValueUp=((Close[j]-Open[j])+2*(Close[j+1]-Open[j+1])+2*(Close[j+2]-Open[j+2])+(Close[j+3]-Open[j+3]))/6;
         dValueDown=((High[j]-Low[j])+2*(High[j+1]-Low[j+1])+2*(High[j+2]-Low[j+2])+(High[j+3]-Low[j+3]))/6;
         dNum+=dValueUp;
         dDeNum+=dValueDown;
        }
      if(dDeNum!=0.0)
         ExtRVIBuffer[i]=dNum/dDeNum;
      else
         ExtRVIBuffer[i]=dNum;   
      //==----==//
      ExtRVIValue[i]=ExtRVISignalBuffer[i]+ExtRVIBuffer[i]*4;
      if(ExtRVISignalBuffer[i]>ExtRVIBuffer[i])
       {
        Rozdiel=ExtRVISignalBuffer[i]-ExtRVIBuffer[i]/2;  
        ExtRVIValue2[i]=ExtRVIBuffer[i]+Rozdiel;
       }      
      if(ExtRVIBuffer[i]>ExtRVISignalBuffer[i])
       {
        Rozdiel=ExtRVIBuffer[i]-ExtRVISignalBuffer[i]/2;  
        ExtRVIValue2[i]=ExtRVISignalBuffer[i]+Rozdiel;
       }      
      //==----==//
     }
//---- signal line counted in the 2-nd buffer
   nLimit=Bars-ExtRVIPeriod-7;
   if(nCountedBars>ExtRVIPeriod+8)
      nLimit=Bars-nCountedBars+1;
   for(i=0; i<=nLimit; i++)
      ExtRVISignalBuffer[i]=(ExtRVIBuffer[i]+2*ExtRVIBuffer[i+1]+2*ExtRVIBuffer[i+2]+ExtRVIBuffer[i+3])/6;
      //==----==//
      ExtRVIValue[i]=ExtRVISignalBuffer[i]+ExtRVIBuffer[i]*4;
      if(ExtRVISignalBuffer[i]>ExtRVIBuffer[i])
       {
        Rozdiel=ExtRVISignalBuffer[i]-ExtRVIBuffer[i]/2;  
        ExtRVIValue2[i]=ExtRVIBuffer[i]+Rozdiel;
       }      
      if(ExtRVIBuffer[i]>ExtRVISignalBuffer[i])
       {
        Rozdiel=ExtRVIBuffer[i]-ExtRVISignalBuffer[i]/2;  
        ExtRVIValue2[i]=ExtRVISignalBuffer[i]+Rozdiel;
       }      
      //==----==//
//----
   return(0);
  }
//+------------------------------------------------------------------+
   

Comments