The ATR Channels indicator is a technical analysis tool designed to provide traders with a visual representation of market trends and volatility. It works by creating a dynamic "envelope" around price action, helping users identify whether the current market movement is normal or potentially overextended.
Core Logic Overview
The indicator functions by calculating two primary mathematical components: a central trend line (Moving Average) and a measure of market volatility (ATR). By combining these two elements, it generates three distinct layers of "channels" that expand and contract based on how much the price is moving at any given moment.
Key Components
1. The Central Trend Line (The Anchor) At the heart of the indicator is a Weighted Moving Average. This line acts as the baseline for the entire visual setup. It smooths out the "noise" of minor price fluctuations to show the general direction of the market. Whether the trend is moving up, down, or sideways, this line serves as the pivot point from which all other calculations are made.
2. The Volatility Measurement (The Expansion) To determine how wide the channels should be, the script uses the Average True Range (ATR). This is a standard financial metric that measures how much an asset typically moves over a specific period. If the market becomes erratic and volatile, the ATR value increases; if the market becomes calm and stable, the ATR value decreases.
3. The Triple Channel System The indicator creates three separate pairs of upper and lower bands (channels) surrounding the central trend line. Each pair uses a different "Multiplication Factor" to create different levels of significance:
- Inner Channels: These are the closest to the moving average. They represent standard price deviations and help identify the immediate "trading zone."
- Middle Channels: These expand further out, providing a broader view of expected price movement.
- Outer Channels: These are the widest bands. They act as extreme boundaries, signaling that price action may be reaching an overbought or oversold state.
How it Works in Practice
Instead of having static lines that never change, these channels are "living" structures.
- During High Volatility: When the market experiences a sudden surge, the ATR value rises, causing all three sets of channels to widen automatically to accommodate the larger price swings.
- During Low Volatility: When the market settles down, the channels contract closer to the moving average.
By observing where the price sits in relation to these multiple layers of channels, traders can better visualize whether a move is a healthy part of a trend or if the price is pushing into "extreme" territory relative to its recent history.
//+------------------------------------------------------------------+
//| ATR Channels.mq4 |
//| Copyright © 2005, Luis Guilherme Damiani |
//| http://www.damianifx.com.br |
//+------------------------------------------------------------------+
#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[];
//---- input parameters
extern int PeriodsATR = 18;
extern int MA_Periods = 49;
extern int MA_type = MODE_LWMA;
extern double Mult_Factor1 = 1.6;
extern double Mult_Factor2 = 3.2;
extern double Mult_Factor3 = 4.8;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string mat;
//---7- indicators
// MA
SetIndexStyle(0, DRAW_LINE);
SetIndexBuffer(0, MA_Buffer0);
SetIndexDrawBegin(0, MathMax(PeriodsATR, MA_Periods));
// 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);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
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;
//----
for(int i = 0; i < limit; i++)
{
double atr = iATR(NULL, 0, PeriodsATR, i);
double ma = iMA(NULL, 0, MA_Periods, 0, MA_type, PRICE_TYPICAL, i);
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