HVR test
Download scriptOverview
The Historical Volatility Ratio (HVR) is a specialized technical analysis tool designed to measure and visualize the relative intensity of market price fluctuations over two different time horizons. By comparing short-term "noise" or activity against long-term trends, it helps traders identify whether the current market environment is experiencing an unusual spike in activity or a period of relative calm.
Core Logic and Functionality
The indicator operates by calculating the "Standard Deviation" of price movements—a common statistical measure used to determine how much a price varies from its average. The logic follows these specific steps:
- Dual-Horizon Tracking: The script simultaneously monitors two different windows of time: a short-term period (set to 6 units) and a long-term period (set to 100 units).
- Volatility Measurement: It calculates the volatility for both of these periods independently using an Exponential Moving Average, which gives more weight to recent price actions.
- The Ratio Calculation: Instead of showing you just the raw volatility of one period, the script divides the short-term volatility by the long-term volatility. This produces a "Ratio."
How to Interpret the Results
The resulting line on your chart represents the relationship between immediate market behavior and historical context:
- High Ratio Values: When the ratio is high, it indicates that price swings are currently much more aggressive than they have been over the long term. This often signals a period of high emotion, rapid news reactions, or a significant breakout.
- Low Ratio Values: When the ratio is low, it suggests that current price movements are stable and consistent with historical norms. This typically represents a "quiet" market where volatility is compressed.
By visualizing this relationship as a single line, the tool allows you to see at a glance whether the current market energy is "overheated" compared to its own history or if it is operating within a standard range of activity.
//+------------------------------------------------------------------+
//| Historical Volatility ratio indicator |
//| HVR.mq4 |
//| mladen |
//+------------------------------------------------------------------+
#property copyright "mladen"
#property link ""
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
#property indicator_minimum 0
//
//
//
//
//
extern int ShortPeriod = 6;
extern int LongPeriod = 100;
extern int AverageMethod = 0;
//
//
//
//
//
double HvrValue[];
double LogValue[];
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(2);
SetIndexBuffer(0,HvrValue);
SetIndexBuffer(1,LogValue);
//
//
//
//
//
IndicatorShortName("HVR ("+ShortPeriod+","+LongPeriod+")");
return(0);
}
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
double dev;
double Short;
double Long;
int counted_bars=IndicatorCounted();
int limit,i,k;
if(counted_bars < 0) return(-1);
limit = Bars-counted_bars;
//
//
//
//
//
for (i = limit; i>=0; i--) {
Short=iStdDev(NULL,0, 60,0, MODE_EMA, PRICE_CLOSE,i);
Long=iStdDev(NULL,0, 100,0, MODE_EMA, PRICE_CLOSE,i);
HvrValue[i]=Short/Long;
LogValue[i]=HvrValue[i];
}
return(0);
}
Comments