3Color_RVI_Hist
Download scriptThis tool is designed to provide visual clarity regarding market momentum by transforming standard price data into a multi-colored histogram. Instead of just showing you where the price is, it focuses on the "vigor" or strength of the movement, helping to identify whether the current trend is gaining steam, losing power, or remaining stagnant.
How the Logic Works
The indicator operates through a three-step processing journey to filter out market noise and highlight significant shifts:
1. Calculating Relative Vigor First, the script looks at the price action of each individual candle. It measures the difference between the opening and closing prices (the actual movement) and compares it against the total range between the high and low points (the volatility). By dividing these two values, it creates a "Vigor" score. This tells the tool how much of the candle's total range was actually used to move in a specific direction.
2. Smoothing the Data Raw market data can be very erratic. To make the information readable, the script applies two layers of mathematical smoothing:
- Primary Smoothing: It takes the "Vigor" scores and calculates a Simple Moving Average. This removes minor fluctuations to show the underlying trend.
- Secondary Smoothing (The Signal): It then applies a second layer of averaging (a Linear Weighted Moving Average) to the first result. This creates a "Signal" line, which represents the smoothed momentum of the market.
3. Visualizing Momentum via Three Colors The final step is the visual logic that gives the indicator its name. The script compares the current signal value against the previous one to determine which color to display on your chart:
- Green (Upward Momentum): If the signal value is currently higher than it was in the previous period, the histogram turns green. This suggests that the buying pressure or upward momentum is increasing.
- Red (Downward Momentum): If the signal value is lower than it was in the previous period, the histogram turns red. This indicates that selling pressure or downward momentum is gaining strength.
- Purple (Neutral/Stagnant): If there is no change between the current and previous signal values, the histogram turns purple. This suggests a state of equilibrium or a "flat" market where momentum is neither increasing nor decreasing.
Summary for the User
By looking at this indicator, you aren't just seeing price movement; you are seeing the acceleration of that movement. The colors act as a quick reference guide: Green and Red show you where the momentum is accelerating, while Purple highlights areas where the market is potentially hesitating or moving sideways.
//+------------------------------------------------------------------+
//| 3Color_RVI_Hist.mq4 |
//| Copyright © 2005, Nikolay Kositsin. |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Nikolay Kositsin ."
#property link ""
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_level2 0.0
#property indicator_color1 Lime
#property indicator_color2 Red
#property indicator_color3 Purple
//---- input parameters
extern int RVIPeriod = 10;
extern int SignPeriod= 4;
extern int CountBars = 300;
//---- buffers
double ind_buffer1 [];
double ind_buffer2 [];
double ind_buffer3 [];
double RVIBuffer [];
double SignalBuffer[];
double TempBuffer [];
double RVI,UpRVI, DownRVI;
//-----------------------------
double value, Oldvalue, minuse;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
//---- indicator line
double Color1 = C'128,0,255';
SetIndexStyle(0,DRAW_HISTOGRAM, STYLE_SOLID, 3, Color1);
SetIndexStyle(1,DRAW_HISTOGRAM, STYLE_SOLID, 3);
SetIndexStyle(2,DRAW_HISTOGRAM, STYLE_SOLID, 3);
SetIndexDrawBegin(0,Bars-CountBars);
SetIndexDrawBegin(1,Bars-CountBars);
SetIndexDrawBegin(2,Bars-CountBars);
//---- 6 additional buffers are used for counting.
IndicatorBuffers(6);
SetIndexBuffer(0, ind_buffer1 );
SetIndexBuffer(1, ind_buffer2 );
SetIndexBuffer(2, ind_buffer3 );
SetIndexBuffer(3, TempBuffer );
SetIndexBuffer(4, RVIBuffer );
SetIndexBuffer(5, SignalBuffer);
//---- name for DataWindow and indicator subwindow label
short_name="RVI("+RVIPeriod+")";
IndicatorShortName(short_name);
SetIndexLabel(0,"RVI_UP");
SetIndexLabel(1,"RVI_DOWN");
SetIndexLabel(2,"RVI_Stright");
//----
SetIndexEmptyValue(0,0);
SetIndexEmptyValue(1,0);
SetIndexEmptyValue(2,0);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Relative Vigor Index |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
//---- check for possible errors
if(counted_bars<0) return(-1);
if(Bars<=RVIPeriod) return(0);
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//--------RVI_Hist-----------------------------------------------------------------------------------------------------=
for(int i=0; i<limit; i++) { UpRVI=Close[i]-Open[i]; DownRVI=High[i]-Low[i]; RVI=UpRVI/DownRVI; TempBuffer[i]= RVI; }
for(int k=0; k<limit; k++) RVIBuffer [k]=iMAOnArray(TempBuffer, Bars, RVIPeriod, 0,MODE_SMA, k);
for( k=0; k<limit; k++) SignalBuffer[k]=iMAOnArray(RVIBuffer , Bars,SignPeriod, 0,MODE_LWMA, k);
//---- 3 Color---------------------------------------------------------------------------------------------------------+
for( k=0; k<limit; k++)
{
ind_buffer1[k]=0.0; ind_buffer2[k]=0.0; ind_buffer3[k]= 0.0;
Oldvalue=SignalBuffer[k+1]; value= SignalBuffer[k]; minuse = value - Oldvalue;
if(minuse>0.0)ind_buffer1[k]= value; else {if(minuse<0.0) ind_buffer2[k]= value; else ind_buffer3[k]= value;}
}
//--------------------------------------------------------------------------------------------------------------------+
return(0);
}
//+---------------------------------------------------------------------------------------+
Comments