//+------------------------------------------------------------------+
//|                                                     ATP Worm.mq4|
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1  clrDodgerBlue
#property indicator_color2  clrRed
#property indicator_color3  clrDodgerBlue
#property indicator_color4  clrRed

#property indicator_width1  2
#property indicator_width2  2
#property indicator_width3  2
#property indicator_width4  2


#property strict

//
//
//
//
//

extern double Pips      = 0.5; // pips
extern int    AtrLength = 14;  // ATR length
extern int    Multiple  = 2;   // Multiplier

double Up1Buffer[],Up2Buffer[],Dn1Buffer[],Dn2Buffer[];

//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//

int OnInit()
{
   IndicatorBuffers(4);
   SetIndexBuffer(0,Up1Buffer, INDICATOR_DATA); SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(1,Up2Buffer, INDICATOR_DATA); SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(2,Dn1Buffer, INDICATOR_DATA); SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(3,Dn2Buffer, INDICATOR_DATA); SetIndexStyle(3,DRAW_LINE); 
   
   IndicatorShortName(" ATP  ");
   
return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason){   }

//
//
//

int OnCalculate (const int       rates_total,
                 const int       prev_calculated,
                 const datetime& time[],
                 const double&   open[],
                 const double&   high[],
                 const double&   low[],
                 const double&   close[],
                 const long&     tick_volume[],
                 const long&     volume[],
                 const int&      spread[])
{
   int i,limit=fmin(rates_total-prev_calculated+1,rates_total-1);
    
          
   double pipMultiplier = Point*MathPow(10,Digits%2);   
   for(i=limit;i>=0; i--)
   {  
      double atr = iATR(Symbol(), 0, AtrLength, i);
      Up1Buffer[i] = (i<rates_total-1) ? low[i+1]  - Pips * pipMultiplier + atr* Multiple : 0;
      Up2Buffer[i] = low[i]    - Pips * pipMultiplier + atr * Multiple;
      Dn1Buffer[i] = (i<rates_total-1) ? high[i+1] + Pips * pipMultiplier - atr* Multiple : 0;
      Dn2Buffer[i] = high[i]   + Pips * pipMultiplier - atr * Multiple;
   }
return(rates_total);
}

//------------------------------------------------------------------
//                                                                  
//------------------------------------------------------------------

