//+------------------------------------------------------------------+
//|                                                        TEST.mq4 |
//|                        Copyright 2017, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
#property indicator_width1 2
#property indicator_style1 0

double Buffer1[];
extern int    P_Period = 14;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   SetIndexBuffer(0, Buffer1);
   SetIndexStyle(0, DRAW_LINE);

   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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 limit=rates_total-prev_calculated;
   double sumdif = 0;
   for(int i=0; i<=P_Period; i++) sumdif += High[i]-Low[i];

   
   for (int j=0; j<limit; j++)
   {
    Buffer1[j] = sumdif;    
   }
   return(rates_total);
  }
//+------------------------------------------------------------------+
