//+------------------------------------------------------------------+
//|                                         Candle_Range_in_pips.mq4 |
//|                                                         Zen_Leow |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Zen_Leow"
#property link      ""
#property indicator_chart_window

extern bool   ShowLable=true;
extern int    CandleNum=1;
extern int    XDistance=10;
extern int    YDistance=100;
extern color  FontColor=Blue;
extern int    FontSize=14;
string FontStyly="Arial";
extern int    WindowNum = 0;
extern int    WindowCorner = 1;

double Range_Buffer[];
string IndiShortName="Candle Range";
int PipFactor = 1;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   
   // Cater for fractional pips
   if (Digits == 3 || Digits == 5)
   {
      PipFactor = 10;
   }
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   if(ObjectFind(0,IndiShortName)!=-1) ObjectDelete(0,IndiShortName);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   /*int limit;
   int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;

   for(int i=0; i<limit;i++){
      Range_Buffer[i]=((High[i]-Low[i])/Point)/PipFactor;
   }*/
   double m=NormalizeDouble(((High[CandleNum]-Low[CandleNum])/Point)/PipFactor,1);   
//---- Show Label
   string LabDoc="CandleRangeInPips="+DoubleToStr(m,1);
   if(ShowLable)  
     SetLable(IndiShortName,LabDoc);
   else
     if(ObjectFind(0,IndiShortName)!=-1) ObjectDelete(0,IndiShortName); 
//---- done
   return(0);
  }
//+------------------------------------------------------------------+

void SetLable(string LableName,string LableDoc)
{
   if(ObjectFind(0,LableName)!=-1) ObjectDelete(0,LableName);
   ObjectCreate(LableName,OBJ_LABEL,WindowNum,0,0);
   ObjectSet(LableName,OBJPROP_CORNER,WindowCorner);
   ObjectSet(LableName,OBJPROP_XDISTANCE,XDistance);
   ObjectSet(LableName,OBJPROP_YDISTANCE,YDistance);
   ObjectSetText(LableName,LableDoc,FontSize,FontStyly,FontColor);
}