i_DCG_ModStDev_v1
Download scriptThis specialized technical indicator is designed to analyze market volatility and momentum by processing the standard deviation of price movements. Instead of looking at price directly, it focuses on the "noise" or variance in the market to identify trends and potential exhaustion points.
Core Logic Overview
The tool operates through a multi-layered calculation process that filters raw market data into smoothed signals. Here is the step-by-step breakdown of how the logic flows:
1. Volatility Measurement (Standard Deviation) The script begins by calculating the Standard Deviation of the closing prices. This value represents how much the price is fluctuating relative to its average. By using a Linear Weighted Moving Average (LWMA) as the foundation, the tool gives more importance to recent price action while measuring these fluctuations.
2. Dual-Layer Smoothing Once the volatility (Standard Deviation) is captured, the script applies two different moving averages to that data:
- Short-term Smoothing: A primary average that reacts quickly to changes in volatility.
- Longer-term Smoothing: A secondary average calculated using a square root multiplier of the main period. This creates a broader, slower baseline of the market's "normal" behavior.
3. The Power Differential The core "Power" metric is derived by calculating the difference between these two smoothed averages. Essentially, it measures the gap between short-term volatility spikes and long-term historical stability. When this gap widens significantly, it indicates a surge in market strength; when it narrows, it suggests a return to equilibrium.
4. Final Signal Smoothing (The Trend Line) To ensure the final output is clean and usable for visual analysis, the "Power" value is passed through one final moving average calculation. This removes minor jitters and provides a smooth, continuous line that highlights the overarching trend of the market's momentum.
Visual Representation
The indicator outputs several components simultaneously:
- A Histogram: Provides a visual representation of the raw volatility power.
- Trend Lines: These represent the various stages of smoothing, allowing you to see not just the current "power" of the move, but how it relates to historical averages.
By combining these elements, the logic helps traders distinguish between actual momentum shifts and temporary market noise, providing a clearer picture of where price volatility is heading.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
/*+------------------------------------------------------------------+
| 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