This script is a specialized financial analysis tool designed to help traders visualize market momentum and volatility more clearly than a standard Relative Strength Index (RSI) alone. By combining traditional momentum tracking with dynamic statistical boundaries, it helps identify when price movements are becoming unusually aggressive or are potentially reaching an exhaustion point.
Core Functionality
The tool works by processing two distinct types of data simultaneously to create a multi-layered visual on your chart:
- Momentum Tracking: At its foundation, the script calculates a standard RSI. This measures the speed and change of price movements, telling you whether an asset is being bought or sold with significant force.
- Dynamic Volatility Bands: Unlike a standard RSI, which uses fixed horizontal levels (like 30 or 70), this tool wraps around the RSI line using "dynamic zones." These zones expand and contract automatically based on how much the market is fluctuating at any given moment.
How it Calculates the Zones
The script employs three specific mathematical steps to create these visual boundaries:
- Averaging: It looks at a specific window of past RSI values to establish a "Moving Average." This represents the "normal" momentum for the current period.
- Variance & Deviation: It calculates the statistical variance—essentially measuring how much the price is "wiggling" or deviating from that average.
- The Outer Limits: By taking that average and adding or subtracting a specific mathematical constant (multiplied by the deviation), the script draws an upper and lower boundary line.
Practical Application
Instead of looking at a static number, you are viewing a "channel" of momentum.
- When the RSI line stays within the orange boundaries, it suggests the market is moving in a relatively stable, expected fashion.
- When the RSI line pushes outside of these dynamic zones, it signals that the current price move is statistically significant and may be overextended, potentially indicating a future reversal or a period of high-intensity volatility.
In short, this script transforms a basic momentum indicator into a smart "envelope" that adjusts itself to the unique personality of whatever asset you are trading.
//+------------------------------------------------------------------+
//| Dynamic Zone RSI.mq4 |
//| Copyright © 2005, Pavel Kulko. |
//| polk@alba.dp.ua |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Pavel Kulko"
#property link "polk@alba.dp.ua"
#property indicator_buffers 3
#property indicator_color1 Lime
#property indicator_color2 SlateBlue
#property indicator_color3 Orange
#property indicator_separate_window
extern int RSIPeriod = 5;
extern int BandPeriod = 30;
double RSIBuf[],UpZone[],DnZone[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE);
SetIndexStyle(1,DRAW_LINE);
SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(0,RSIBuf);
SetIndexBuffer(1,UpZone);
SetIndexBuffer(2,DnZone);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
double MA, RSI[];
ArrayResize(RSI,BandPeriod);
int counted_bars=IndicatorCounted();
int limit = Bars-counted_bars-1;
for(int i=limit; i>=0; i--)
{
RSIBuf[i] = iRSI(NULL,0,RSIPeriod,MODE_CLOSE,i);
MA = 0;
for(int j=i; j<i+BandPeriod; j++) {
RSI[j-i] = RSIBuf[j];
MA += RSIBuf[j]/BandPeriod;
}
UpZone[i] = MA + (1.3185 * StDev(RSI,BandPeriod));
DnZone[i] = MA - (1.3185 * StDev(RSI,BandPeriod));
}
//----
return(0);
}
double StDev(double& Data[], int Per)
{
return(MathSqrt(Variance(Data,Per)));
}
double Variance(double& Data[], int Per)
{
double sum, ssum;
for (int i=0; i<Per; i++)
{
sum += Data[i];
ssum += MathPow(Data[i],2);
}
return((ssum*Per - sum*sum)/(Per*(Per-1)));
}
//+------------------------------------------------------------------+
Comments