This tool is designed to analyze market volatility and momentum by processing price data through several layers of mathematical smoothing. Instead of looking at raw price movements alone, it focuses on the "behavior" of price fluctuations to help identify trends and potential energy shifts in the market.
How the Logic Works
The script operates by performing a multi-step calculation that transforms raw price data into visual signals:
1. Measuring Volatility (Standard Deviation) The foundation of this indicator is the calculation of "Standard Deviation." This measures how much the price is deviating from its recent average. By using a specific weighted moving average, the tool ensures that more recent price actions carry more significance than older data.
2. Establishing Smoothing Layers Once the volatility is measured, the script doesn't just show you that raw number (which can be jumpy). It applies two different layers of smoothing to these measurements:
- The Primary Smooth: A standard weighted average is applied to stabilize the volatility data.
- The Secondary Smooth: A longer-term, mathematically derived average (based on a square root calculation) is used to establish a broader baseline of market behavior.
3. Calculating Market "Power" The core logic then calculates the difference between these two smoothing layers. By subtracting the long-term average from the primary smooth, the tool isolates the "Power"—essentially showing whether current volatility is expanding or contracting relative to its historical norm.
4. Trend Confirmation Finally, the indicator applies a third layer of smoothing to this "Power" value. This helps filter out minor market noise, providing a clearer visual representation of the underlying momentum.
Visual Output
The resulting data is presented in your trading window using different visual formats:
- Histogram: Provides a quick look at the immediate "Power" or strength of the current price movement.
- Lines: These represent the various smoothed averages, allowing you to see the relationship between short-term fluctuations and long-term trends.
In summary, this script takes complex price volatility, smooths it out multiple times to remove "noise," and calculates the difference between short-term and long-term behaviors to reveal the hidden momentum of the market.
//+------------------------------------------------------------------+
//| |
//| FileName: i_DCG_ModStDev.mq4 |
//| Author: Copyright © 2005, Fermin Da Costa Gomez |
//| Description: This indicator measures |
//| |
//| Version: 000 20050728 14:52 GMT |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Fermin Da Costa Gomez"
#property link "http://forex.viahetweb.nl"
//----
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Silver
#property indicator_color2 Red
#property indicator_color3 Lime
#property indicator_color4 SkyBlue
//---- External parameters
extern int _maPeriod=12;
//---- indicator buffers
double _sd[];
double _sdMa[];
double _sdMa2[];
double _sdPower[];
double _sdPowerMa[];
//----
int ExtCountedBars=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
int draw_begin;
string short_name;
IndicatorBuffers(5);
//---- indicator buffers mapping
SetIndexBuffer(0, _sdPower);
SetIndexEmptyValue(0, 0.0);
SetIndexStyle(0, DRAW_HISTOGRAM);
SetIndexBuffer(1, _sdPowerMa);
SetIndexEmptyValue(1, 0.0);
SetIndexStyle(1, DRAW_LINE);
SetIndexBuffer(3, _sd);
SetIndexEmptyValue(3, 0.0);
SetIndexStyle(3, DRAW_LINE);
SetIndexBuffer(4, _sdMa);
SetIndexEmptyValue(4, 0.0);
SetIndexStyle(4, DRAW_LINE);
SetIndexBuffer(2, _sdMa2);
SetIndexEmptyValue(2, 0.0);
SetIndexStyle(2, DRAW_LINE);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| CalculateIndicators |
//+------------------------------------------------------------------+
void calculateIndicators(int i)
{
double m10, m11, m20, m21;
int fastPeriod=_maPeriod*0.382;
_sd[i]=iStdDev(Symbol(), 0, _maPeriod, MODE_LWMA, 0, PRICE_CLOSE, i);
_sdMa[i]=iMAOnArray(_sd, 0, _maPeriod, 0, MODE_LWMA, i);
_sdMa2[i]=iMAOnArray(_sd, 0, _maPeriod*MathSqrt(_maPeriod), 0, MODE_LWMA, i);
_sdPower[i]= _sdMa[i]-_sdMa2[i];
_sdPowerMa[i]=iMAOnArray(_sdPower, 0, _maPeriod*1.618, 0, MODE_LWMA, i);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
int i, shift, counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
int limit=Bars-counted_bars;
//----
if(counted_bars>0) limit++;
//---- moving average
for(i=limit; i>=0; i--)
{
//calculateIndicators(i);
double m10, m11, m20, m21;
int fastPeriod=_maPeriod*0.382;
_sd[i]=iStdDev(Symbol(), 0, _maPeriod, MODE_LWMA, 0, PRICE_CLOSE, i);
_sdMa[i]=iMAOnArray(_sd, 0, _maPeriod, 0, MODE_LWMA, i);
_sdMa2[i]=iMAOnArray(_sd, 0, _maPeriod*MathSqrt(_maPeriod), 0, MODE_LWMA, i);
_sdPower[i]= _sdMa[i]-_sdMa2[i];
_sdPowerMa[i]=iMAOnArray(_sdPower, 0, _maPeriod*1.618, 0, MODE_LWMA, i);
}
return(0);
}
//+------------------------------------------------------------------+
Comments