//+------------------------------------------------------------------+
//|                                                          NR7.mq4 |
//|                                                       |
//|                               |
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""

#property indicator_chart_window
#property indicator_buffers 2

#property indicator_width1 3
#property indicator_color1 Blue

extern int OfDays = 7;
extern int Wingdings = 244;
extern color Clr = Blue;

double NR[];
double Range[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   SetIndexBuffer(0, NR);
    SetIndexBuffer(1, Range);
   SetIndexLabel(0,"NarrowRange");
    SetIndexLabel(1,"Range");
   SetIndexStyle(0, DRAW_ARROW, STYLE_SOLID, indicator_width1, Clr);
   SetIndexArrow(0, Wingdings);
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int limit = Bars - IndicatorCounted() - 1;
   
   for (int i=1; i<limit; i++) {
      NR[i] = EMPTY_VALUE;
     Range[i]=High[i]-Low[i];
      if(Bars>OfDays){
     
        
         if (isNarrowRange(i)) {
            NR[i] = High[i] + 50*Point;
         }
      }
      
   }
   return(0);
  }

bool isNarrowRange(int start) {

   int NarrowestRangeinLast7Bars=ArrayMinimum(Range,OfDays, start+1);
    //NR[ start]=NarrowestRangeinLast7Bars;
   if(Range[start] <=NarrowestRangeinLast7Bars){
   return (true);
   }
   else{
   return (false);
   }
   
  
}
//+------------------------------------------------------------------+