This custom indicator is designed to analyze market volatility by comparing short-term price movements against long-term historical averages. Instead of looking at raw price data, it focuses on the "range" or "movement intensity" of the market to provide a smoother signal for traders.
Core Logic and Functionality
The script operates using a two-step mathematical process to identify trends in market volatility:
1. Volatility Ratio Calculation The indicator first calculates the average range of price movements over two different timeframes: a "fast" period (short-term) and a "slow" period (long-term). It then divides the short-term volatility by the long-term volatility.
- When this ratio is high, it suggests that current market activity is significantly more intense than usual.
- When the ratio is low, it indicates that the market is relatively calm or consolidating compared to its historical average.
2. Signal Smoothing Because raw volatility data can often be "noisy" or jump around erratically, the indicator applies a secondary smoothing layer. It takes the results from the first step and runs them through a Moving Average (specifically a Smoothed Moving Average). This filters out minor fluctuations and highlights the broader trend of the volatility.
Visual Representation
The tool displays two distinct lines in a separate window beneath your main price chart:
- ATR Signal: This represents the raw ratio between short-term and long-term volatility.
- MA (Moving Average): This acts as the primary smoothed trendline. By observing how the ATR Signal interacts with this smoothed line, traders can better identify shifts in market momentum.
Summary for Traders
Essentially, this tool helps you see "how much" the market is moving relative to its own history. By smoothing that information out, it aims to provide a clearer picture of whether the current market environment is expanding or contracting, helping to filter out the "noise" of standard price action.
//+------------------------------------------------------------------+
//| Gideons_ATR.mq4 |
//| Copyright © 2007, GideonSmolders@gmail.com |
//| MetaTrader Group Yahoo |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, GideonSmolders"
#property link ""
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Silver
#property indicator_color2 Red
//---- indicator parameters
extern int atr_fast=5;
extern int atr_slow=48;
//---- indicator buffers
double ind_buffer1[];
double ind_buffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- drawing settings
SetIndexStyle(0,DRAW_LINE);
SetIndexStyle(1,DRAW_LINE);
SetIndexDrawBegin(0,atr_slow);
SetIndexDrawBegin(1,atr_slow);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1);
//---- indicator buffers mapping
if(!SetIndexBuffer(0,ind_buffer1) && !SetIndexBuffer(1,ind_buffer2))
Print("cannot set indicator buffers!");
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("Gideons ATR("+atr_fast+","+atr_slow+")");
SetIndexLabel(0,"ATR_Signal");
SetIndexLabel(1,"MA");
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//---- atr signal counted in the 1-st buffer
for(int i=0; i<limit; i++)
ind_buffer1[i]= iATR(NULL,0,atr_fast,i)/iATR(NULL,0,atr_slow,i);
//---- ma line counted in the 2-nd buffer
for(i=0; i<limit; i++)
ind_buffer2[i]=iMAOnArray(ind_buffer1,0,7,0,MODE_SMMA,i);
//---- done
return(0);
}
//+------------------------------------------------------------------+
Comments