//+------------------------------------------------------------------+
//| #BobokusFibo.mq4 modified from
//| #SpudFibo.mq4
//| http://www.forexfactory.com/showthread.php?t=50767
//+------------------------------------------------------------------+
#property  indicator_chart_window

#property indicator_buffers 3
//#property indicator_color1 OrangeRed 
//#property indicator_color2 OrangeRed 
//#property indicator_color3 OrangeRed 


extern color MLongFibo = Gold;
extern int MLongFibo_Width = 1;
extern int MLongFibo_Style = 0;
extern color MShortFibo = Gold;
extern int MShortFibo_Width = 1;
extern int MShortFibo_Style = 0;
extern color MonthlyFibo = Gold;
extern int MonthlyFibo_Width = 1;
extern int MonthlyFibo_Style = 0;



double HiPrice, LoPrice, Range;
datetime StartTime;

int init()
{
   return(0);
}

int deinit()
{
   ObjectDelete("LongFibo2");
   ObjectDelete("ShortFibo2");
   ObjectDelete("MNFibo2");
   return(0);
}

//+------------------------------------------------------------------+
//| Draw Fibo
//+------------------------------------------------------------------+

int DrawFibo()
{
	if(ObjectFind("LongFibo2") == -1)
		ObjectCreate("LongFibo2",OBJ_FIBO,0,StartTime,HiPrice+Range,StartTime,HiPrice);
	else
	{
		ObjectSet("LongFibo2",OBJPROP_TIME2, StartTime);
		ObjectSet("LongFibo2",OBJPROP_TIME1, StartTime);
		ObjectSet("LongFibo2",OBJPROP_PRICE1,HiPrice+Range);
		ObjectSet("LongFibo2",OBJPROP_PRICE2,HiPrice);
	}
   ObjectSet("LongFibo2",OBJPROP_LEVELCOLOR,MLongFibo);
   ObjectSet("LongFibo2",OBJPROP_LEVELWIDTH,MLongFibo_Width);
   ObjectSet("LongFibo2",OBJPROP_LEVELSTYLE,MLongFibo_Style);
   ObjectSet("LongFibo2",OBJPROP_FIBOLEVELS,2);
   ObjectSet("LongFibo2",OBJPROP_FIRSTLEVEL+0,0.34);	ObjectSetFiboDescription("LongFibo2",0,"Monthly  Long Target 1 -  %$"); 
   ObjectSet("LongFibo2",OBJPROP_FIRSTLEVEL+1,0.55);	ObjectSetFiboDescription("LongFibo2",1,"Monthly  Long Target 2 -  %$"); 
   ObjectSet("LongFibo2",OBJPROP_RAY,true);
   ObjectSet("LongFibo2",OBJPROP_BACK,true);

	if(ObjectFind("ShortFibo2") == -1)
		ObjectCreate("ShortFibo2",OBJ_FIBO,0,StartTime,LoPrice-Range,StartTime,LoPrice);
	else
	{
		ObjectSet("ShortFibo2",OBJPROP_TIME2, StartTime);
		ObjectSet("ShortFibo2",OBJPROP_TIME1, StartTime);
		ObjectSet("ShortFibo2",OBJPROP_PRICE1,LoPrice-Range);
		ObjectSet("ShortFibo2",OBJPROP_PRICE2,LoPrice);
	}
   ObjectSet("ShortFibo2",OBJPROP_LEVELCOLOR,MShortFibo); 
   ObjectSet("ShortFibo2",OBJPROP_LEVELWIDTH,MShortFibo_Width);
   ObjectSet("ShortFibo2",OBJPROP_LEVELSTYLE,MShortFibo_Style);
   ObjectSet("ShortFibo2",OBJPROP_FIBOLEVELS,2);
   ObjectSet("ShortFibo2",OBJPROP_FIRSTLEVEL+0,0.34);	ObjectSetFiboDescription("ShortFibo2",0,"Monthly  Short Target 1 -  %$"); 
   ObjectSet("ShortFibo2",OBJPROP_FIRSTLEVEL+1,0.55);	ObjectSetFiboDescription("ShortFibo2",1,"Monthly  Short Target 2 -  %$"); 
   ObjectSet("ShortFibo2",OBJPROP_RAY,true);
   ObjectSet("ShortFibo2",OBJPROP_BACK,true);

		if(ObjectFind("MN        Fibo2") == -1)
			ObjectCreate("MN        Fibo2",OBJ_FIBO,0,StartTime,HiPrice,StartTime+PERIOD_MN1*60,LoPrice);
		else
		{
			ObjectSet("MN        Fibo2",OBJPROP_TIME2, StartTime);
			ObjectSet("MN        Fibo2",OBJPROP_TIME1, StartTime+PERIOD_MN1*60);
			ObjectSet("MN        Fibo2",OBJPROP_PRICE1,HiPrice);
			ObjectSet("MN        Fibo2",OBJPROP_PRICE2,LoPrice);
		}
   	ObjectSet("MN        Fibo2",OBJPROP_LEVELCOLOR,MonthlyFibo); 
   	ObjectSet("MN        Fibo2",OBJPROP_LEVELWIDTH,MonthlyFibo_Width);
      ObjectSet("MN        Fibo2",OBJPROP_LEVELSTYLE,MonthlyFibo_Style);
   	ObjectSet("MN        Fibo2",OBJPROP_FIBOLEVELS,7);
   	ObjectSet("MN        Fibo2",OBJPROP_FIRSTLEVEL+0,0.0);	ObjectSetFiboDescription("MN        Fibo2",0,"Monthly  Low -  %$"); 
   	ObjectSet("MN        Fibo2",OBJPROP_FIRSTLEVEL+1,0.191);	ObjectSetFiboDescription("MN        Fibo2",1,"Monthly  S1 -  %$"); 
   	ObjectSet("MN        Fibo2",OBJPROP_FIRSTLEVEL+2,0.382);	ObjectSetFiboDescription("MN        Fibo2",2,"Monthly  Short -  %$"); 
   	ObjectSet("MN        Fibo2",OBJPROP_FIRSTLEVEL+3,0.500);	ObjectSetFiboDescription("MN        Fibo2",3,"Monthly  Pivot -  %$"); 
   	ObjectSet("MN        Fibo2",OBJPROP_FIRSTLEVEL+4,0.618);	ObjectSetFiboDescription("MN        Fibo2",4,"Monthly  Long -  %$"); 
   	ObjectSet("MN        Fibo2",OBJPROP_FIRSTLEVEL+5,0.809);	ObjectSetFiboDescription("MN        Fibo2",5,"Monthly  R1 -  %$"); 
   	ObjectSet("MN        Fibo2",OBJPROP_FIRSTLEVEL+6,1.000);	ObjectSetFiboDescription("MN        Fibo2",6,"Monthly  High -  %$"); 
   	ObjectSet("MN        Fibo2",OBJPROP_RAY,true);
   	ObjectSet("MN        Fibo2",OBJPROP_BACK,true);
   return(0);
   }

//+------------------------------------------------------------------+
//| Indicator start function
//+------------------------------------------------------------------+

int start()
{
	int shift	= iBarShift(NULL,PERIOD_MN1,Time[0]) + 1;	// yesterday
	HiPrice		= iHigh(NULL,PERIOD_MN1,shift);
	LoPrice		= iLow (NULL,PERIOD_MN1,shift);
	StartTime	= iTime(NULL,PERIOD_MN1,shift);

	if(TimeDayOfWeek(StartTime)==0/*Sunday*/)
	{//Add fridays high and low
		HiPrice = MathMax(HiPrice,iHigh(NULL,PERIOD_MN1,shift+1));
		LoPrice = MathMin(LoPrice,iLow(NULL,PERIOD_MN1,shift+1));
	}

	Range = HiPrice-LoPrice;

	DrawFibo();

	return(0);
}
//+------------------------------------------------------------------+

