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);
  }
//+-----------






Sample





Analysis



Market Information Used:

Series array that contains open time of each bar


Indicator Curves created:

Implements a curve of type DRAW_LINE


Indicators Used:




Custom Indicators Used:
ATR Channels

Order Management characteristics:

Other Features: