//+------------------------------------------------------------------+
//|   #H4_Hi_Low_Middle.mq4
//|   Base from spudfibo.Upgrade by Darkkiller
//+------------------------------------------------------------------+
#property  indicator_chart_window

extern int       iPeriods=5; 
extern string note1 = "Resistance,Middle,Support colors";
extern color ResistanceColor = Red;
extern color SRMiddleColor = Gray;
extern color SupportColor = Blue;
extern string note2 = "Draw S/R middle?";
extern bool  SRMiddle = false;

double xRES, xSUP, Range;
datetime StartTime;

string tLabel01, tLabel02, tLabel03 ; 

int init()
{

  tLabel01 = "Resistance" + iPeriods ;
  tLabel02 = "Support" + iPeriods ;
  tLabel03 = "SRMiddle" + iPeriods ; 
  
   return(0);
}

int deinit()
{
   ObjectDelete(tLabel01);
   ObjectDelete(tLabel02);
   ObjectDelete(tLabel03);
   return(0);
}

//+------------------------------------------------------------------+
//| Draw Fibo
//+------------------------------------------------------------------+

int DrawFibo()
{
	if(ObjectFind(tLabel01) == -1)
		ObjectCreate(tLabel01,OBJ_FIBO,0,StartTime,xRES+Range,StartTime,xRES);
	else
	{
		ObjectSet(tLabel01,OBJPROP_TIME2, StartTime);
		ObjectSet(tLabel01,OBJPROP_TIME1, StartTime);
		ObjectSet(tLabel01,OBJPROP_PRICE1,xRES+Range);
		ObjectSet(tLabel01,OBJPROP_PRICE2,xRES);
	}
   ObjectSet(tLabel01,OBJPROP_LEVELCOLOR,ResistanceColor);
   ObjectSet(tLabel01,OBJPROP_FIBOLEVELS,1);
   ObjectSet(tLabel01,OBJPROP_FIRSTLEVEL+0,0.0);	
   ObjectSetFiboDescription(tLabel01,0,"RESISTANCE(" + iPeriods+ ") %$"); 
   ObjectSet(tLabel01,OBJPROP_RAY,true);
   ObjectSet(tLabel01,OBJPROP_BACK,true);

	if(ObjectFind(tLabel02) == -1)
		ObjectCreate(tLabel02,OBJ_FIBO,0,StartTime,xSUP-Range,StartTime,xSUP);
	else
	{
		ObjectSet(tLabel02,OBJPROP_TIME2, StartTime);
		ObjectSet(tLabel02,OBJPROP_TIME1, StartTime);
		ObjectSet(tLabel02,OBJPROP_PRICE1,xSUP-Range);
		ObjectSet(tLabel02,OBJPROP_PRICE2,xSUP);
	}
   ObjectSet(tLabel02,OBJPROP_LEVELCOLOR,SupportColor); 
   ObjectSet(tLabel02,OBJPROP_FIBOLEVELS,1);
   ObjectSet(tLabel02,OBJPROP_FIRSTLEVEL+0,0.0);	
   ObjectSetFiboDescription(tLabel02,0,"SUPPORT(" + iPeriods+ ") %$"); 

   ObjectSet(tLabel02,OBJPROP_RAY,true);
   ObjectSet(tLabel02,OBJPROP_BACK,true);

	if(SRMiddle)
	{
		if(ObjectFind(tLabel03) == -1)
			ObjectCreate(tLabel03,OBJ_FIBO,0,StartTime,xRES,StartTime+PERIOD_H4*60,xSUP);
		else
		{
			ObjectSet(tLabel03,OBJPROP_TIME2, StartTime);
			ObjectSet(tLabel03,OBJPROP_TIME1, StartTime);
			ObjectSet(tLabel03,OBJPROP_PRICE1,xRES);
			ObjectSet(tLabel03,OBJPROP_PRICE2,xSUP);
		}
   	ObjectSet(tLabel03,OBJPROP_LEVELCOLOR,SRMiddleColor); 
   	ObjectSet(tLabel03,OBJPROP_FIBOLEVELS,1);
   
   	ObjectSet(tLabel03,OBJPROP_FIRSTLEVEL+0,0.500);	
   	ObjectSetFiboDescription(tLabel03,0,"S/R MIDDLE(" + iPeriods+ ") %$"); 

   	ObjectSet(tLabel03,OBJPROP_RAY,true);
   	ObjectSet(tLabel03,OBJPROP_BACK,true);
   }
   else
	   ObjectDelete(tLabel03);
}

//+------------------------------------------------------------------+
//| Indicator start function
//+------------------------------------------------------------------+

int start()
{
 
   xRES = High[Highest(NULL,0,MODE_HIGH,iPeriods,0)]; 
   xSUP = Low[Lowest(NULL,0,MODE_LOW,iPeriods,0)]; 

	Range = xRES-xSUP;

	DrawFibo();

	return(0);
}
//+------------------------------------------------------------------+

