//+------------------------------------------------------------------+
//|   #SpudFibo.mq4 - downloaded from ultimaforex.com
//+------------------------------------------------------------------+
#property  indicator_chart_window

extern string note1 = "Fibonacci colors";
extern color DailyFiboColor = Lime;
extern color WeeklyFiboColor = Magenta;
extern color MonthlyFiboColor = Aqua;
extern string note2 = "Draw main Fibonacci lines?";
bool  InnerFibs = true;

extern bool DailyKGFibo = true;
extern bool WeeklyKGFibo = true;
extern bool MonthlyKGFibo = true;

// Added by Newman
extern int DailyFiboTime1=3;
extern int DailyFiboTime2=5;
extern int WeeklyFiboTime1=2;
extern int WeeklyFiboTime2=5;
extern int MonthlyFiboTime1=1;
extern int MonthlyFiboTime2=5;



/*
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 Time1, datetime Time2,double HiPrice, double LoPrice, string TF)
{
	if(InnerFibs)
	{
		if(ObjectFind("FiboIn"+TF) == -1)
			ObjectCreate("FiboIn"+TF,OBJ_FIBO,0,Time[Time1],HiPrice,Time[Time2],LoPrice);
		else
		{
			ObjectSet("FiboIn"+TF,OBJPROP_TIME2, Time[Time1]);
			ObjectSet("FiboIn"+TF,OBJPROP_TIME1, Time[Time2]);
			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+" Lowest Break TP4) - %$");
   	ObjectSet("FiboIn"+TF,OBJPROP_FIRSTLEVEL+1,-0.75);	ObjectSetFiboDescription("FiboIn"+TF,1,"("+TF+" Lowest Break TP3) - %$");
   	ObjectSet("FiboIn"+TF,OBJPROP_FIRSTLEVEL+2,-0.50);	ObjectSetFiboDescription("FiboIn"+TF,2,"("+TF+" Lowest Break TP2) - %$");
   	ObjectSet("FiboIn"+TF,OBJPROP_FIRSTLEVEL+3,-0.25);	ObjectSetFiboDescription("FiboIn"+TF,3,"("+TF+" Lowest Break TP1) - %$");
   	ObjectSet("FiboIn"+TF,OBJPROP_FIRSTLEVEL+4,0.0);	ObjectSetFiboDescription("FiboIn"+TF,4,"("+TF+" Lowest Price) - %$"); 
   	ObjectSet("FiboIn"+TF,OBJPROP_FIRSTLEVEL+5,0.25);	ObjectSetFiboDescription("FiboIn"+TF,5,"("+TF+" Sellers Balance) - %$"); 
   	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+" Buyers Balance) - %$"); 
   	ObjectSet("FiboIn"+TF,OBJPROP_FIRSTLEVEL+8,1.00);	ObjectSetFiboDescription("FiboIn"+TF,8,"("+TF+" Highest price)  - %$");
   	ObjectSet("FiboIn"+TF,OBJPROP_FIRSTLEVEL+9,1.25);	ObjectSetFiboDescription("FiboIn"+TF,9,"("+TF+" Highest Break TP1) - %$");
   	ObjectSet("FiboIn"+TF,OBJPROP_FIRSTLEVEL+10,1.50);	ObjectSetFiboDescription("FiboIn"+TF,10,"("+TF+" Highest Break TP2) - %$");
   	ObjectSet("FiboIn"+TF,OBJPROP_FIRSTLEVEL+11,1.75);	ObjectSetFiboDescription("FiboIn"+TF,11,"("+TF+" Highest Break TP3) - %$");
   	ObjectSet("FiboIn"+TF,OBJPROP_FIRSTLEVEL+12,2.0);	ObjectSetFiboDescription("FiboIn"+TF,12,"("+TF+" Highest Break TP4) - %$"); 
   	ObjectSet("FiboIn"+TF,OBJPROP_RAY,false);
   	ObjectSet("FiboIn"+TF,OBJPROP_BACK,true);
   	ObjectSet("FiboIn"+TF,OBJPROP_COLOR, CLR_NONE);
   }
   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");
*/
// Modified by Newman
	if(DailyKGFibo) DrawFibo(DailyFiboColor, DailyFiboTime1,DailyFiboTime2, HiDay, LoDay,"Day");
	if(WeeklyKGFibo) DrawFibo(WeeklyFiboColor, WeeklyFiboTime1,WeeklyFiboTime2,HiWeek, LoWeek,"Week");
	if(MonthlyKGFibo) DrawFibo(MonthlyFiboColor, MonthlyFiboTime1,MonthlyFiboTime2,HiMonth, LoMonth,"Month");
	
	return(0);
}
//+------------------------------------------------------------------+