//+------------------------------------------------------------------+
//|                                      Simple Range Calculator.mq4 |
//|                                                 by VictoriaNaomi |
//|                      Copyright © 2008, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, MetaQuotes Software Corp."
#property link      "http://www.forexindo.com/forum/showthread.php?t=95&page=9"
#property indicator_chart_window
#define IND_NAME "Simple Range Calculator"

string perhatian_range;
string perhatian_range1;
string perhatian_range2;
string perhatian_range3;

double pt;//untuk mengubah Point untuk broker 4 dan 5 digit
//+----------------------------- Note -------------------------------+
//|Originally made by VictoriaNaomi
//|New features added by wiedstone :
//|1. Logic enhancement
//|2. Broker's digits friendy (it works for 4 or 5 digits broker)
//|3. JPY pairs' friendly (it works for JPY pairs with 2 or 3 digits)
//|4. Percentage for Daily, Weekly, 2-Weekly, and Monthly Range
//|   relative to the the previous Daily, Weekly, and 2-Weekly Range
//+---------------------- End of Note    ----------------------------+




//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- Synch the digits by wiedstone
   int digit1=MarketInfo(Symbol(),MODE_DIGITS);
   switch(digit1)
   { case 2: {pt=1*Point;return;}  //for JPY 2 digits
     case 3: {pt=10*Point;return;} //for JPY 3 digits
     case 4: {pt=1*Point;return;}  //for pair 4 digits 
     case 5: {pt=10*Point;return;} //for pair 5 digits
   }
//---- End of Synch the digits   
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
//----
   double HiDayNow = iHigh(NULL,PERIOD_D1,0);
   double LoDayNow = iLow(NULL,PERIOD_D1,0);  
   double HiDay1 = iHigh(NULL,PERIOD_D1,1);
   double LoDay1 = iLow(NULL,PERIOD_D1,1);
   double HiWeekNow = iHigh(NULL,PERIOD_W1,0);
   double LoWeekNow = iLow(NULL,PERIOD_W1,0);
   double HiWeek1 = iHigh(NULL,PERIOD_W1,1);
   double LoWeek1 = iLow(NULL,PERIOD_W1,1);
   double HiWeek2 = iHigh(NULL,PERIOD_W1,2);
   double LoWeek2 = iLow(NULL,PERIOD_W1,2);
   double HiWeek3 = iHigh(NULL,PERIOD_W1,3);
   double LoWeek3 = iLow(NULL,PERIOD_W1,3);
   double Hi2WeeklyNow = MathMax(HiWeek1,HiWeekNow);
   double Lo2WeeklyNow = MathMin(LoWeek1,LoWeekNow);
   double HiMonthNow = iHigh(NULL,PERIOD_MN1,0);
   double LoMonthNow = iLow(NULL,PERIOD_MN1,0);
   
   int shift_Hi12MN        = iHighest(NULL,PERIOD_MN1,MODE_HIGH,11,0);
   int shift_Lo12MN        = iLowest(NULL,PERIOD_MN1,MODE_LOW,11,0);
   double Hi12MonthlyNow   = iHigh(NULL,PERIOD_MN1,shift_Hi12MN);
   double Lo12MonthlyNow   = iLow(NULL,PERIOD_MN1,shift_Lo12MN);

   double RangeDayNow = (HiDayNow-LoDayNow)/pt;  
   double RangeWeekNow = (HiWeekNow-LoWeekNow)/pt; 
   double Range2WeeklyNow = (MathMax(HiWeek1,HiWeekNow)-MathMin(LoWeek1,LoWeekNow))/pt;
   double Range2Weekly1 = (MathMax(HiWeek3,HiWeek2)-MathMin(LoWeek3,LoWeek2))/pt;
   double RangeMonthNow = (iHigh(NULL,PERIOD_MN1,0)-iLow(NULL,PERIOD_MN1,0))/pt;     
   double RangeDay1 = (iHigh(NULL,PERIOD_D1,1)-iLow(NULL,PERIOD_D1,1))/pt;
   double RangeDay2 = (iHigh(NULL,PERIOD_D1,2)-iLow(NULL,PERIOD_D1,2))/pt;
   double RangeDay3 = (iHigh(NULL,PERIOD_D1,3)-iLow(NULL,PERIOD_D1,3))/pt;
   double RangeWeek1 = (iHigh(NULL,PERIOD_W1,1)-iLow(NULL,PERIOD_W1,1))/pt;
   double RangeWeek2 = (iHigh(NULL,PERIOD_W1,2)-iLow(NULL,PERIOD_W1,2))/pt;
   double RangeWeek3 = (iHigh(NULL,PERIOD_W1,3)-iLow(NULL,PERIOD_W1,3))/pt;
   double RangeMonth1 = (iHigh(NULL,PERIOD_MN1,1)-iLow(NULL,PERIOD_MN1,1))/pt;
   double RangeMonth2 = (iHigh(NULL,PERIOD_MN1,2)-iLow(NULL,PERIOD_MN1,2))/pt;
   double RangeMonth3 = (iHigh(NULL,PERIOD_MN1,3)-iLow(NULL,PERIOD_MN1,3))/pt;
   double RangeMonth4 = (iHigh(NULL,PERIOD_MN1,4)-iLow(NULL,PERIOD_MN1,4))/pt;
   double Range12MonthlyNow = (Hi12MonthlyNow-Lo12MonthlyNow)/pt;
   
   if (RangeDayNow<RangeDay1) {perhatian_range="RANGE HARI KEMARIN BELUM TERPENUHI";}
   if (RangeDayNow>=RangeDay1) {perhatian_range="RANGE HARI KEMARIN SUDAH TERPENUHI";}
   
   if (RangeWeekNow<RangeWeek1) {perhatian_range1="RANGE MINGGU KEMARIN BELUM TERPENUHI";}
   if (RangeWeekNow>=RangeWeek1) {perhatian_range1="RANGE MINGGU KEMARIN SUDAH TERPENUHI";}
   
   if (Range2WeeklyNow< Range2Weekly1) {perhatian_range2="RANGE 2 MINGGUAN KEMARIN BELUM TERPENUHI";}
   if (Range2WeeklyNow>= Range2Weekly1) {perhatian_range2="RANGE 2 MINGGUAN KEMARIN SUDAH TERPENUHI";}
   
   if (RangeMonthNow<RangeMonth1) {perhatian_range3="RANGE BULAN KEMARIN BELUM TERPENUHI";}
   if (RangeMonthNow>=RangeMonth1) {perhatian_range3="RANGE BULAN KEMARIN SUDAH TERPENUHI";}
   //----
   double RAvg               = (RangeDayNow+RangeWeekNow+Range2WeeklyNow+RangeMonthNow)/4;   //Rata-rata R1 s.d. R20
   double RangePctDayNow     = RangeDayNow/RangeDay1*100;        //Persentase Range Hari ini dg Range Kemarin
   double RangePctWeekNow    = RangeWeekNow/RangeWeek1*100;      //Persentase Range Minggu ini dg Range Minggu Kemarin
   double RangePct2WeeklyNow = Range2WeeklyNow/Range2Weekly1*100;//Persentase Range 2 Mingguan ini dg Range 2 Mingguan Kemarin
   double RangePctMonthNow   = RangeMonthNow/RangeMonth1*100;    //Persentase Range Bulan ini dg Range Bulan Kemarin
   
			Comment (
		       "\n Indicator : " + IND_NAME + "  "
					 +"\n --------------------------------------------------------------"
					 +"\n Harga Tertinggi Hari ini: "+(DoubleToStr (HiDayNow,Digits))
					 +"\n Harga Tertinggi Kemarin: "+(DoubleToStr (HiDay1,Digits))
					 +"\n Harga Tertinggi Minggu ini: "+(DoubleToStr (HiWeekNow,Digits))
					 +"\n Harga Tertinggi 2 Minggu ini: "+(DoubleToStr (Hi2WeeklyNow,Digits))
					 +"\n Harga Tertinggi Bulan ini: "+(DoubleToStr (HiMonthNow,Digits))
					 +"\n Harga Tertinggi 12 Bulan ini: "+(DoubleToStr (Hi12MonthlyNow,Digits))
					 +"\n --------------------------------------------------------------"
					 +"\n Harga Terendah Hari ini: "+(DoubleToStr (LoDayNow,Digits))
					 +"\n Harga Terendah Kemarin: "+(DoubleToStr (LoDay1,Digits))
					 +"\n Harga Terendah Minggu ini: "+(DoubleToStr (LoWeekNow,Digits))
					 +"\n Harga Terendah 2 Minggu ini: "+(DoubleToStr (Lo2WeeklyNow,Digits))
					 +"\n Harga Terendah Bulan ini: "+(DoubleToStr (LoMonthNow,Digits))
					 +"\n Harga Terendah 12 Bulan ini: "+(DoubleToStr (Lo12MonthlyNow,Digits))
					 +"\n --------------------------------------------------------------"
					 +"\n Range Hari ini: " + DoubleToStr(RangeDayNow,1)+""
					 +"\n Range Minggu ini: " + DoubleToStr(RangeWeekNow,1)+""
					 +"\n Range 2 Minggu ini: " + DoubleToStr(Range2WeeklyNow,1)+""
					 +"\n Range Bulan ini: " + DoubleToStr(RangeMonthNow,1)+""
                +"\n Range 12 Bulan ini: " + DoubleToStr(Range12MonthlyNow,1)+""
					 +"\n --------------------------------------------------------------"
					 +"\n Rata-Rata Range Hari,Minggu,2 Minggu, dan Bulan ini : " + DoubleToStr(RAvg,1)+""
					 +"\n --------------------------------------------------------------"
					 +"\n Range 1 Hari Kemarin: " + DoubleToStr(RangeDay1,1)+""
                +"\n Range 2 Hari Kemarin: " + DoubleToStr(RangeDay2,1)+""
                +"\n Range 3 Hari Kemarin: " + DoubleToStr(RangeDay3,1)+""
                +"\n Range 1 Minggu Kemarin: " + DoubleToStr(RangeWeek1,1)+""
                +"\n Range 2 Minggu Kemarin: " + DoubleToStr(RangeWeek2,1)+""
                +"\n Range 3 Minggu Kemarin: " + DoubleToStr(RangeWeek3,1)+""
                +"\n Range 1 Bulan Kemarin: " + DoubleToStr(RangeMonth1,1)+""
                +"\n Range 2 Bulan Kemarin: " + DoubleToStr(RangeMonth2,1)+""
                +"\n Range 3 Bulan Kemarin: " + DoubleToStr(RangeMonth3,1)+""
                +"\n Range 4 Bulan Kemarin: " + DoubleToStr(RangeMonth4,1)+""
					 +"\n ---------------------------------------------------------------------------"
					 +"\n PERHATIAN 1 : " + perhatian_range + " (" + DoubleToStr(RangePctDayNow,1) + " %)" +""
					 +"\n PERHATIAN 2 : " + perhatian_range1 + " (" + DoubleToStr(RangePctWeekNow,1) + " %)" +""
					 +"\n PERHATIAN 3 : " + perhatian_range2 + " (" + DoubleToStr(RangePct2WeeklyNow,1) + " %)" +""
					 +"\n PERHATIAN 4 : " + perhatian_range3 + " (" + DoubleToStr(RangePctMonthNow,1) + " %)" +""
					 +"\n ---------------------------------------------------------------------------"
			       +"\n =    SPECIAL RESPECT FOR KG from VictoriaNaomi & wiedstone     ="

					);
   return(0);
  }
//+------------------------------------------------------------------+