//+------------------------------------------------------------------+
//|   #SpudFibo.mq4 - downloaded from ultimaforex.com
//+------------------------------------------------------------------+
#property  indicator_chart_window

extern string note1 = "Fibonacci colors";
extern color UpperFiboColor = clrMediumSeaGreen;
extern color MainFiboColor = clrSilver;
extern color LowerFiboColor = clrRed;
extern string note2 = "Draw main Fibonacci lines?";
extern bool  InnerFibs = true;
extern int textShiftBars = 20;

double HiPrice, LoPrice, Range;
datetime StartTime;

int init()
{
   return(0);
}

int deinit()
{
   ObjectDelete("FiboUp");
   ObjectDelete("FiboDn");
   ObjectDelete("FiboIn");
   return(0);
}


//+------------------------------------------------------------------+
//| Draw Fibo
//+------------------------------------------------------------------+

int DrawFibo()
{
	if(ObjectFind("FiboUpw") == -1)
		ObjectCreate("FiboUpw",OBJ_FIBO,0,StartTime,HiPrice+Range,StartTime,HiPrice);
	else
	{
		ObjectSet("FiboUpw",OBJPROP_TIME2, StartTime);
		ObjectSet("FiboUpw",OBJPROP_TIME1, StartTime);
		ObjectSet("FiboUpw",OBJPROP_PRICE1,HiPrice+Range);
		ObjectSet("FiboUpw",OBJPROP_PRICE2,HiPrice);
	}
   ObjectSet("FiboUpw",OBJPROP_LEVELCOLOR,UpperFiboColor);
   ObjectSet("FiboUpw",OBJPROP_FIBOLEVELS,13);
   //ObjectSet("FiboUpw",OBJPROP_FIRSTLEVEL+0,0.0);	ObjectSetFiboDescription("FiboUpw",0,"(100.0%) -  %$"); 
   //ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+1,0.236);	ObjectSetFiboDescription("FiboUp",1,"(123.6%) -  %$"); 
   ObjectSet("FiboUpw",OBJPROP_FIRSTLEVEL+2,0.272);	ObjectSetFiboDescription("FiboUpw",2,"(127.2%) -  %$"); 
   //ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+3,0.500);	ObjectSetFiboDescription("FiboUp",3,"(150.0%) -  %$"); 
   ObjectSet("FiboUpw",OBJPROP_FIRSTLEVEL+4,0.618);	ObjectSetFiboDescription("FiboUpw",4,"(161.8%) -  %$"); 
   //ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+5,0.764);	ObjectSetFiboDescription("FiboUp",5,"(176.4%) -  %$"); 
   ObjectSet("FiboUpw",OBJPROP_FIRSTLEVEL+6,1.000);	ObjectSetFiboDescription("FiboUpw",6,"(200.0%) -  %$"); 
   //ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+7,1.236);	ObjectSetFiboDescription("FiboUp",7,"(223.6%) -  %$"); 
   //ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+8,1.500);	ObjectSetFiboDescription("FiboUp",8,"(250.0%) -  %$"); 
   ObjectSet("FiboUpw",OBJPROP_FIRSTLEVEL+9,1.618);	ObjectSetFiboDescription("FiboUpw",9,"(261.8%) -  %$"); 
   //ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+10,2.000);	ObjectSetFiboDescription("FiboUp",10,"(300.0%) -  %$"); 
   //ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+11,2.500);	ObjectSetFiboDescription("FiboUp",11,"(350.0%) -  %$"); 
   //ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+12,3.000);	ObjectSetFiboDescription("FiboUp",12,"(400.0%) -  %$"); 
   //ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+13,3.500);	ObjectSetFiboDescription("FiboUp",13,"(450.0%) -  %$"); 
   //ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+14,4.000);	ObjectSetFiboDescription("FiboUp",14,"(500.0%) -  %$"); 
   ObjectSet("FiboUpw",OBJPROP_RAY,false);
   ObjectSet("FiboUpw",OBJPROP_BACK,true);

	if(ObjectFind("FiboDnw") == -1)
		ObjectCreate("FiboDnw",OBJ_FIBO,0,StartTime,LoPrice-Range,StartTime,LoPrice);
	else
	{
		ObjectSet("FiboDnw",OBJPROP_TIME2, StartTime);
		ObjectSet("FiboDnw",OBJPROP_TIME1, StartTime);
		ObjectSet("FiboDnw",OBJPROP_PRICE1,LoPrice-Range);
		ObjectSet("FiboDnw",OBJPROP_PRICE2,LoPrice);
	}
   ObjectSet("FiboDnw",OBJPROP_LEVELCOLOR,LowerFiboColor); 
   ObjectSet("FiboDnw",OBJPROP_FIBOLEVELS,19);
   //ObjectSet("FiboDnw",OBJPROP_FIRSTLEVEL+0,0.0);	ObjectSetFiboDescription("FiboDnw",0,"(0.0%) -  %$"); 
   //ObjectSet("FiboDn",OBJPROP_FIRSTLEVEL+1,0.236);	ObjectSetFiboDescription("FiboDn",1,"(-123.6%) -  %$"); 
   ObjectSet("FiboDnw",OBJPROP_FIRSTLEVEL+2,0.272);	ObjectSetFiboDescription("FiboDnw",2,"(-127.2%) -  %$"); 
   //ObjectSet("FiboDn",OBJPROP_FIRSTLEVEL+3,0.500);	ObjectSetFiboDescription("FiboDn",3,"(-150.0%) -  %$"); 
   ObjectSet("FiboDnw",OBJPROP_FIRSTLEVEL+4,0.618);	ObjectSetFiboDescription("FiboDnw",4,"(-161.8%) -  %$"); 
   //ObjectSet("FiboDn",OBJPROP_FIRSTLEVEL+5,0.764);	ObjectSetFiboDescription("FiboDn",5,"(-176.4%) -  %$"); 
   ObjectSet("FiboDnw",OBJPROP_FIRSTLEVEL+6,1.000);	ObjectSetFiboDescription("FiboDnw",6,"(-200.0%) -  %$"); 
   //ObjectSet("FiboDn",OBJPROP_FIRSTLEVEL+7,1.236);	ObjectSetFiboDescription("FiboDn",7,"(-223.6%) -  %$"); 
   //ObjectSet("FiboDn",OBJPROP_FIRSTLEVEL+8,1.382);	ObjectSetFiboDescription("FiboDn",8,"(-238.2%) -  %$"); 
   //ObjectSet("FiboDn",OBJPROP_FIRSTLEVEL+9,1.500);	ObjectSetFiboDescription("FiboDn",9,"(-250.0%) -  %$"); 
   ObjectSet("FiboDnw",OBJPROP_FIRSTLEVEL+10,1.618);	ObjectSetFiboDescription("FiboDnw",10,"(-261.8%) -  %$"); 
   //ObjectSet("FiboDn",OBJPROP_FIRSTLEVEL+11,1.764);	ObjectSetFiboDescription("FiboDn",11,"(-176.4%) -  %$"); 
   //ObjectSet("FiboDn",OBJPROP_FIRSTLEVEL+12,2.000);	ObjectSetFiboDescription("FiboDn",12,"(-200.0%) -  %$"); 
   //ObjectSet("FiboDn",OBJPROP_FIRSTLEVEL+13,2.500);	ObjectSetFiboDescription("FiboDn",13,"(-250.0%) -  %$"); 
   //ObjectSet("FiboDn",OBJPROP_FIRSTLEVEL+14,3.000);	ObjectSetFiboDescription("FiboDn",14,"(-300.0%) -  %$"); 
   //ObjectSet("FiboDn",OBJPROP_FIRSTLEVEL+15,3.500);	ObjectSetFiboDescription("FiboDn",15,"(-350.0%) -  %$"); 
   //ObjectSet("FiboDn",OBJPROP_FIRSTLEVEL+16,4.000);	ObjectSetFiboDescription("FiboDn",16,"(-400.0%) -  %$"); 
   //ObjectSet("FiboDn",OBJPROP_FIRSTLEVEL+17,4.500);	ObjectSetFiboDescription("FiboDn",17,"(-450.0%) -  %$"); 
   //ObjectSet("FiboDn",OBJPROP_FIRSTLEVEL+18,5.000);	ObjectSetFiboDescription("FiboDn",18,"(-500.0%) -  %$"); 
   ObjectSet("FiboDnw",OBJPROP_RAY,false);
   ObjectSet("FiboDnw",OBJPROP_BACK,true);

   if(ObjectFind("FiboUp0w") !=0)
			ObjectCreate("FiboUp0w",OBJ_FIBO,0,StartTime,HiPrice,StartTime,LoPrice);
		else
		{
			ObjectSet("FiboUp0w",OBJPROP_TIME1, StartTime);
			ObjectSet("FiboUp0w",OBJPROP_TIME2, StartTime);
			ObjectSet("FiboUp0w",OBJPROP_PRICE1,HiPrice);
			ObjectSet("FiboUp0w",OBJPROP_PRICE2,LoPrice);
			
		}
   	ObjectSet("FiboUp0w",OBJPROP_LEVELCOLOR,clrGold); 
   	ObjectSet("FiboUp0w",OBJPROP_FIBOLEVELS,7);
   	ObjectSet("FiboUp0w",OBJPROP_FIRSTLEVEL+0,0.0);	   ObjectSetFiboDescription("FiboUp0w",0,"=="+"(0.0) -  %$"); 
   	ObjectSet("FiboUp0w",OBJPROP_FIRSTLEVEL+6,1.000);	ObjectSetFiboDescription("FiboUp0w",6,"=="+"(100) -  %$"); 
      ObjectSet("FiboUp0w",OBJPROP_RAY,false);
   	ObjectSet("FiboUp0w",OBJPROP_BACK,false);
   	
	if(InnerFibs)
	{
		if(ObjectFind("FiboInw") == -1)
			ObjectCreate("FiboInw",OBJ_FIBO,0,StartTime,HiPrice,StartTime,LoPrice);
		else
		{
			ObjectSet("FiboInw",OBJPROP_TIME2, StartTime);
			ObjectSet("FiboInw",OBJPROP_TIME1, StartTime);
			ObjectSet("FiboInw",OBJPROP_PRICE1,HiPrice);
			ObjectSet("FiboInw",OBJPROP_PRICE2,LoPrice);
		}
   	ObjectSet("FiboInw",OBJPROP_LEVELCOLOR,MainFiboColor); 
   	ObjectSet("FiboInw",OBJPROP_FIBOLEVELS,7);
   	//ObjectSet("FiboInw",OBJPROP_FIRSTLEVEL+0,0.0);	ObjectSetFiboDescription("FiboInw",0,"(0.0) -  %$"); 
   	ObjectSet("FiboInw",OBJPROP_FIRSTLEVEL+1,0.236);	ObjectSetFiboDescription("FiboInw",1,"(23.6) -  %$"); 
   	ObjectSet("FiboInw",OBJPROP_FIRSTLEVEL+2,0.382);	ObjectSetFiboDescription("FiboInw",2,"(38.2) -  %$"); 
   	ObjectSet("FiboInw",OBJPROP_FIRSTLEVEL+3,0.500);	ObjectSetFiboDescription("FiboInw",3,"(50.0) -  %$"); 
   	ObjectSet("FiboInw",OBJPROP_FIRSTLEVEL+4,0.618);	ObjectSetFiboDescription("FiboInw",4,"(61.8) -  %$"); 
   	ObjectSet("FiboInw",OBJPROP_FIRSTLEVEL+5,0.764);	ObjectSetFiboDescription("FiboInw",5,"(76.4) -  %$"); 
   	//ObjectSet("FiboInw",OBJPROP_FIRSTLEVEL+6,1.000);	ObjectSetFiboDescription("FiboInw",6,"(100.0) -  %$"); 
      ObjectSet("FiboInw",OBJPROP_RAY,false);
   	ObjectSet("FiboInw",OBJPROP_BACK,true);
   }
   else
	   ObjectDelete("FiboInw");
}

//+------------------------------------------------------------------+
//| Indicator start function
//+------------------------------------------------------------------+

int start()
{
	int shift	= iBarShift(NULL,PERIOD_W1,Time[0]) + 1;	// yesterday
	HiPrice		= iHigh(NULL,PERIOD_W1,shift);
	LoPrice		= iLow (NULL,PERIOD_W1,shift);
	StartTime	= Time[0]+textShiftBars*60*Period();

	if(TimeDayOfWeek(StartTime)==0/*Sunday*/)
	{//Add fridays high and low
		HiPrice = MathMax(HiPrice,iHigh(NULL,PERIOD_W1,shift));
		LoPrice = MathMin(LoPrice,iLow(NULL,PERIOD_W1,shift));
	}

	Range = HiPrice-LoPrice;

	DrawFibo();

	return(0);
}
//+------------------------------------------------------------------+

