StochasticRVI
Download scriptThis indicator is designed to provide traders with a sophisticated way to measure market momentum and price activity by combining two distinct mathematical concepts: the Relative Volatility Index (RVI) and Stochastic oscillators.
Core Analytical Logic
The script operates through a multi-layered calculation process to smooth out market "noise" and identify underlying trends:
1. Volatility and Price Action Weighting The logic begins by examining the relationship between price movement (the difference between opening and closing prices) and the range of price volatility (the distance between highs and lows). Instead of looking at a single candle in isolation, it applies a weighted average over four consecutive periods. This ensures that the data reflects recent trends while giving significant importance to the most immediate price actions.
2. The RVI Component By dividing the weighted price movement by the weighted volatility range, the script generates the Relative Volatility Index (RVI). This step effectively normalizes the data, allowing traders to see the strength of a move relative to how much the price is swinging. It helps distinguish between a "strong" move and a "noisy" move.
3. Stochastic Normalization
Once the RVI value is established, the script applies a Stochastic filter. This looks at the highest and lowest RVI values over a specific user-defined period (the Length2 parameter). It calculates where the current RVI sits within that historical range. This creates a percentage-like value that helps identify whether the current momentum is overextended or处于 equilibrium.
4. Smoothing and Final Output To prevent the indicator from jumping erratically, the script applies a final smoothing calculation (a weighted moving average) to the Stochastic result. This produces the primary "Stochastic RVI" line.
5. The Trigger Line Finally, the script calculates a "Trigger" line based on a percentage of the smoothed data. This serves as a secondary reference point; when the main line interacts with this trigger, it can help traders identify potential turning points or shifts in momentum.
Summary for the Trader
In simple terms, this tool filters out minor price fluctuations to show you the "true" strength of a trend. It combines how much the price is moving (Momentum) with how much it is swinging (Volatility), then smooths that data into two lines that help identify when a trend is becoming exhausted or gaining significant strength.
//+------------------------------------------------------------------+
//| StochasticRVI.mq4 |
//| |
//| Stochastic RVI |
//| |
//| Algorithm taken from book |
//| "Cybernetics Analysis for Stock and Futures" |
//| by John F. Ehlers |
//| |
//| contact@mqlsoft.com |
//| http://www.mqlsoft.com/ |
//+------------------------------------------------------------------+
#property copyright "Coded by Witold Wozniak"
#property link "www.mqlsoft.com"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_level1 0
#property indicator_minimum -1
#property indicator_maximum 1
double StocRVI[];
double Trigger[];
double RVI[];
double Value1[];
double Value2[];
double Value3[];
extern int Length2 = 8;
int buffers = 0;
int drawBegin = 0;
int init() {
drawBegin = Length2;
initBuffer(StocRVI, "Stochastic RVI", DRAW_LINE);
initBuffer(Trigger, "Trigger", DRAW_LINE);
initBuffer(RVI);
initBuffer(Value1);
initBuffer(Value2);
initBuffer(Value3);
IndicatorBuffers(buffers);
IndicatorShortName("Stochastic RVI [" + Length2 + "]");
return (0);
}
int start() {
if (Bars <= drawBegin) return (0);
int countedBars = IndicatorCounted();
if (countedBars < 0) return (-1);
if (countedBars > 0) countedBars--;
int s, limit = Bars - countedBars - 1;
for (s = limit; s >= 0; s--) {
Value1[s] = ((Close[s] - Open[s]) +
2.0 * (Close[s + 1] - Open[s + 1]) +
2.0 * (Close[s + 2] - Open[s + 2]) +
(Close[s + 3] - Open[s + 3])) / 6.0;
Value2[s] = ((High[s] - Low[s]) +
2.0 * (High[s + 1] - Low[s + 1]) +
2.0 * (High[s + 2] - Low[s + 2]) +
(High[s + 3] - Low[s + 3])) / 6.0;
double Num = 0.0;
double Denom = 0.0;
for (int count = 0; count < Length2; count++) {
Num += Value1[s + count];
Denom += Value2[s + count];
}
if (Denom != 0.0) {
RVI[s] = Num / Denom;
} else {
RVI[s] = 0.0;
}
double rvi = RVI[s];
double hh = rvi, ll = rvi;
for (int i = 0; i < Length2; i++) {
double tmp = RVI[s + i];
hh = MathMax(hh, tmp);
ll = MathMin(ll, tmp);
}
Value3[s] = 0.0;
if (hh != ll) {
Value3[s] = (rvi - ll) / (hh - ll);
}
StocRVI[s] = (4.0 * Value3[s] + 3.0 * Value3[s + 1] + 2.0 * Value3[s + 2] + Value3[s + 3]) / 10.0;
StocRVI[s] = 2.0 * (StocRVI[s] - 0.5);
Trigger[s] = 0.96 * (StocRVI[s + 1] + 0.02);
}
return (0);
}
void initBuffer(double array[], string label = "", int type = DRAW_NONE, int arrow = 0, int style = EMPTY, int width = EMPTY, color clr = CLR_NONE) {
SetIndexBuffer(buffers, array);
SetIndexLabel(buffers, label);
SetIndexEmptyValue(buffers, EMPTY_VALUE);
SetIndexDrawBegin(buffers, drawBegin);
SetIndexShift(buffers, 0);
SetIndexStyle(buffers, type, style, width);
SetIndexArrow(buffers, arrow);
buffers++;
}
Comments