//+------------------------------------------------------------------+
//|                                         Candle_Range_in_pips.mq4 |
//|                                                         Zen_Leow |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Zen_Leow"
#property link      ""

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1  SkyBlue
#property indicator_width1  3

double Range_Buffer[];
double Range_Buffers0;
double Range_Buffers1;
double Range_Buffers2;
double Range_Buffers3;
double Range_Buffers4;
double Range_Buffers5;

int PipFactor = 1;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
//---- drawing settings
   SetIndexStyle(0,DRAW_NONE);
   SetIndexBuffer(0,Range_Buffer);
   SetIndexLabel(0,"Range");
   
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("Candle Range");
   IndicatorDigits(2);
   // Cater for fractional pips
   if (Digits == 3 || Digits == 5)
   {
      PipFactor = 10;
   }
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   ObjectDelete("CRP0");
   ObjectDelete("CRP1");
   ObjectDelete("CRP2");
   ObjectDelete("CRP3");
   ObjectDelete("CRP4");
   ObjectDelete("CRP5");
//----
   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;
      Range_Buffers0=((High[0]-Low[0])/Point)/PipFactor;
      Range_Buffers1=((High[1]-Low[1])/Point)/PipFactor;
      Range_Buffers2=((High[2]-Low[2])/Point)/PipFactor;
      Range_Buffers3=((High[3]-Low[3])/Point)/PipFactor;
      Range_Buffers4=((High[4]-Low[4])/Point)/PipFactor;
      Range_Buffers5=((High[5]-Low[5])/Point)/PipFactor;
        
      ObjectCreate("CRP0", OBJ_LABEL, 0, 0, 0);
      ObjectSet("CRP0", OBJPROP_CORNER, 1);
      ObjectSet("CRP0", OBJPROP_XDISTANCE, 5);
      ObjectSet("CRP0", OBJPROP_YDISTANCE,  5);
      ObjectSetText("CRP0", " 0 Candle  " + Range_Buffers0 + "  Pips", 10, "Arial", clrLime);
      
      ObjectCreate("CRP1", OBJ_LABEL, 0, 0, 0);
      ObjectSet("CRP1", OBJPROP_CORNER, 1);
      ObjectSet("CRP1", OBJPROP_XDISTANCE, 5);
      ObjectSet("CRP1", OBJPROP_YDISTANCE,  20);
      ObjectSetText("CRP1", " 1 Candle  " + Range_Buffers1 + "  Pips", 10, "Arial", clrLime);
      
      ObjectCreate("CRP2", OBJ_LABEL, 0, 0, 0);
      ObjectSet("CRP2", OBJPROP_CORNER, 1);
      ObjectSet("CRP2", OBJPROP_XDISTANCE, 5);
      ObjectSet("CRP2", OBJPROP_YDISTANCE,  35);
      ObjectSetText("CRP2", " 2 Candle  " + Range_Buffers2 + "  Pips", 10, "Arial", clrLime);
      
      ObjectCreate("CRP3", OBJ_LABEL, 0, 0, 0);
      ObjectSet("CRP3", OBJPROP_CORNER, 1);
      ObjectSet("CRP3", OBJPROP_XDISTANCE, 5);
      ObjectSet("CRP3", OBJPROP_YDISTANCE,  50);
      ObjectSetText("CRP3", " 3 Candle  " + Range_Buffers3 + "  Pips", 10, "Arial", clrLime);
      
      ObjectCreate("CRP4", OBJ_LABEL, 0, 0, 0);
      ObjectSet("CRP4", OBJPROP_CORNER, 1);
      ObjectSet("CRP4", OBJPROP_XDISTANCE, 5);
      ObjectSet("CRP4", OBJPROP_YDISTANCE,  65);
      ObjectSetText("CRP4", " 4 Candle  " + Range_Buffers4 + "  Pips", 10, "Arial", clrLime);
      
      ObjectCreate("CRP5", OBJ_LABEL, 0, 0, 0);
      ObjectSet("CRP5", OBJPROP_CORNER, 1);
      ObjectSet("CRP5", OBJPROP_XDISTANCE, 5);
      ObjectSet("CRP5", OBJPROP_YDISTANCE,  80);
      ObjectSetText("CRP5", " 5 Candle  " + Range_Buffers5 + "  Pips", 10, "Arial", clrLime);
     }       
//---- done
   return(0);
  }
//+------------------------------------------------------------------+
