//+------------------------------------------------------------------+
//|   #SpudFibo.mq4 - downloaded from ultimaforex.com
//+------------------------------------------------------------------+
#property  indicator_chart_window

extern string note1 = "Fibonacci colors";
extern color DailyFiboColor = RoyalBlue;
extern color WeeklyFiboColor = Green;
extern color MonthlyFiboColor = Maroon;
extern string note2 = "Draw main Fibonacci lines?";
bool  InnerFibs = true;

extern bool DailyKGFibo = true;
extern bool WeeklyKGFibo = true;
extern bool MonthlyKGFibo = true;

/*
Weekly,Monthly Options
Modified by metropolis

hope KG don't mind ^_^
*/

int init()
{
   return(0);
}

int deinit()
{
   ObjectDelete("FiboUpDay");
   ObjectDelete("FiboDnDay");
   ObjectDelete("FiboInDay");
   
   ObjectDelete("FiboUpWeek");
   ObjectDelete("FiboDnWeek");
   ObjectDelete("FiboInWeek");
   
   ObjectDelete("FiboUpMonth");
   ObjectDelete("FiboDnMonth");
   ObjectDelete("FiboInMonth");
   return(0);
}


//+------------------------------------------------------------------+
//| Draw Fibo
//+------------------------------------------------------------------+

int DrawFibo(color MainFiboColor, datetime StartTime, double HiPrice, double LoPrice, double Range, string TF)
{
	if(InnerFibs)
	{
		if(ObjectFind("FiboIn"+TF) == -1)
			ObjectCreate("FiboIn"+TF,OBJ_FIBO,0,StartTime,HiPrice,StartTime+PERIOD_D1*60,LoPrice);
		else
		{
			ObjectSet("FiboIn"+TF,OBJPROP_TIME2, StartTime);
			ObjectSet("FiboIn"+TF,OBJPROP_TIME1, StartTime+PERIOD_D1*60);
			ObjectSet("FiboIn"+TF,OBJPROP_PRICE1,HiPrice);
			ObjectSet("FiboIn"+TF,OBJPROP_PRICE2,LoPrice);
		}
   	ObjectSet("FiboIn"+TF,OBJPROP_LEVELCOLOR,MainFiboColor); 
   	ObjectSet("FiboIn"+TF,OBJPROP_FIBOLEVELS,13);
   	ObjectSet("FiboIn"+TF,OBJPROP_FIRSTLEVEL+0,-1.00);	ObjectSetFiboDescription("FiboIn"+TF,0,"("+TF+" SD-3.0)  -  %$");
   	ObjectSet("FiboIn"+TF,OBJPROP_FIRSTLEVEL+1,-0.75);	ObjectSetFiboDescription("FiboIn"+TF,1,"("+TF+" SD-2.5)  -  %$");
   	ObjectSet("FiboIn"+TF,OBJPROP_FIRSTLEVEL+2,-0.50);	ObjectSetFiboDescription("FiboIn"+TF,2,"("+TF+" SD-2.0)  -  %$");
   	ObjectSet("FiboIn"+TF,OBJPROP_FIRSTLEVEL+3,-0.25);	ObjectSetFiboDescription("FiboIn"+TF,3,"("+TF+" SD-1.5)  -  %$");
   	ObjectSet("FiboIn"+TF,OBJPROP_FIRSTLEVEL+4,0.0);	ObjectSetFiboDescription("FiboIn"+TF,4,"("+TF+" SD-1.0)  -  %$"); 
   	ObjectSet("FiboIn"+TF,OBJPROP_FIRSTLEVEL+5,0.25);	ObjectSetFiboDescription("FiboIn"+TF,5,"("+TF+" SD -0.5) -  %$"); 
   	ObjectSet("FiboIn"+TF,OBJPROP_FIRSTLEVEL+6,0.50);	ObjectSetFiboDescription("FiboIn"+TF,6,"("+TF+" Balance) -  %$"); 
   	ObjectSet("FiboIn"+TF,OBJPROP_FIRSTLEVEL+7,0.75);	ObjectSetFiboDescription("FiboIn"+TF,7,"("+TF+" SD +0.5) -  %$"); 
   	ObjectSet("FiboIn"+TF,OBJPROP_FIRSTLEVEL+8,1.00);	ObjectSetFiboDescription("FiboIn"+TF,8,"("+TF+" SD +1.0)  -  %$");
   	ObjectSet("FiboIn"+TF,OBJPROP_FIRSTLEVEL+9,1.25);	ObjectSetFiboDescription("FiboIn"+TF,9,"("+TF+" SD+1.5)  -  %$");
   	ObjectSet("FiboIn"+TF,OBJPROP_FIRSTLEVEL+10,1.50);	ObjectSetFiboDescription("FiboIn"+TF,10,"("+TF+" SD+2.0)  -  %$");
   	ObjectSet("FiboIn"+TF,OBJPROP_FIRSTLEVEL+11,1.75);	ObjectSetFiboDescription("FiboIn"+TF,11,"("+TF+" SD+2.5)  -  %$");
   	ObjectSet("FiboIn"+TF,OBJPROP_FIRSTLEVEL+12,2.0);	ObjectSetFiboDescription("FiboIn"+TF,12,"("+TF+" SD+3.0)  -  %$"); 
   	ObjectSet("FiboIn"+TF,OBJPROP_RAY,true);
   	ObjectSet("FiboIn"+TF,OBJPROP_BACK,true);
   }
   else
	   ObjectDelete("FiboIn"+TF);
}

//+------------------------------------------------------------------+
//| Indicator start function
//+------------------------------------------------------------------+

int start()
{
	int shift	= iBarShift(NULL,PERIOD_D1,Time[0]) + 1;	// yesterday
	double HiDay		= iHigh(NULL,PERIOD_D1,shift);
	double LoDay		= iLow (NULL,PERIOD_D1,shift);
	datetime StartDay	= iTime(NULL,PERIOD_D1,shift);
	
	double HiWeek = iHigh(NULL,PERIOD_W1,1);
	double LoWeek = iLow(NULL,PERIOD_W1,1);
	datetime StartWeek	= iTime(NULL,PERIOD_W1,1);
	
	double HiMonth = iHigh(NULL,PERIOD_MN1,1);
	double LoMonth = iLow(NULL,PERIOD_MN1,1);
	datetime StartMonth	= iTime(NULL,PERIOD_MN1,1);
	


	if(TimeDayOfWeek(StartDay)==0/*Sunday*/)
	{//Add fridays high and low
		HiDay = MathMax(HiDay,iHigh(NULL,PERIOD_D1,shift+1));
		LoDay = MathMin(LoDay,iLow(NULL,PERIOD_D1,shift+1));
	}

	double RangeDay = HiDay-LoDay;
	double RangeWeek = HiWeek-LoWeek;
	double RangeMonth = HiMonth-LoMonth;

	if(DailyKGFibo) DrawFibo(DailyFiboColor, StartDay, HiDay, LoDay, RangeDay, "Day");
	if(WeeklyKGFibo) DrawFibo(WeeklyFiboColor, StartWeek, HiWeek, LoWeek, RangeWeek, "Week");
	if(MonthlyKGFibo) DrawFibo(MonthlyFiboColor, StartMonth, HiMonth, LoMonth, RangeMonth, "Month");

	return(0);
}
//+------------------------------------------------------------------+

