ATR_Channels_VarTFs_mtf_TMA

Download script
Author: Copyright � 2005, Luis Guilherme Damiani
ATR_Channels_VarTFs_mtf_TMA

This script is a technical analysis tool designed for the MetaTrader platform. Its primary purpose is to visualize market volatility and price trends by plotting a series of dynamic "channels" on a trading chart.

Here is a breakdown of how the logic functions:

Core Components

The indicator operates by calculating three distinct layers of data, all revolving around a central baseline:

  1. The Baseline (Moving Average): The script identifies a central trend line using a specific type of moving average (a weighted average). This acts as the "anchor" for the channels, representing the smoothed price trend over a long period.
  2. The Volatility Measurement (ATR): To determine how wide the channels should be, the script uses an Average True Range (ATR) calculation. This measures how much an asset typically moves in price over a specific time frame.
  3. The Channels: By combining the baseline and the volatility measurement, the script draws three pairs of upper and lower bands. Each pair uses a different multiplier to create distinct visual zones:
    • Inner Channel: A tighter band for identifying immediate price fluctuations.
    • Middle Channel: A standard range based on a neutral multiplier.
    • Outer Channel: A wider band used to identify extreme price movements or overextended trends.

Multi-Timeframe Intelligence

One of the more advanced features of this logic is its ability to "look" at different timeframes simultaneously. It can pull volatility data from a much higher time frame (e.g., Daily or Weekly) and project it onto your current lower time frame chart (e.g., Hourly or Minutes). This allows traders to see how high-level market trends are impacting the current price action.

How It Works in Practice

  • Trend Identification: The green baseline helps the user see the general direction of the market.
  • Volatility Mapping: The blue and red bands create a "tunnel" or "envelope." When the price stays within these bands, it suggests normal market behavior.
  • Dynamic Adjustment: Because the logic relies on the ATR (volatility), these channels are not static. They will automatically expand during periods of high market activity (high volatility) and contract during quiet periods (low volatility).

Summary of Visual Output

When applied to a chart, you will see a central moving average with three sets of symmetrical bands surrounding it. These provide a visual "map" of where the price is likely to stay based on historical volatility, helping users distinguish between standard market noise and significant price breakouts.

Indicators Used
Indicator of the average true range
Miscellaneous
Implements a curve of type %1
12 Views
0 Downloads
0 Favorites
ATR_Channels_VarTFs_mtf_TMA
//+------------------------------------------------------------------+
//|                                                 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 = 50;
extern int     HalfLength = 201;
extern int     Price  = PRICE_WEIGHTED;
extern int     MA_shift  = 0;
extern int     MA_x_shift= 0;

extern int    TimeFrame=0;
extern int    ATR_TimeFrame=0;


extern double Mult_Factor1 = 0.618;
extern double Mult_Factor2 = 1.0;
extern double Mult_Factor3 = 1.5;

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, HalfLength));
   string  sATRc = StringConcatenate("ATRchannel MA( ",HalfLength,") ATR ", PeriodsATR, ") [",TimeFrame,"] "); 
   SetIndexLabel(0, sATRc);

  
  // ATR 1 up
   SetIndexStyle(1, DRAW_LINE);
   SetIndexBuffer(1, Ch1up_Buffer1);
   SetIndexDrawBegin(1, MathMax(PeriodsATR, HalfLength));
   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, HalfLength));
   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, HalfLength));
   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, HalfLength));
   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, HalfLength));
   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, HalfLength));
   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  = iCustom(NULL,0,"TMAcentered",HalfLength,Price,0,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