Navigation´╝ÜHome > Content >

SpudFibo_mtf_1.01.mq4

Time: 2012-03-03 | Download file:SpudFibo_mtf_1.01.mq4

//+------------------------------------------------------------------+
//|   #SpudFibo.mq4 - downloaded from ultimaforex.com
//+------------------------------------------------------------------+

/*--------------------------------------------------------------------
#SpudFibo_v2:

For a "cleaner" look, this version completely separates the three groups
of Fibos from each other, and changes the diagonal line on the main 
Fibo to a vertical line, to match the others.  An indicator ON/OFF
"switch" has been added so that the indicator can remain in the list of
chart indicators, but be turned on/off by selecting "true" or "false" in 
the Indcator Window.
                                                       - Traderathome
----------------------------------------------------------------------*/  

#property  indicator_chart_window

extern int    TimeFrame      = 1440;
extern bool   Indicator_On?  = true;
extern color  UpperFiboColor = RoyalBlue;
extern bool   UpperFiboOn    = true;
extern color  MainFiboColor  = DarkOliveGreen;
extern bool   MainFiboOn     = true;
extern color  LowerFiboColor = IndianRed;
extern bool   LowerFiboOn    = true;
extern string UniqueID       = "SpudFibo1";
extern int    LookBack       = 1;

double HiPrice, LoPrice, Range;
datetime StartTime;

//+------------------------------------------------------------------+
//| Indicator Initialization                                         |
//+------------------------------------------------------------------+
int init()
{
   return(0);
}

//+------------------------------------------------------------------+
//| Indicator De-initializtion                                       |
//+------------------------------------------------------------------+
int deinit()
{
   ObjectDelete(UniqueID+":FiboUp");
   ObjectDelete(UniqueID+":FiboDn");
   ObjectDelete(UniqueID+":FiboIn");
   return(0);
}

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

int start()
{
   if (Indicator_On? == false){return(0);}
   
	int shift	= iBarShift(NULL,TimeFrame,Time[0]) + LookBack;	// yesterday
	HiPrice		= iHigh(NULL,TimeFrame,shift);
	LoPrice		= iLow (NULL,TimeFrame,shift);
	StartTime	= iTime(NULL,TimeFrame,shift);

	if(TimeDayOfWeek(StartTime)==0/*Sunday*/)
	{//Add fridays high and low
		HiPrice = MathMax(HiPrice,iHigh(NULL,TimeFrame,shift+1));
		LoPrice = MathMin(LoPrice,iLow(NULL,TimeFrame,shift+1));
	}

	Range = HiPrice-LoPrice;
	DrawFibo();
	return(0);
}

//+------------------------------------------------------------------+
//| Indicator Draw Fibo Sub-routine                                  |
//+------------------------------------------------------------------+

int DrawFibo()
{
   if(UpperFiboOn)
   {
	if(ObjectFind(UniqueID+":FiboUp") == -1)
	 //ObjectCreate(UniqueID+":FiboUp",OBJ_FIBO,0,StartTime,HiPrice+Range,StartTime,HiPrice);
		ObjectCreate(UniqueID+":FiboUp",OBJ_FIBO,0,StartTime,HiPrice+Range,StartTime,HiPrice+Range*0.236);
	else
	{
		ObjectSet(UniqueID+":FiboUp",OBJPROP_TIME2, StartTime);
		ObjectSet(UniqueID+":FiboUp",OBJPROP_TIME1, StartTime);
		ObjectSet(UniqueID+":FiboUp",OBJPROP_PRICE1,HiPrice+Range);
	 //ObjectSet(UniqueID+":FiboUp",OBJPROP_PRICE2,HiPrice);
		ObjectSet(UniqueID+":FiboUp",OBJPROP_PRICE2,HiPrice+Range*0.236);
	}
   ObjectSet(UniqueID+":FiboUp",OBJPROP_LEVELCOLOR,UpperFiboColor);
   ObjectSet(UniqueID+":FiboUp",OBJPROP_FIBOLEVELS,18);   
   ObjectSet(UniqueID+":FiboUp",OBJPROP_FIRSTLEVEL+ 0,0.000); ObjectSetFiboDescription(UniqueID+":FiboUp",0,"(123.6%) -  %$");
   ObjectSet(UniqueID+":FiboUp",OBJPROP_FIRSTLEVEL+ 1,0.189); ObjectSetFiboDescription(UniqueID+":FiboUp",1,"(138.2%) -  %$");
   ObjectSet(UniqueID+":FiboUp",OBJPROP_FIRSTLEVEL+ 2,0.346); ObjectSetFiboDescription(UniqueID+":FiboUp",2,"(150.0%) -  %$"); 
   ObjectSet(UniqueID+":FiboUp",OBJPROP_FIRSTLEVEL+ 3,0.500); ObjectSetFiboDescription(UniqueID+":FiboUp",3,"(161.8%) -  %$"); 
   ObjectSet(UniqueID+":FiboUp",OBJPROP_FIRSTLEVEL+ 4,0.691); ObjectSetFiboDescription(UniqueID+":FiboUp",4,"(176.4%) -  %$"); 
   ObjectSet(UniqueID+":FiboUp",OBJPROP_FIRSTLEVEL+ 5,1.000); ObjectSetFiboDescription(UniqueID+":FiboUp",5,"(200.0%) -  %$"); 
   ObjectSet(UniqueID+":FiboUp",OBJPROP_FIRSTLEVEL+ 6,1.311); ObjectSetFiboDescription(UniqueID+":FiboUp",6,"(223.6%) -  %$"); 
   ObjectSet(UniqueID+":FiboUp",OBJPROP_FIRSTLEVEL+ 7,1.500); ObjectSetFiboDescription(UniqueID+":FiboUp",7,"(238.2%) -  %$");
   ObjectSet(UniqueID+":FiboUp",OBJPROP_FIRSTLEVEL+ 8,1.654); ObjectSetFiboDescription(UniqueID+":FiboUp",8,"(250.0%) -  %$"); 
   ObjectSet(UniqueID+":FiboUp",OBJPROP_FIRSTLEVEL+ 9,1.810); ObjectSetFiboDescription(UniqueID+":FiboUp",9,"(261.8%) -  %$"); 
   ObjectSet(UniqueID+":FiboUp",OBJPROP_FIRSTLEVEL+10,2.000); ObjectSetFiboDescription(UniqueID+":FiboUp",10,"(276.4%) -  %$");
   ObjectSet(UniqueID+":FiboUp",OBJPROP_FIRSTLEVEL+11,2.309); ObjectSetFiboDescription(UniqueID+":FiboUp",11,"(300.0%) -  %$"); 
   ObjectSet(UniqueID+":FiboUp",OBJPROP_FIRSTLEVEL+12,2.960); ObjectSetFiboDescription(UniqueID+":FiboUp",12,"(350.0%) -  %$"); 
   ObjectSet(UniqueID+":FiboUp",OBJPROP_FIRSTLEVEL+13,3.618); ObjectSetFiboDescription(UniqueID+":FiboUp",13,"(400.0%) -  %$"); 
   ObjectSet(UniqueID+":FiboUp",OBJPROP_FIRSTLEVEL+14,4.272); ObjectSetFiboDescription(UniqueID+":FiboUp",14,"(450.0%) -  %$"); 
   ObjectSet(UniqueID+":FiboUp",OBJPROP_FIRSTLEVEL+15,4.927); ObjectSetFiboDescription(UniqueID+":FiboUp",15,"(500.0%) -  %$"); 
   ObjectSet(UniqueID+":FiboUp",OBJPROP_FIRSTLEVEL+16,5.578); ObjectSetFiboDescription(UniqueID+":FiboUp",16,"(550.0%) -  %$"); 
   ObjectSet(UniqueID+":FiboUp",OBJPROP_FIRSTLEVEL+17,6.236); ObjectSetFiboDescription(UniqueID+":FiboUp",17,"(600.0%) -  %$"); 
   ObjectSet(UniqueID+":FiboUp",OBJPROP_RAY,true);
   ObjectSet(UniqueID+":FiboUp",OBJPROP_BACK,true);
   }

   //-----------------------------------------------------------------
	if(MainFiboOn)
	{
	if(ObjectFind(UniqueID+":FiboIn") == -1)
	 //ObjectCreate(UniqueID+":FiboIn",OBJ_FIBO,0,StartTime,HiPrice,StartTime+PERIOD_D1*60,LoPrice); //diagonal line
		ObjectCreate(UniqueID+":FiboIn",OBJ_FIBO,0,StartTime,HiPrice,StartTime,LoPrice);              //vertical line
	else
	{
		ObjectSet(UniqueID+":FiboIn",OBJPROP_TIME2, StartTime);
	 //ObjectSet(UniqueID+":FiboIn",OBJPROP_TIME1, StartTime+PERIOD_D1*60); //creates diagonal line
		ObjectSet(UniqueID+":FiboIn",OBJPROP_TIME1, StartTime);              //creates vertical line
		ObjectSet(UniqueID+":FiboIn",OBJPROP_PRICE1,HiPrice);
		ObjectSet(UniqueID+":FiboIn",OBJPROP_PRICE2,LoPrice);
	}
   ObjectSet(UniqueID+":FiboIn",OBJPROP_LEVELCOLOR,MainFiboColor); 
   ObjectSet(UniqueID+":FiboIn",OBJPROP_FIBOLEVELS,7);
   ObjectSet(UniqueID+":FiboIn",OBJPROP_FIRSTLEVEL+0,0.000);	ObjectSetFiboDescription(UniqueID+":FiboIn",0,"Daily LOW  (  0  ) -  %$"); 
   ObjectSet(UniqueID+":FiboIn",OBJPROP_FIRSTLEVEL+1,0.236);	ObjectSetFiboDescription(UniqueID+":FiboIn",1,"(23.6) -  %$"); 
   ObjectSet(UniqueID+":FiboIn",OBJPROP_FIRSTLEVEL+2,0.382);	ObjectSetFiboDescription(UniqueID+":FiboIn",2,"(38.2) -  %$"); 
   ObjectSet(UniqueID+":FiboIn",OBJPROP_FIRSTLEVEL+3,0.500);	ObjectSetFiboDescription(UniqueID+":FiboIn",3,"(50.0) -  %$"); 
   ObjectSet(UniqueID+":FiboIn",OBJPROP_FIRSTLEVEL+4,0.618);	ObjectSetFiboDescription(UniqueID+":FiboIn",4,"(61.8) -  %$"); 
   ObjectSet(UniqueID+":FiboIn",OBJPROP_FIRSTLEVEL+5,0.764);	ObjectSetFiboDescription(UniqueID+":FiboIn",5,"(76.4) -  %$"); 
   ObjectSet(UniqueID+":FiboIn",OBJPROP_FIRSTLEVEL+6,1.000);	ObjectSetFiboDescription(UniqueID+":FiboIn",6,"Daily HIGH  (100) -  %$"); 
   ObjectSet(UniqueID+":FiboIn",OBJPROP_RAY,true);
   ObjectSet(UniqueID+":FiboIn",OBJPROP_BACK,true);
   }


   //-----------------------------------------------------------------
   if(LowerFiboOn)
   {
	if(ObjectFind(UniqueID+":FiboDn") == -1)
	 //ObjectCreate(UniqueID+":FiboDn",OBJ_FIBO,0,StartTime,LoPrice-Range,StartTime,LoPrice);
		ObjectCreate(UniqueID+":FiboDn",OBJ_FIBO,0,StartTime,LoPrice-Range,StartTime,LoPrice-Range*0.236);
	else
	{
		ObjectSet(UniqueID+":FiboDn",OBJPROP_TIME2, StartTime);
		ObjectSet(UniqueID+":FiboDn",OBJPROP_TIME1, StartTime);
		ObjectSet(UniqueID+":FiboDn",OBJPROP_PRICE1,LoPrice-Range);
	 //ObjectSet(UniqueID+":FiboDn",OBJPROP_PRICE1,LoPrice);
		ObjectSet(UniqueID+":FiboDn",OBJPROP_PRICE2,LoPrice-Range*0.236);
	}
   ObjectSet(UniqueID+":FiboDn",OBJPROP_LEVELCOLOR,LowerFiboColor); 
   ObjectSet(UniqueID+":FiboDn",OBJPROP_FIBOLEVELS,18);   
   ObjectSet(UniqueID+":FiboDn",OBJPROP_FIRSTLEVEL+ 0,0.000); ObjectSetFiboDescription(UniqueID+":FiboDn", 0,"(-23.6%) -  %$"); 
   ObjectSet(UniqueID+":FiboDn",OBJPROP_FIRSTLEVEL+ 1,0.189); ObjectSetFiboDescription(UniqueID+":FiboDn", 1,"(-38.2%) -  %$"); 
   ObjectSet(UniqueID+":FiboDn",OBJPROP_FIRSTLEVEL+ 2,0.346); ObjectSetFiboDescription(UniqueID+":FiboDn", 2,"(-50.0%) -  %$"); 
   ObjectSet(UniqueID+":FiboDn",OBJPROP_FIRSTLEVEL+ 3,0.500); ObjectSetFiboDescription(UniqueID+":FiboDn", 3,"(-61.8%) -  %$"); 
   ObjectSet(UniqueID+":FiboDn",OBJPROP_FIRSTLEVEL+ 4,0.691); ObjectSetFiboDescription(UniqueID+":FiboDn", 4,"(-76.4%) -  %$"); 
   ObjectSet(UniqueID+":FiboDn",OBJPROP_FIRSTLEVEL+ 5,1.000); ObjectSetFiboDescription(UniqueID+":FiboDn", 5,"(-100.0%) -  %$"); 
   ObjectSet(UniqueID+":FiboDn",OBJPROP_FIRSTLEVEL+ 6,1.311); ObjectSetFiboDescription(UniqueID+":FiboDn", 6,"(-123.6%) -  %$"); 
   ObjectSet(UniqueID+":FiboDn",OBJPROP_FIRSTLEVEL+ 7,1.500); ObjectSetFiboDescription(UniqueID+":FiboDn", 7,"(-138.2%) -  %$"); 
   ObjectSet(UniqueID+":FiboDn",OBJPROP_FIRSTLEVEL+ 8,1.654); ObjectSetFiboDescription(UniqueID+":FiboDn", 8,"(-150.0%) -  %$"); 
   ObjectSet(UniqueID+":FiboDn",OBJPROP_FIRSTLEVEL+ 9,1.810); ObjectSetFiboDescription(UniqueID+":FiboDn", 9,"(-161.8%) -  %$"); 
   ObjectSet(UniqueID+":FiboDn",OBJPROP_FIRSTLEVEL+10,2.000); ObjectSetFiboDescription(UniqueID+":FiboDn",10,"(-176.4%) -  %$"); 
   ObjectSet(UniqueID+":FiboDn",OBJPROP_FIRSTLEVEL+11,2.309); ObjectSetFiboDescription(UniqueID+":FiboDn",11,"(-200.0%) -  %$"); 
   ObjectSet(UniqueID+":FiboDn",OBJPROP_FIRSTLEVEL+12,2.960); ObjectSetFiboDescription(UniqueID+":FiboDn",12,"(-250.0%) -  %$"); 
   ObjectSet(UniqueID+":FiboDn",OBJPROP_FIRSTLEVEL+13,3.618); ObjectSetFiboDescription(UniqueID+":FiboDn",13,"(-300.0%) -  %$"); 
   ObjectSet(UniqueID+":FiboDn",OBJPROP_FIRSTLEVEL+14,4.272); ObjectSetFiboDescription(UniqueID+":FiboDn",14,"(-350.0%) -  %$"); 
   ObjectSet(UniqueID+":FiboDn",OBJPROP_FIRSTLEVEL+15,4.927); ObjectSetFiboDescription(UniqueID+":FiboDn",15,"(-400.0%) -  %$"); 
   ObjectSet(UniqueID+":FiboDn",OBJPROP_FIRSTLEVEL+16,5.578); ObjectSetFiboDescription(UniqueID+":FiboDn",16,"(-450.0%) -  %$"); 
   ObjectSet(UniqueID+":FiboDn",OBJPROP_FIRSTLEVEL+17,6.236); ObjectSetFiboDescription(UniqueID+":FiboDn",17,"(-500.0%) -  %$"); 
   ObjectSet(UniqueID+":FiboDn",OBJPROP_RAY,true);
   ObjectSet(UniqueID+":FiboDn",OBJPROP_BACK,true);
   } 
}

//+------------------------------------------------------------------+
//| Indicator - End of Program                                       |
//+------------------------------------------------------------------+

Recommend