Relative Vigor Index
Download scriptThe Relative Vigor Index (RVI) is a momentum-based technical analysis tool designed to help traders understand the strength and direction of price movements. Unlike standard indicators that might only look at whether a price is going up or down, this script measures the "vigor" or intensity behind those moves by comparing the body of the candles to their total range.
How the Logic Works
To provide a clear picture of market momentum, the script performs a multi-step calculation based on three core concepts:
1. Measuring Price Movement (The Core Data) The script looks at each individual price candle and extracts two key pieces of information:
- Body Activity: It calculates the difference between the opening and closing prices. This represents the actual progress made by the market during a specific period.
- Total Range: It calculates the distance between the highest and lowest points reached during that same period. This represents the total volatility or "workspace" of the price.
2. Weighted Averaging Rather than looking at just one candle—which could be an outlier or a "noise" spike—the script uses a weighted approach. It gathers data from a sequence of nearby candles (determined by the user-defined "Length").
- It gives more weight to the most recent candles in that sequence.
- By doing this, it creates a smoother, more reliable trend line that filters out minor fluctuations while still remaining responsive to real market changes.
3. The Ratio Calculation The final value shown on your chart is a ratio. The script divides the Total Body Activity by the Total Range.
- If the price is moving strongly in one direction with very little "wasted" movement, the indicator reflects high vigor.
- If the price is swinging wildly (large highs and lows) but barely making progress toward a target (small bodies), the indicator reflects low vigor.
How to Read the Results
The script displays this data as two distinct lines on a separate window:
- Primary Line: This shows the current RVI value. It tells you how much "effort" is currently being put into the trend. When the line moves significantly away from the zero mark, it suggests a strong, vigorous move in the market.
- Secondary Line: This acts as a trailing reference, showing the previous period's value to help you visualize the rate of change and identify potential shifts in momentum before they become obvious on the main price chart.
In short, this tool helps you distinguish between a "weak" trend (high volatility but little progress) and a "strong" trend (steady movement with purposeful direction).
//+------------------------------------------------------------------+
//| Relative Vigor Index |
//| Copyright © 2006, Luis Guilherme Damiani |
//| http://www.damianifx.com.br |
//|
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Luis Guilherme Damiani"
#property link "http://www.damianifx.com.br"
#property indicator_buffers 2
#property indicator_separate_window
//#property indicator_chart_window
#property indicator_color1 Yellow
#property indicator_color2 Green
//#property indicator_color3 Yellow
//---- input parameters
extern double length=10;
//extern int maxbars=2000;
//extern string
//Price_Choice="----- Typical or Median --------------";
//extern bool is_median=true;
//---- buffers
double ind1[];
double ind2[];
//double ind3[];
//double AuxBuffer[]; //Smooth
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,ind1);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,ind2);
// SetIndexStyle(2,DRAW_LINE);
// SetIndexBuffer(2,ind3);
SetLevelValue(0,0.0);
// SetLevelValue(1,-0.8);
ArrayInitialize(ind1,0.0);
ArrayInitialize(ind2,0.0);
// ArrayInitialize(ind3,0.0);
/// ArrayResize(AuxBuffer,maxbars+3);
// ArrayInitialize(AuxBuffer,0.0);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
double num=0,denom=0;
//---- check for possible errors
if(counted_bars<0) return(-1);
int limit=Bars-counted_bars;
// if(limit>maxbars)limit=maxbars;
//if (limit>Bars-1)limit=Bars-1;
//----
for (int i = limit; i>=0;i--)
{
num=0;denom=0;
for(int j=0;j<length;j++)
{
num=num+v1(i,j);
denom=denom+v2(i,j);
}
if(denom!=0)ind1[i]=num/denom;
ind2[i]=ind1[i+1];
}
//----
return(0);
}
double v1(int x,int y)
{
double pr;
pr=((Close[x+y]-Open[x+y])+2*(Close[x+y+1]-Open[x+y+1])+2*(Close[x+y+2]-Open[x+y+2])+(Close[x+y+3]-Open[x+y+3]))/6;
return(pr);
}
double v2(int x,int y)
{
double pr;
pr=((High[x+y]-Low[x+y])+2*(High[x+y+1]-Low[x+y+1])+2*(High[x+y+2]-Low[x+y+2])+(High[x+y+3]-Low[x+y+3]))/6;
return(pr);
}
//+------------------------------------------------------------------+
Comments