ATR CountBack





//+------------------------------------------------------------------+
//|                                                ATR CountBack.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Altered by cja"
#property link      "http://www.metaquotes.net/"

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 DodgerBlue
//---- input parameters
extern int AtrPeriod=14;
extern int ATR_TF = 60;
extern int CountBack = 0;

//---- buffers
double AtrBuffer[];
double TempBuffer[];

string TimeFrameStr;
extern int Maxbars   = 24;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
    
    switch(ATR_TF)
   {
      case 1 : 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 "; ATR_TF=0;
   }
  
   string short_name;
//---- 1 additional buffer used for counting.
   IndicatorBuffers(2);
//---- indicator line
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,AtrBuffer);
   SetIndexBuffer(1,TempBuffer);
//---- name for DataWindow and indicator subwindow label
   short_name="ATR( "+AtrPeriod+" )( "+TimeFrameStr+" )( "+CountBack+" )";
   IndicatorShortName(short_name);
   SetIndexLabel(0,short_name);
//----
   SetIndexDrawBegin(0,AtrPeriod);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Average True Range                                               |
//+------------------------------------------------------------------+
int start()
  {
   int i,counted_bars=IndicatorCounted();
   
    int limit;
   limit = MathMin(counted_bars,Maxbars);
   if (limit ==0)
      limit = Maxbars;
   
  //----
   if(Bars<=AtrPeriod) return(0);
//---- initial zero
   if(counted_bars<1)
      for(i=1;i<=AtrPeriod;i++) AtrBuffer[Bars-i]=0.0;
//----
   i=Bars-counted_bars-1;
   while(i>=0)
     {
      double high=iHigh(NULL,ATR_TF,i+CountBack);
      double low =iLow(NULL,ATR_TF,i+CountBack);
      if(i==Bars-1) TempBuffer[i]=high-low;
      else
        {
         double prevclose=iClose(NULL,ATR_TF,i+1+CountBack);
         TempBuffer[i]=MathMax(high,prevclose)-MathMin(low,prevclose);
        }
      i--;
     }
//----
   if(counted_bars>0) counted_bars--;
   //int limit=Bars-counted_bars;
   for(i=0; i<limit; i++)
      AtrBuffer[i]=iMAOnArray(TempBuffer,Bars,AtrPeriod,0,MODE_SMA,i);
      
//----
   return(0);
  }
//+------------------------------------------------------------------+



Sample





Analysis



Market Information Used:

Series array that contains the highest prices of each bar
Series array that contains the lowest prices of each bar
Series array that contains close prices for each bar


Indicator Curves created:

Implements a curve of type DRAW_LINE


Indicators Used:

Moving average indicator


Custom Indicators Used:

Order Management characteristics:

Other Features: