ATR_Bands





//+------------------------------------------------------------------+
//|                                                    ATR_Bands.mq4 |
//| ATR Bands are self-adjusting enveloppes, based on the volatility |
//|        Based on BB indicator, modified by kris.pivo[at]gmail.com |
//+------------------------------------------------------------------+
#property copyright "© 2008, Kris"
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 C'150,150,150'
#property indicator_color2 C'080,080,080'
#property indicator_color3 C'080,080,080'
//---- indicator parameters
extern int    Bands_Period   =  21;
extern int    Bands_Shift    =   0;
extern int    ATR_Period     =  14;
extern double ATR_Multiplier = 1.5;
//---- buffers
double MovingBuffer[];
double UpperBuffer[];
double LowerBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle( 0,DRAW_LINE,STYLE_SOLID,2,indicator_color1);
   SetIndexBuffer(0,MovingBuffer);
   SetIndexStyle( 1,DRAW_LINE,STYLE_DOT,  1,indicator_color2);
   SetIndexBuffer(1,UpperBuffer);
   SetIndexStyle( 2,DRAW_LINE,STYLE_DOT,  1,indicator_color3);
   SetIndexBuffer(2,LowerBuffer);
//----
   SetIndexDrawBegin(0,Bands_Period+Bands_Shift);
   SetIndexDrawBegin(1,Bands_Period+Bands_Shift);
   SetIndexDrawBegin(2,Bands_Period+Bands_Shift);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Bollinger Bands                                                  |
//+------------------------------------------------------------------+
int start()
  {
   int    i,k,counted_bars=IndicatorCounted();
   double TrueRange;
   double sum,oldval,newres;
//----
   if(Bars<=Bands_Period) return(0);
//---- initial zero
   if(counted_bars<1)
      for(i=1;i<=Bands_Period;i++)
        {
         MovingBuffer[Bars-i]=EMPTY_VALUE;
         UpperBuffer[Bars-i]=EMPTY_VALUE;
         LowerBuffer[Bars-i]=EMPTY_VALUE;
        }
//----
   int limit=Bars-counted_bars;
   if(counted_bars>0) limit++;
   for(i=0; i<limit; i++)
      MovingBuffer[i]=iMA(NULL,0,Bands_Period,Bands_Shift,MODE_EMA,PRICE_CLOSE,i);
//----
   i=Bars-Bands_Period+1;
   if(counted_bars>Bands_Period-1) i=Bars-counted_bars-1;
   while(i>=0)
     {
      sum=0.0;
      k=i+Bands_Period-1;
      oldval=MovingBuffer[i];
      TrueRange=ATR_Multiplier*iATR(NULL,0,ATR_Period,Bands_Shift);
      UpperBuffer[i]=oldval+TrueRange;
      LowerBuffer[i]=oldval-TrueRange;
      i--;
     }
//----
   return(0);
  }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
//                                       THE END                                        |
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+





Sample





Analysis



Market Information Used:



Indicator Curves created:

Implements a curve of type DRAW_LINE


Indicators Used:

Moving average indicator
Indicator of the average true range


Custom Indicators Used:

Order Management characteristics:

Other Features: