ATR_Channels_VarTFs_mtf
Download scriptThis script is a visual trading tool designed to map out market volatility and trend direction on a price chart. It functions by combining two primary technical analysis concepts: Moving Averages (which show the trend) and Average True Range (ATR, which measures how much a price typically moves).
Core Logic Overview
The indicator creates a dynamic "envelope" or "channel" system around a central trend line. Instead of just showing where the price is going, it visualizes how far the price is likely to swing based on recent market history.
How the Visualization Works
The script draws seven distinct lines on your chart:
-
The Central Trend Line: At the heart of the indicator is a Moving Average. This acts as the baseline, smoothing out "market noise" to help you see the primary direction of the price (upward, downward, or sideways).
-
The Triple Channel System: The script generates three distinct pairs of "bands" (upper and lower boundaries) radiating from that central trend line. These are calculated by taking the current trend value and adding or subtracting a volatility multiplier:
- Channel 1 (Narrow): Uses a smaller multiplier to show immediate, tight volatility boundaries.
- Channel 2 (Medium): Provides a balanced view of standard market swings.
- Channel 3 (Wide): Uses a larger multiplier to identify extreme price deviations or "overextended" moves.
Multi-Timeframe Integration
A sophisticated feature of this script is its ability to look at multiple timeframes simultaneously. It can pull volatility data from one timeframe (e.g., Daily) and apply it to the chart you are currently viewing (e.g., Hourly).
By doing this, the indicator allows a trader to see how "big" the market moves on a macro scale while staying focused on the micro-movements of the current price action. This helps in identifying if a current price move is significant relative to the broader market history.
Summary for the User
Essentially, this tool acts as a "volatility map." The central line tells you the direction, while the three sets of colored bands provide a visual guide of the expected "territory" the price might cover. When the price stays within these bands, it is behaving normally; when it pushes toward or outside the outer red bands, it signals that the market is experiencing significantly higher-than-average volatility.
//+------------------------------------------------------------------+
//| ATR Channels.mq4 |
//| Copyright © 2005, Luis Guilherme Damiani |
//| http://www.damianifx.com.br |
//+------------------------------------------------------------------+
// ATR_Channels_VarTFs_mtf.mq4 //TimeFrame=0; ATR_TimeFrame=1440;
//mtf2009fxtsd ki
#property copyright "Copyright © 2005, Luis Guilherme Damiani"
#property link "http://www.damianifx.com.br"
#property indicator_chart_window
#property indicator_buffers 7
#property indicator_color1 Green //Moving Average
#property indicator_color2 DeepSkyBlue // Lower band 1
#property indicator_color3 DeepSkyBlue // Upper band 1
#property indicator_color4 Blue // Lower band 2
#property indicator_color5 Blue // Upper band 2
#property indicator_color6 Red // Lower band 3
#property indicator_color7 Red // Upper band 3
//---- indicator buffers
double MA_Buffer0[];
double Ch1up_Buffer1[];
double Ch1dn_Buffer2[];
double Ch2up_Buffer3[];
double Ch2dn_Buffer4[];
double Ch3up_Buffer5[];
double Ch3dn_Buffer6[];
double ATR_Buffer[];
//---- input parameters
extern int PeriodsATR = 18;
extern int MA_Periods = 49;
extern int MA_type = MODE_EMA;
extern int MA_Price = 0;
extern int MA_shift = 0;
extern int MA_x_shift= 0;
extern int TimeFrame=0;
extern int ATR_TimeFrame=1440;
extern double Mult_Factor1 = 0.618;
extern double Mult_Factor2 = 1.0;
extern double Mult_Factor3 = 1.5;
extern string note_Price = "0C 1O 2H 3L 4Md 5Tp 6WghC: Md(HL/2)4,Tp(HLC/3)5,Wgh(HLCC/4)6";
extern string MA_Method_ = "SMA0 EMA1 SMMA2 LWMA3";
extern string TimeFrames = "M1;5,15,30,60H1;240H4;1440D1;10080W1;43200MN";
//double ma[], atr[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string mat;
//---7- indicators
IndicatorBuffers (8);
SetIndexStyle(0, DRAW_LINE);
SetIndexBuffer(0, MA_Buffer0);
SetIndexDrawBegin(0, MathMax(PeriodsATR, MA_Periods));
string sATRc = StringConcatenate("ATRchannel MA( ",MA_Periods,") ATR ", PeriodsATR, ") [",TimeFrame,"] ");
SetIndexLabel(0, sATRc);
// ATR 1 up
SetIndexStyle(1, DRAW_LINE);
SetIndexBuffer(1, Ch1up_Buffer1);
SetIndexDrawBegin(1, MathMax(PeriodsATR, MA_Periods));
string sATRu1 = StringConcatenate("ATRu(", PeriodsATR, ", ", Mult_Factor1, ")");
SetIndexLabel(1, sATRu1);
// ATR 1 down
SetIndexStyle(2, DRAW_LINE);
SetIndexBuffer(2, Ch1dn_Buffer2);
SetIndexDrawBegin(2, MathMax(PeriodsATR, MA_Periods));
string sATRd1 = StringConcatenate("ATRd(", PeriodsATR, ", ", Mult_Factor1, ")");
SetIndexLabel(2, sATRd1);
// ATR 2 up
SetIndexStyle(3, DRAW_LINE);
SetIndexBuffer(3, Ch2up_Buffer3);
SetIndexDrawBegin(3, MathMax(PeriodsATR, MA_Periods));
string sATRu2 = StringConcatenate("ATRu(", PeriodsATR, ", ", Mult_Factor2, ")");
SetIndexLabel(3, sATRu2);
// ATR 2 down
SetIndexStyle(4, DRAW_LINE);
SetIndexBuffer(4, Ch2dn_Buffer4);
SetIndexDrawBegin(4, MathMax(PeriodsATR, MA_Periods));
string sATRd2 = StringConcatenate("ATRd(", PeriodsATR, ", ", Mult_Factor2, ")");
SetIndexLabel(4, sATRd2);
// ATR 3 up
SetIndexStyle(5, DRAW_LINE);
SetIndexBuffer(5, Ch3up_Buffer5);
SetIndexDrawBegin(5, MathMax(PeriodsATR, MA_Periods));
string sATRu3 = StringConcatenate("ATRu(", PeriodsATR, ", ", Mult_Factor3, ")");
SetIndexLabel(5, sATRu3);
// ATR 3 down
SetIndexStyle(6, DRAW_LINE);
SetIndexBuffer(6, Ch3dn_Buffer6);
SetIndexDrawBegin(6, MathMax(PeriodsATR, MA_Periods));
string sATRd3 = StringConcatenate("ATRd(", PeriodsATR, ", ", Mult_Factor3, ")");
SetIndexLabel(6, sATRd3);
SetIndexBuffer(7, ATR_Buffer);
ATR_TimeFrame =MathMax(ATR_TimeFrame, Period());
TimeFrame =MathMax(TimeFrame, Period());
SetIndexShift(0,MA_shift+ MA_x_shift*TimeFrame/Period());
SetIndexShift(1,MA_shift+ MA_x_shift*TimeFrame/Period());
SetIndexShift(2,MA_shift+ MA_x_shift*TimeFrame/Period());
SetIndexShift(3,MA_shift+ MA_x_shift*TimeFrame/Period());
SetIndexShift(4,MA_shift+ MA_x_shift*TimeFrame/Period());
SetIndexShift(5,MA_shift+ MA_x_shift*TimeFrame/Period());
SetIndexShift(6,MA_shift+ MA_x_shift*TimeFrame/Period());
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
datetime TimeArray[]; datetime TimeArray1[];
ArrayCopySeries(TimeArray1 ,MODE_TIME ,NULL,ATR_TimeFrame);
ArrayCopySeries(TimeArray ,MODE_TIME ,NULL,TimeFrame);
int i,y,y1;
// if(Bars <= MathMax(PeriodsATR, MA_Periods))
// return(0);
int fixed_bars = IndicatorCounted();
//---- check for possible errors
if(fixed_bars < 0) return(-1);
//---- last counted bar will be recounted
if(fixed_bars > 0) fixed_bars--;
int limit = Bars - fixed_bars;
limit = MathMax (limit,TimeFrame/Period());
limit = MathMax (limit,ATR_TimeFrame/Period());
//----
for( i = 0, y=0, y1=0; i < limit; i++)
{
if (Time[i]<TimeArray[y]) y++;
if (Time[i]<TimeArray1[y1]) y1++;
double atr = iATR(NULL, ATR_TimeFrame, PeriodsATR, y1);
double ma = iMA(NULL, TimeFrame, MA_Periods, 0, MA_type, MA_Price, y);
MA_Buffer0[i] = ma;
Ch1up_Buffer1[i] = ma + atr*Mult_Factor1;
Ch1dn_Buffer2[i] = ma - atr*Mult_Factor1;
Ch2up_Buffer3[i] = ma+ atr*Mult_Factor2;
Ch2dn_Buffer4[i] = ma - atr*Mult_Factor2;
Ch3up_Buffer5[i] = ma + atr*Mult_Factor3;
Ch3dn_Buffer6[i] = ma - atr*Mult_Factor3;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments