//+------------------------------------------------------------------+
//|                                                  PriceToOpen.mq4 |
//+------------------------------------------------------------------+
#property description "Price relative to Open Histogram"

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_minimum 0
#property indicator_maximum 2
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_width1 4
#property indicator_width2 4

int TimeFrame = PERIOD_D1;
double up[],dn[];
int    i,y,limit,counted_bars;
double opn;

//|------------------------------------------------------------------|

void init() {
  SetIndexBuffer(0,up);
  SetIndexBuffer(1,dn);
  SetIndexStyle(0,DRAW_HISTOGRAM);
  SetIndexStyle(1,DRAW_HISTOGRAM);
  SetIndexArrow(0,110);
  SetIndexArrow(1,110);
}

//+------------------------------------------------------------------+
void deinit() {}
//+------------------------------------------------------------------+

int start()
{
   datetime TimeArray[];
   counted_bars=IndicatorCounted();
   if(counted_bars<1)limit=Bars-1;
   else limit=Bars-counted_bars;
  
   if(Period()>=240)return(0);  
   ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),TimeFrame);

   for(i=0,y=0;i<limit;i++)
      {
          if(Time[i]<TimeArray[y])y++;
          up[i]=EMPTY_VALUE;
          dn[i]=EMPTY_VALUE;
          opn=iOpen( Symbol(),TimeFrame,y);
          if(Close[i+0]>opn)up[i+0]=2;
          else              dn[i+0]=2;
      }
 return(0);
}

//+------------------------------------------------------------------+