//+------------------------------------------------------------------+
//|                                           Candle_Open_Close.mq4 |
//|                                                                 |
//+------------------------------------------------------------------+

#property indicator_chart_window

extern double DisplayLengthLimit = 2.5;
extern color DisplayUpperColor = DodgerBlue;
extern color DisplayLowerColor = Red;
extern int DisplayDistance = 8; // Distance from Pip Count

double Poin;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
	Poin = Point;
	//Checking for unconvetional Point digits number
   if ((Point == 0.00001) || (Point == 0.001)) Poin *= 10;
   return(0);
}

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{
   for (int i = 0; i < Bars; i++)
   {
      ObjectDelete("DisplayUpperColor" + TimeToStr(Time[i], TIME_DATE|TIME_MINUTES));
      ObjectDelete("DisplayLowerColor" + TimeToStr(Time[i], TIME_DATE|TIME_MINUTES));
   }
   return(0);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   string name, length;
   double R;
      
   int counted_bars = IndicatorCounted();
   if (counted_bars > 0) counted_bars--;
   int limit = Bars - counted_bars;
   if (limit > 250) limit = 250;
     
   for (int i = 0; i <= limit; i++)
   {
          R = (Close[i] - Open[i]) / Poin;
          length = DoubleToStr(R, 0);
          name = TimeToStr(Time[i], TIME_DATE|TIME_MINUTES);
          if (ObjectFind(name) != -1) ObjectDelete(name);
      
         if (R > DisplayLengthLimit)
         {
            if (ObjectFind(name) != -1) ObjectDelete(name); 
            length = DoubleToStr(R, 0);
            ObjectCreate(name, OBJ_TEXT, 0, Time[i], High[i] + DisplayDistance * Point);
            ObjectSetText(name, length, 10, "Verdana", DisplayUpperColor);
            }
            if (R < DisplayLengthLimit * (-1))
            {
            if (ObjectFind(name) != -1) ObjectDelete(name); 
            length = DoubleToStr(MathAbs (R), 0);
            ObjectCreate(name, OBJ_TEXT, 0, Time[i], High[i] + DisplayDistance * Point);
            ObjectSetText(name, length, 10, "Verdana", DisplayLowerColor);
            }
         }
   
   return(0);
}
//+------------------------------------------------------------------+