#SpudFibo_007

Download script
#SpudFibo_007

This script is designed to automatically calculate and display Fibonacci retracement levels on your trading chart based on daily price action. Rather than requiring you to manually select highs and lows, the tool automates this process by referencing historical data from the previous day's trading session.

How it Works

1. Data Identification The script automatically looks back at the Daily (D1) timeframe to identify the highest price point and the lowest price point reached during the previous trading day. It is specifically programmed to handle weekend gaps; if the current day is Sunday, it intelligently expands its search to include Friday's data to ensure the range remains accurate.

2. Dynamic Fibonacci Mapping Once the high and low points of the previous period are identified, the script calculates the "Range" (the total distance between the top and bottom). It then projects three distinct types of Fibonacci levels onto your chart:

  • Upward Projection: Highlights levels based on a projected upward movement. These are labeled with percentage markers to help identify potential resistance zones.
  • Downward Projection: Highlights levels based on a projected downward movement, providing visual cues for potential support zones.
  • Inner Fibonacci (Optional): If enabled in the settings, the script draws an "Inner" set of levels that maps the specific price action occurring between the high and low points of that day's range.

3. Visual Presentation The tool is designed to be visually organized for easy reading:

  • Color Coding: It uses distinct colors (Blue, Green, and Red) to separate the different Fibonacci types, making it easier to distinguish between upward and downward trends at a glance.
  • Automatic Updates: The script constantly refreshes these levels so that as new days begin, the tool automatically updates to reflect the most recent daily price data.
  • Clean Layout: It utilizes "background" properties to ensure the lines do not clutter your primary price candles, keeping your chart clean and professional.

Key Benefits

Instead of manually drawing lines every time a new day starts, this script provides a consistent, objective framework for identifying key support and resistance levels. By automating the selection of the previous day's high and low, it removes human error and ensures that your Fibonacci levels are always synchronized with the most recent significant market price range.

Price Data Components
Series array that contains the highest prices of each barSeries array that contains the lowest prices of each bar
10 Views
0 Downloads
0 Favorites
#SpudFibo_007
//+------------------------------------------------------------------+
//|   #SpudFibo.mq4
//+------------------------------------------------------------------+
#property  indicator_chart_window

extern color UpColor = Blue;
extern color InColor = Green;
extern color DnColor = Red;
extern bool  InnerFibs = true;

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("FiboUp") == -1)
		ObjectCreate("FiboUp",OBJ_FIBO,0,StartTime,HiPrice+Range,StartTime,HiPrice);
	else
	{
		ObjectSet("FiboUp",OBJPROP_TIME2, StartTime);
		ObjectSet("FiboUp",OBJPROP_TIME1, StartTime);
		ObjectSet("FiboUp",OBJPROP_PRICE1,HiPrice+Range);
		ObjectSet("FiboUp",OBJPROP_PRICE2,HiPrice);
	}
   ObjectSet("FiboUp",OBJPROP_LEVELCOLOR,UpColor);
   ObjectSet("FiboUp",OBJPROP_FIBOLEVELS,7);
   ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+0,0.0);	ObjectSetFiboDescription("FiboUp",0,"100.0  %$"); 
   ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+1,0.236);	ObjectSetFiboDescription("FiboUp",1,"123.6  %$"); 
   ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+2,0.382);	ObjectSetFiboDescription("FiboUp",2,"138.2  %$"); 
   ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+3,0.500);	ObjectSetFiboDescription("FiboUp",3,"150.0  %$"); 
   ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+4,0.618);	ObjectSetFiboDescription("FiboUp",4,"161.8  %$"); 
   ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+5,0.764);	ObjectSetFiboDescription("FiboUp",5,"176.4  %$"); 
   ObjectSet("FiboUp",OBJPROP_FIRSTLEVEL+6,1.000);	ObjectSetFiboDescription("FiboUp",6,"200.0  %$"); 
   ObjectSet("FiboUp",OBJPROP_RAY,true);
   ObjectSet("FiboUp",OBJPROP_BACK,true);

	if(ObjectFind("FiboDn") == -1)
		ObjectCreate("FiboDn",OBJ_FIBO,0,StartTime,LoPrice-Range,StartTime,LoPrice);
	else
	{
		ObjectSet("FiboDn",OBJPROP_TIME2, StartTime);
		ObjectSet("FiboDn",OBJPROP_TIME1, StartTime);
		ObjectSet("FiboDn",OBJPROP_PRICE1,LoPrice-Range);
		ObjectSet("FiboDn",OBJPROP_PRICE2,LoPrice);
	}
   ObjectSet("FiboDn",OBJPROP_LEVELCOLOR,DnColor); 
   ObjectSet("FiboDn",OBJPROP_FIBOLEVELS,7);
   ObjectSet("FiboDn",OBJPROP_FIRSTLEVEL+0,0.0);	ObjectSetFiboDescription("FiboDn",0,"0.0  %$"); 
   ObjectSet("FiboDn",OBJPROP_FIRSTLEVEL+1,0.236);	ObjectSetFiboDescription("FiboDn",1,"-23.6  %$"); 
   ObjectSet("FiboDn",OBJPROP_FIRSTLEVEL+2,0.382);	ObjectSetFiboDescription("FiboDn",2,"-38.2  %$"); 
   ObjectSet("FiboDn",OBJPROP_FIRSTLEVEL+3,0.500);	ObjectSetFiboDescription("FiboDn",3,"-50.0  %$"); 
   ObjectSet("FiboDn",OBJPROP_FIRSTLEVEL+4,0.618);	ObjectSetFiboDescription("FiboDn",4,"-61.8  %$"); 
   ObjectSet("FiboDn",OBJPROP_FIRSTLEVEL+5,0.764);	ObjectSetFiboDescription("FiboDn",5,"-76.4  %$"); 
   ObjectSet("FiboDn",OBJPROP_FIRSTLEVEL+6,1.000);	ObjectSetFiboDescription("FiboDn",6,"-100.0  %$"); 
   ObjectSet("FiboDn",OBJPROP_RAY,true);
   ObjectSet("FiboDn",OBJPROP_BACK,true);

	if(InnerFibs)
	{
		if(ObjectFind("FiboIn") == -1)
			ObjectCreate("FiboIn",OBJ_FIBO,0,StartTime,HiPrice,StartTime+PERIOD_D1*60,LoPrice);
		else
		{
			ObjectSet("FiboIn",OBJPROP_TIME2, StartTime);
			ObjectSet("FiboIn",OBJPROP_TIME1, StartTime+PERIOD_D1*60);
			ObjectSet("FiboIn",OBJPROP_PRICE1,HiPrice);
			ObjectSet("FiboIn",OBJPROP_PRICE2,LoPrice);
		}
   	ObjectSet("FiboIn",OBJPROP_LEVELCOLOR,InColor); 
   	ObjectSet("FiboIn",OBJPROP_FIBOLEVELS,7);
   	ObjectSet("FiboIn",OBJPROP_FIRSTLEVEL+0,0.0);	ObjectSetFiboDescription("FiboIn",0,"0.0  %$"); 
   	ObjectSet("FiboIn",OBJPROP_FIRSTLEVEL+1,0.236);	ObjectSetFiboDescription("FiboIn",1,"23.6  %$"); 
   	ObjectSet("FiboIn",OBJPROP_FIRSTLEVEL+2,0.382);	ObjectSetFiboDescription("FiboIn",2,"38.2  %$"); 
   	ObjectSet("FiboIn",OBJPROP_FIRSTLEVEL+3,0.500);	ObjectSetFiboDescription("FiboIn",3,"50.0  %$"); 
   	ObjectSet("FiboIn",OBJPROP_FIRSTLEVEL+4,0.618);	ObjectSetFiboDescription("FiboIn",4,"61.8  %$"); 
   	ObjectSet("FiboIn",OBJPROP_FIRSTLEVEL+5,0.764);	ObjectSetFiboDescription("FiboIn",5,"76.4  %$"); 
   	ObjectSet("FiboIn",OBJPROP_FIRSTLEVEL+6,1.000);	ObjectSetFiboDescription("FiboIn",6,"100.0  %$"); 
   	ObjectSet("FiboIn",OBJPROP_RAY,true);
   	ObjectSet("FiboIn",OBJPROP_BACK,true);
   }
   else
	   ObjectDelete("FiboIn");
}

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

int start()
{
	int shift	= iBarShift(NULL,PERIOD_D1,Time[0]) + 1;	// yesterday
	HiPrice		= iHigh(NULL,PERIOD_D1,shift);
	LoPrice		= iLow (NULL,PERIOD_D1,shift);
	StartTime	= iTime(NULL,PERIOD_D1,shift);

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

	Range = HiPrice-LoPrice;

	DrawFibo();

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

Comments