//+------------------------------------------------------------------+
//|      SP_Range.mq4                                                |
//|                                                                  |
//|      Shane Lee                                                   |
//|      tradingmail@bigpond.com                                     |
//|      modified by sangmane                                                            |           
//+------------------------------------------------------------------+
#property indicator_chart_window

   
//-------------------------------------------------------------------
   extern string timeframe = "D1";
   extern int period = 30;
   extern int x_adjust = 65;
   extern int init_y_adjust = 25;      
   extern int IndiCount=1;

//-------------------------------------------------------------------
int init()
  {

   return(0);
  }
//-------------------------------------------------------------------
int start()
  {
   int tf=0;
   int y_adjust;
   if (timeframe=="M1")tf=1;
   if (timeframe=="M5")tf=5;
   if (timeframe=="M15")tf=15;
   if (timeframe=="M30")tf=30;
   if (timeframe=="H1")tf=60;
   if (timeframe=="H4")tf=240;
   if (timeframe=="D1")tf=1440;
   if (timeframe=="W1")tf=10080;
   if (timeframe=="MN1" || timeframe=="MN")tf=43200;

//change Digits to Digits-1 for servers with 3 (jap) and 5 (others) decimals
   double curr_high = iHigh(Symbol(),tf,0);
   double curr_low = iLow(Symbol(),tf,0);
   double curr_range = (curr_high - curr_low)* MathPow(10,Digits);
   double prev_high = iHigh(Symbol(),tf,1);
   double prev_low = iLow(Symbol(),tf,1);
   double prev_range = (prev_high - prev_low) * MathPow(10,Digits);
   double ATR = (iATR(Symbol(),tf,period,0))* MathPow(10,Digits);
 
   y_adjust = init_y_adjust+(IndiCount-1)*45;
   label ("rnge"+IndiCount,x_adjust+5,y_adjust);
   ObjectSetText("rnge"+IndiCount,timeframe+" RANGE",7, "Verdana",DimGray);
   label ("c_r"+IndiCount,x_adjust+5,y_adjust+10);
   ObjectSetText("c_r"+IndiCount,"Current "+DoubleToStr(curr_range,0),8, "Verdana",Blue);
   label ("p_r"+IndiCount,x_adjust+5,y_adjust+20);
   ObjectSetText("p_r"+IndiCount,"Previous "+DoubleToStr(prev_range,0),8, "Verdana",Gray);
   label ("atr"+IndiCount,x_adjust+5,y_adjust+30);
   ObjectSetText("atr"+IndiCount,"ATR("+period+") "+DoubleToStr(ATR,0),8, "Verdana",Green);

   return(0);
  }
//-------------------------------------------------------------------

int deinit()
  {
   ObjectDelete("rnge"+IndiCount);
   ObjectDelete("c_r"+IndiCount);
   ObjectDelete("p_r"+IndiCount);
   ObjectDelete("atr"+IndiCount);
   
   return(0);
  }
//-------------------------------------------------------------------

void label(string name,int X,int Y,int corner=0)
   {
    ObjectCreate(name,OBJ_LABEL,0,0,0);
    ObjectSet(name,OBJPROP_CORNER,corner);
    ObjectSet(name,OBJPROP_XDISTANCE,X);
    ObjectSet(name,OBJPROP_YDISTANCE,Y);
   }