RVI
Download scriptThe Relative Vigor Index (RVI) is a technical analysis tool designed to help traders gauge the strength of price movements. Unlike some indicators that simply look at whether a price is moving up or down, this script measures the "vigor" or intensity of those moves by comparing the closing prices against the opening and high/low ranges of the market.
How the Logic Works
The indicator operates by processing historical price data through two primary calculations to create a visual representation of market momentum:
1. Calculating Market Vigor The script looks at a specific window of recent bars (determined by the user-defined period). For each bar within this window, it evaluates two distinct types of movement:
- Upward Momentum: It calculates the difference between the closing price and the opening price across multiple consecutive bars. By weighting the middle bars more heavily, it identifies how strongly the price is being pushed toward the top of its range.
- Downward Volatility: Simultaneously, it measures the total distance between the "High" and "Low" prices for those same bars. This represents the overall volatility or "room" the price has moved within during that timeframe.
By dividing the upward momentum by this total volatility, the script produces a ratio. This ratio tells you how much of the available price action is actually being used to move the price higher.
2. Generating the Signal Line Once the primary RVI value is established, the script applies a secondary "smoothing" calculation. It takes the RVI values from the most recent periods and averages them out. This creates a Signal Line.
What it Shows on the Chart
The indicator appears in a separate window below your main price chart as two distinct lines:
- The Main RVI Line: This represents the current strength of the trend. When this line is high, it suggests strong buying pressure; when it is low, it suggests dominant selling pressure.
- The Signal Line: This acts as a guide for the main line. Because it is an average of previous RVI values, it moves more slowly than the main line.
Practical Interpretation
Traders typically use these two lines to identify shifts in momentum. When the main RVI line crosses above or below its signal line, it can indicate a potential change in the trend's strength. Because the logic filters out "noise" by comparing price movement against total volatility, it aims to provide a clearer picture of whether a current trend has enough energy to continue or if it is beginning to exhaust itself.
//+------------------------------------------------------------------+
//| Relativ 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 2
#property indicator_color1 Green
#property indicator_color2 Red
//---- indicator parameters
extern int ExtRVIPeriod=10;
//---- indicator buffers
double ExtRVIBuffer[];
double ExtRVISignalBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicator buffers mapping
SetIndexBuffer(0,ExtRVIBuffer);
SetIndexBuffer(1,ExtRVISignalBuffer);
//---- indicator line
SetIndexStyle(0,DRAW_LINE);
SetIndexStyle(1,DRAW_LINE);
//---- drawing settings
SetIndexDrawBegin(0,ExtRVIPeriod+3);
SetIndexDrawBegin(1,ExtRVIPeriod+7);
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("RVI("+ExtRVIPeriod+")");
SetIndexLabel(0,"RVI");
SetIndexLabel(1,"RVIS");
//---- 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;
}
//---- 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;
//----
return(0);
}
//+------------------------------------------------------------------+
Comments