ATR_x3LHist_mtf
Download scriptThis tool is a specialized technical indicator designed to help traders visualize and measure market volatility over different time horizons. It focuses on the "Average True Range" (ATR), which is a standard measure of how much an asset's price typically moves in a given period.
Core Functionality
The primary logic of this script is to calculate three distinct layers of volatility simultaneously. Instead of looking at just one average, it provides three different perspectives based on the user-defined periods:
- Short-Term Volatility: Tracks immediate, rapid price fluctuations.
- Medium-Term Volatility: Identifies moderate price movements.
- Long-Term Volatility: Reveals broader market trends and sustained swings.
Multi-Timeframe Integration
One of the most significant features of this script is its ability to "bridge" timeframes. It allows you to view volatility data from a different timeframe than the one currently visible on your chart. For example, while you are looking at a 1-minute chart, the indicator can calculate and display volatility data for hourly, daily, or even weekly scales.
Visual Representation
To make this information easy to interpret, the script renders these three data sets differently on a separate window below your main price chart:
- Dynamic Labeling: The tool automatically identifies which timeframe it is calculating (e.g., M5, H1, D1) and displays this clearly in the indicator's title.
- Distinct Visual Styles: It uses different visual formats—specifically a combination of lines and histograms—allowing you to distinguish between the three volatility periods at a glance.
- Automatic Adjustments: The script intelligently calculates the starting point for each data line based on its specific period, ensuring that the information displayed is accurate and relevant to the historical data available.
Practical Application
For a trader, this logic provides a clearer picture of "market noise" versus actual movement. By comparing the three different ATR values, you can see if current price action is unusually wild compared to the long-term average or if the market is becoming calmer than usual. It serves as a comprehensive volatility dashboard, consolidating multiple timeframes into one view.
//+------------------------------------------------------------------+
//| ATR.mq4 |
//| Copyright © 2005, MetaQuotes Software Corp. |
//|atr x2 http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
//2008fxtsd mtf keris f-la
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Maroon
#property indicator_color2 DeepSkyBlue
#property indicator_color3 RoyalBlue
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 1
#property indicator_level1 0.001
#property indicator_levelcolor SlateGray
//---- input parameters
extern int AtrPeriod1=2;
extern int AtrPeriod2=9;
extern int AtrPeriod3=14;
extern int TimeFrame=0;
extern string TimeFrames = "M1;5,15,30,60H1;240H4;1440D1;10080W1;43200MN";
//---- buffers
double AtrBuffer1[];
double AtrBuffer2[];
double AtrBuffer3[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
// IndicatorBuffers(3);
//---- indicator line
SetIndexStyle (2,DRAW_HISTOGRAM);
SetIndexStyle (1,DRAW_LINE);
SetIndexStyle (0,DRAW_LINE);
SetIndexBuffer(2,AtrBuffer1);
SetIndexBuffer(1,AtrBuffer2);
SetIndexBuffer(0,AtrBuffer3);
//---- name for DataWindow and indicator subwindow label
TimeFrame = MathMax (TimeFrame,Period());
switch(TimeFrame)
{
case 1 : string TimeFrameStr="M1"; break;
case 5 : TimeFrameStr="M5"; break;
case 15 : TimeFrameStr="M15"; break;
case 30 : TimeFrameStr="M30"; break;
case 60 : TimeFrameStr="H1"; break;
case 240 : TimeFrameStr="H4"; break;
case 1440 : TimeFrameStr="D1"; break;
case 10080 : TimeFrameStr="W1"; break;
case 43200 : TimeFrameStr="MN"; break;
default : TimeFrameStr="TF0";
}
string short_name;
short_name="ATR_("+AtrPeriod1+","+AtrPeriod2+","+AtrPeriod3+") ["+TimeFrameStr+"] ";
IndicatorShortName(short_name);
SetIndexLabel(0,"ATR3 "+short_name);
SetIndexLabel(1,"ATR2 "+short_name);
SetIndexLabel(2,"ATR1 "+short_name);
SetIndexDrawBegin(0,AtrPeriod3);
SetIndexDrawBegin(1,AtrPeriod2);
SetIndexDrawBegin(2,AtrPeriod1);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Average True Range |
//+------------------------------------------------------------------+
int start()
{
datetime TimeArray[];
int i,shift,limit,y,counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),TimeFrame);
limit=Bars-counted_bars;
limit = MathMax (limit,TimeFrame/Period());
for(i=0,y=0;i<limit;i++)
{
if (Time[i]<TimeArray[y]) y++;
AtrBuffer1[i]=iATR(NULL,TimeFrame,AtrPeriod1,y) ;
AtrBuffer2[i]=iATR(NULL,TimeFrame,AtrPeriod2,y);
AtrBuffer3[i]=iATR(NULL,TimeFrame,AtrPeriod3,y);
}
return(0);
}
//+---
Comments