1 //+------------------------------------------------------------------+
\r
3 //| Copyright © 2005, MetaQuotes Software Corp. |
\r
4 //| http://www.metaquotes.net/ |
\r
5 //+------------------------------------------------------------------+
\r
6 #property copyright "Copyright © 2005, MetaQuotes Software Corp."
\r
7 #property link "http://www.metaquotes.net/"
\r
9 #property indicator_separate_window
\r
10 #property indicator_buffers 1
\r
11 #property indicator_color1 DodgerBlue
\r
12 //---- input parameters
\r
13 extern int AtrPeriod=14;
\r
16 double TempBuffer[];
\r
17 //+------------------------------------------------------------------+
\r
18 //| Custom indicator initialization function |
\r
19 //+------------------------------------------------------------------+
\r
23 //---- 1 additional buffer used for counting.
\r
24 IndicatorBuffers(2);
\r
25 //---- indicator line
\r
26 SetIndexStyle(0,DRAW_LINE);
\r
27 SetIndexBuffer(0,AtrBuffer);
\r
28 SetIndexBuffer(1,TempBuffer);
\r
29 //---- name for DataWindow and indicator subwindow label
\r
30 short_name="ATR("+AtrPeriod+")";
\r
31 IndicatorShortName(short_name);
\r
32 SetIndexLabel(0,short_name);
\r
34 SetIndexDrawBegin(0,AtrPeriod);
\r
38 //+------------------------------------------------------------------+
\r
39 //| Average True Range |
\r
40 //+------------------------------------------------------------------+
\r
43 int i,counted_bars=IndicatorCounted();
\r
45 if(Bars<=AtrPeriod) return(0);
\r
48 for(i=1;i<=AtrPeriod;i++) AtrBuffer[Bars-i]=0.0;
\r
50 i=Bars-counted_bars-1;
\r
53 double high=High[i];
\r
55 if(i==Bars-1) TempBuffer[i]=high-low;
\r
58 double prevclose=Close[i+1];
\r
59 TempBuffer[i]=MathMax(high,prevclose)-MathMin(low,prevclose);
\r
64 if(counted_bars>0) counted_bars--;
\r
65 int limit=Bars-counted_bars;
\r
66 for(i=0; i<limit; i++)
\r
67 AtrBuffer[i]=iMAOnArray(TempBuffer,Bars,AtrPeriod,0,MODE_SMA,i);
\r
71 //+------------------------------------------------------------------+