//+------------------------------------------------------------------+
//|                                                  highlow seo.mq4 |
//|                        Copyright 2016, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 clrGreen  // highest high calc color
#property indicator_width1 1        // line width
#property indicator_color2 clrRed  // lowest low calc color
#property indicator_width2 1       // line width


extern int myval = 24;    // input variable for calculations

double Buffer1[];         // number of bars since last highest high by input
double Buffer2[];         // number of bars since last low high by input

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,Buffer1);
   SetIndexBuffer(1,Buffer2);
   // line draw
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   //start at first occurance
   SetIndexDrawBegin(0,myval+1);
   SetIndexDrawBegin(1,myval+1);
   // name of each line
   SetIndexLabel(0,"HHLVL");
   SetIndexLabel(1,"LWLVL");
   
   
  
//---
   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;
//---- main loop
   for(int i=0; i<limit; i++)
   
   {
    
     Buffer1[i]= ( iHighest(NULL,PERIOD_CURRENT,MODE_HIGH,myval,1));
     Buffer2[i]= ( iLowest(NULL,PERIOD_CURRENT,MODE_LOW,myval,1));
   }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
