Navigation:Home > Content >

LWMA_ATR_S.mq4

Time: 2014-11-09 | Download file:LWMA_ATR_S.mq4

//+------------------------------------------------------------------+
//|                                                   LWMA_ATR_S.mq4 |
//|                               Copyright © Sovpel Alexander, 2009 |
//+------------------------------------------------------------------+
#property copyright "Copyright © Sovpel Alexander, 2009"
#property link      "E-mail: [email protected]"

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 DodgerBlue
//---- input parameters
extern int AtrPeriod    =15;
extern int Multiplier   =3;
extern int Text_Corner  =0;
extern color Text_Color =DeepSkyBlue;
//---- buffers
double AtrBuffer[];
double TempBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   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="LWMA_ATR("+AtrPeriod+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0,short_name);
//----
   SetIndexDrawBegin(0,AtrPeriod);
//----
   ObjectCreate("ATR_0",OBJ_LABEL,0,TimeCurrent(),0,0);
   ObjectSet("ATR_0", OBJPROP_XDISTANCE, 5);
   ObjectSet("ATR_0", OBJPROP_YDISTANCE, 15);
   
   ObjectCreate("ATR_1",OBJ_LABEL,0,TimeCurrent(),0,0);
   ObjectSet("ATR_1", OBJPROP_XDISTANCE, 5);
   ObjectSet("ATR_1", OBJPROP_YDISTANCE, 33);
   
   return(0);
  }
//+------------------------------------------------------------------+
//| Average True Range                                               |
//+------------------------------------------------------------------+
int start()
  {
   int i,counted_bars=IndicatorCounted();
//----
   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=High[i];
      double low =Low[i];
      if(i==Bars-1) TempBuffer[i]=high-low;
      else
        {
         double prevclose=Close[i+1];
         TempBuffer[i]=(MathMax(high,prevclose)-MathMin(low,prevclose))/Point;
        }
      i--;
     }
//----
   if(counted_bars>0) counted_bars--;
   int limit=Bars-counted_bars;
   for(i=0; i        

Recommend