- #property indicator_chart_window
- #property indicator_buffers 2
- #property indicator_color1 DodgerBlue
- #property indicator_color2 DodgerBlue
- //---- input parameters
- extern double target=2;
- extern int AtrPeriod=20;
- //---- buffers
- double Up[],Dn[];
- //+------------------------------------------------------------------+
- //| Custom indicator initialization function |
- //+------------------------------------------------------------------+
- int init()
- {
- string short_name;
- IndicatorBuffers(2);
- //---- indicator line
- SetIndexStyle(0,DRAW_LINE);
- SetIndexStyle(1,DRAW_LINE);
- SetIndexBuffer(0,Up);
- SetIndexBuffer(1,Dn);
- //---- name for DataWindow and indicator subwindow label
- short_name="ATR("+AtrPeriod+")";
- IndicatorShortName(short_name);
- SetIndexLabel(0,short_name);
- SetIndexLabel(1,short_name);
- //----
- SetIndexDrawBegin(0,AtrPeriod);
- SetIndexDrawBegin(1,AtrPeriod);
- //----
- return(0);
- }
- //+------------------------------------------------------------------+
- //| Average True Range |
- //+------------------------------------------------------------------+
- int start()
- {
- int i,counted_bars=IndicatorCounted();
- //----
- if(counted_bars>0) counted_bars--;
- int limit=Bars-counted_bars;
-
- for(i=0; i<limit; i++)
- {
- Up[i]=Open[i]+target*iATR(NULL,0,AtrPeriod,i);
- Dn[i]=Open[i]-target*iATR(NULL,0,AtrPeriod,i);
- }
- //----
- return(0);
- }
- //+------------------------------------------------------------------+
|