MTF_ATR Channels

Download script
Author: Copyright � 2005, Luis Guilherme Damiani
MTF_ATR Channels

Overview of the MTF ATR Channels Indicator

The MTF ATR Channels is a sophisticated technical analysis tool designed to help traders visualize market volatility and price trends across different timeframes simultaneously. It combines moving averages with Average True Range (ATR) channels to create a multi-layered "envelope" system that identifies potential overextended prices and helps smooth out market noise.

Core Functionalities

1. Multi-Timeframe (MTF) Integration

One of the primary features of this script is its ability to project data from higher timeframes onto your current chart. For example, if you are viewing a 15-minute chart, you can set the indicator to display data from the 4-hour or Daily charts. This allows you to stay aware of the "big picture" trends without constantly switching tabs.

2. The Central Moving Average

At the heart of the indicator is a core moving average line. This serves as the primary trend baseline. It helps identify the general direction of the market (bullish or bearish) by providing a smoothed representation of price action over a specific period.

3. Three-Tiered ATR Channels

The script generates three distinct sets of "channels" (upper and lower bands) surrounding the central moving average. These are calculated based on the Average True Range, which measures how much an asset typically moves in a given time period.

  • Channel 1 (Narrow): Closely tracks the price to identify immediate volatility.
  • Channel 2 (Medium): Provides a broader scope for standard market fluctuations.
  • Channel 3 (Wide): Represents extreme price movements.

By having three different tiers, the indicator allows traders to see not just where the price is currently moving, but also how far it has strayed from the "norm." When the price pushes toward or outside these outer bands, it often signals that the market may be overbought or oversold.

Visual Logic and Behavior

The script is designed to be highly organized and readable:

  • Color Coding: Different colors are assigned to each set of channels, making it easy to distinguish between short-term volatility and long-term extremes at a glance.
  • Buffer Smoothing: The logic includes a specific "Refresh" mechanism. This ensures that when viewing higher timeframes on a lower timeframe chart, the lines appear smooth and continuous rather than jagged or disconnected. It effectively "fills in the gaps" to provide a seamless visual experience.

Summary for the Trader

This tool is built for traders who want to see context. Instead of looking at price in isolation, it provides a visual map of:

  1. Trend: Via the central moving average.
  2. Volatility: Via the ATR-based bands.
  3. Perspective: By allowing the user to overlay larger timeframe data onto their current workspace.
Miscellaneous
Implements a curve of type %1
12 Views
0 Downloads
0 Favorites
MTF_ATR Channels
//+------------------------------------------------------------------+
//|      MTF                                        ATR Channels.mq4 |
//|                         Copyright © 2005, Luis Guilherme Damiani |
//|      forex-tsd.com                   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  DarkGreen       //Moving Average
#property  indicator_color2  DodgerBlue // Lower band 1
#property  indicator_color3  DodgerBlue // Upper band 1
#property  indicator_color4  RoyalBlue        // Lower band 2
#property  indicator_color5  RoyalBlue        // Upper band 2
#property  indicator_color6  FireBrick         // Lower band 3
#property  indicator_color7  FireBrick         // Upper band 3
#property indicator_width1    2 
#property indicator_width2    2 
#property indicator_width3    2 
#property indicator_width4    2 
#property indicator_width5    2 
#property indicator_width6    2 
#property indicator_width7    2 
//---- 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 TimeFrame=0;
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));
 SetIndexLabel(0, "MTF_ATR_Chnl_MA["+TimeFrame+"]"+PeriodsATR+", "+MA_Periods+"");
  // ATR 1 up
   SetIndexStyle(1, DRAW_LINE);
   SetIndexBuffer(1, Ch1up_Buffer1);
   SetIndexDrawBegin(1, MathMax(PeriodsATR, MA_Periods));
   string  sATRu1 = StringConcatenate("MTF_ATRu1([",TimeFrame,"]", 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("AMTF_TRd1([",TimeFrame,"]", 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("MTF_ATRu2([",TimeFrame,"]", 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("MTF_ATRd2([",TimeFrame,"]", 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("MTF_ATRu3([",TimeFrame,"]", 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("MTF_ATRd3([",TimeFrame,"]", PeriodsATR, ", ", Mult_Factor3, ")"); 
   SetIndexLabel(6, sATRd3);
//----

//---- name for DataWindow and indicator subwindow label   
   switch(TimeFrame)
   {
      case 1 : string TimeFrameStr="Period_M1"; break;
      case 5 : TimeFrameStr="Period_M5"; break;
      case 15 : TimeFrameStr="Period_M15"; break;
      case 30 : TimeFrameStr="Period_M30"; break;
      case 60 : TimeFrameStr="Period_H1"; break;
      case 240 : TimeFrameStr="Period_H4"; break;
      case 1440 : TimeFrameStr="Period_D1"; break;
      case 10080 : TimeFrameStr="Period_W1"; break;
      case 43200 : TimeFrameStr="Period_MN1"; break;
      default : TimeFrameStr="Current Timeframe";
  
      string short_name="MTF_ATR_Channels["+TimeFrameStr+"]"+PeriodsATR+","+MA_Periods+")";
   IndicatorShortName(short_name);
   
   } 
//
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   return(0);
  }
  
//+------------------------------------------------------------------+
//| MTF   ATR Channels                                               |
//+------------------------------------------------------------------+
int start()
  {
   datetime TimeArray[];
   int    i,limit,y=0,counted_bars=IndicatorCounted();
 
// Plot defined time frame on to current time frame
   ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),TimeFrame); 
   
   limit=Bars-counted_bars+TimeFrame/Period();
   for(i=0,y=0;i<limit;i++)
   {
   if (Time[i]<TimeArray[y]) y++;

/***********************************************************   
   Add your main indicator loop below.  You can reference an existing
      indicator with its iName  or iCustom.
   Rule 1:  Add extern inputs above for all neccesary values   
   Rule 2:  Use 'TimeFrame' for the indicator time frame
   Rule 3:  Use 'y' for your indicator's shift value
 **********************************************************/  
 MA_Buffer0[i]   =iCustom(NULL,TimeFrame,"ATR Channels",PeriodsATR, MA_Periods, MA_type,Mult_Factor1, Mult_Factor2, Mult_Factor3, 0,y);
 Ch1up_Buffer1[i]=iCustom(NULL,TimeFrame,"ATR Channels",PeriodsATR, MA_Periods, MA_type,Mult_Factor1, Mult_Factor2, Mult_Factor3, 1,y);
 Ch1dn_Buffer2[i]=iCustom(NULL,TimeFrame,"ATR Channels",PeriodsATR, MA_Periods, MA_type,Mult_Factor1, Mult_Factor2, Mult_Factor3, 2,y);
 Ch2up_Buffer3[i]=iCustom(NULL,TimeFrame,"ATR Channels",PeriodsATR, MA_Periods, MA_type,Mult_Factor1, Mult_Factor2, Mult_Factor3, 3,y);
 Ch2dn_Buffer4[i]=iCustom(NULL,TimeFrame,"ATR Channels",PeriodsATR, MA_Periods, MA_type,Mult_Factor1, Mult_Factor2, Mult_Factor3, 4,y);
 Ch3up_Buffer5[i]=iCustom(NULL,TimeFrame,"ATR Channels",PeriodsATR, MA_Periods, MA_type,Mult_Factor1, Mult_Factor2, Mult_Factor3, 5,y);
 Ch3dn_Buffer6[i]=iCustom(NULL,TimeFrame,"ATR Channels",PeriodsATR, MA_Periods, MA_type,Mult_Factor1, Mult_Factor2, Mult_Factor3, 6,y);
  
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
}
    //----  Refresh buffers ++++++++++++++++++++ upgrade by Raff  
     int TimeFrame;   if (TimeFrame>Period()) {
     int PerINT=TimeFrame/Period()+1;
     datetime TimeArr[]; ArrayResize(TimeArr,PerINT);
     ArrayCopySeries(TimeArr,MODE_TIME,Symbol(),Period()); 
     for(i=0;i<PerINT+1;i++) {if (TimeArr[i]>=TimeArray[0]) {
 /********************************************************  
    Refresh buffers:         buffer[i] = buffer[0];
 ********************************************************/  
 
 MA_Buffer0[i]   = MA_Buffer0[0];
 Ch1up_Buffer1[i]= Ch1up_Buffer1[0];
 Ch1dn_Buffer2[i]= Ch1dn_Buffer2[0];
 Ch2up_Buffer3[i]= Ch2up_Buffer3[0];
 Ch2dn_Buffer4[i]= Ch2dn_Buffer4[0];
 Ch3up_Buffer5[i]= Ch3up_Buffer5[0];
 Ch3dn_Buffer6[i]= Ch3dn_Buffer6[0];

   } } }
//+++++++++++++++++++++++++++++++++++++++++++++++++++  Raff  
   return(0);
  }
//+-----------


Comments