R_Volatility_I
Download scriptThis tool is designed to provide a visual representation of market momentum and volatility, helping traders understand the balance between upward and downward price movements. By appearing in a separate window below your main trading chart, it translates complex price fluctuations into a readable numerical scale (typically ranging between 20 and 80).
How the Logic Works
The script functions by analyzing historical price data over a specific timeframe—which you can customize—to determine the "strength" of the current trend. Here is the step-by-step logic it follows:
- Data Collection: The tool looks at the highest and lowest prices reached during each candle within your chosen period. Instead of just looking at the closing price, it evaluates the extremes of the market movement.
- Volatility Measurement: It calculates the standard deviation for both the "highs" and the "lows." In simple terms, it measures how wildly the price is swinging in an upward direction versus a downward direction.
- Momentum Calculation: By comparing these two sets of data, the script determines the relative strength. If the upward movements are significantly more volatile than the downward ones, the indicator moves higher on the scale; conversely, if downward pressure dominates, it moves lower.
- Visual Output: The final result is plotted as a continuous line. This allows you to see the "pulse" of the market at a glance. It helps identify whether the market is becoming overextended in one direction or if there is a balanced equilibrium between buyers and sellers.
Key Features for the User
- Customizable Sensitivity: You can adjust the period settings to make the indicator more responsive to short-term "noise" or more smoothed out to highlight long-term trends.
- Visual Clarity: The indicator is designed to be clean and easy to read, using a distinct color to help you quickly identify shifts in market sentiment without cluttering your primary price chart.
//+------------------------------------------------------------------+
//| RSI.mq4 |
//| Copyright © 2004, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
#property indicator_separate_window
#property indicator_minimum 20
#property indicator_maximum 80
#property indicator_buffers 1
#property indicator_color1 DodgerBlue
//---- input parameters
extern int RVIPeriod=10;
//---- buffers
double RSIBuffer[];
double PosBuffer[];
double NegBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
//---- 2 additional buffers are used for counting.
IndicatorBuffers(3);
SetIndexBuffer(1,PosBuffer);
SetIndexBuffer(2,NegBuffer);
//---- indicator line
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,RSIBuffer);
//---- name for DataWindow and indicator subwindow label
short_name="R_Volatility_I("+RVIPeriod+")";
IndicatorShortName(short_name);
SetIndexLabel(0,short_name);
//----
SetIndexDrawBegin(0,RVIPeriod);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Relative Strength Index |
//+------------------------------------------------------------------+
int start()
{
int i,counted_bars=IndicatorCounted();
double rel,negative,positive;
//----
if(Bars<=RVIPeriod) return(0);
//---- initial zero
if(counted_bars<1)
for(i=1;i<=RVIPeriod;i++) RSIBuffer[Bars-i]=0.0;
//----
i=Bars-RVIPeriod-1;
if(counted_bars>=RVIPeriod) i=Bars-counted_bars-1;
while(i>=0)
{
positive=iStdDev(NULL,0,RVIPeriod,0,MODE_EMA,PRICE_HIGH,i);
negative=iStdDev(NULL,0,RVIPeriod,0,MODE_EMA,PRICE_LOW,i);
RSIBuffer[i]=100.0-100.0/(1+positive/negative);
i--;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments