BobokusFibo_v2
Download scriptThis script is designed to automatically plot various Fibonacci retracement and extension levels on your trading chart based on specific timeframes. Instead of requiring you to manually calculate and draw these lines, the tool handles the geometry and labeling for you, providing a visual roadmap for potential price targets and support/resistance zones.
Core Functionality
The script identifies key price points (the highest and lowest prices) from a previous period—such as a day, week, or month—and uses those boundaries to construct three distinct types of Fibonacci visuals:
- Long Targets: These are designed to project potential upward price targets based on the previous period's range.
- Short Targets: These project potential downward price targets, helping you identify where price might react if a trend reverses or pulls back.
- Intraday Levels: This creates a detailed breakdown of the current period, highlighting specific milestones like the Pivot point, Support (S1), and Resistance (R1) levels.
Key Features & Logic
Automated Data Selection The script looks back at the previous completed candle on your chosen timeframe to determine the "High" and "Low" prices. For example, if you are looking at a Daily chart, it automatically grabs the highest and lowest prices from yesterday to set the boundaries for today's Fibonacci levels.
Smart Weekend Handling The logic includes a specific check for Sundays. To ensure the data remains consistent during market closures, if the script detects a Sunday, it will automatically incorporate the high and low prices from the preceding Friday into its calculations.
Dynamic Labeling One of the most user-friendly aspects of this script is its naming convention. It dynamically updates the text descriptions on the chart to match your selected timeframe. Whether you are viewing Hourly, Daily, Weekly, or Monthly charts, the labels will automatically adjust their text (e.g., "H1 Long Target" vs. "Daily Long Target") so you always know exactly what each level represents.
Safety and Compatibility The script includes built-in restrictions to ensure accuracy. It is specifically tuned for higher-timeframe analysis; if you attempt to run it on very short timeframes (like 1-minute or 5-minute charts), the script will detect this and display a visual warning on your screen, advising you to use more significant timeframes for better reliability.
Visual Organization To keep your chart clean and readable, the script uses specific colors for different types of levels:
- Royal Blue for Intraday levels.
- Blue for Upper/Long targets.
- Dodger Blue for Lower/Short targets.
By automating these calculations, the tool allows you to see where "mathematical" price targets lie at a glance, helping you decide where to take profits or enter trades based on historical price volatility.
//+------------------------------------------------------------------+
//| #BobokusFibo.mq4 modified from |
//| #SpudFibo.mq4 |
//| http://www.forexfactory.com/showthread.php?t=50767 |
//+------------------------------------------------------------------+
#property link "Modified by cja"
#property indicator_chart_window
#property indicator_buffers 3
extern int TimeFrame =60;
extern int Fibo_Num = 12345;
extern color Intra_color = RoyalBlue;
extern color Upper_color = Blue;
extern color Lower_color = DodgerBlue;
double HiPrice, LoPrice, Range;
datetime StartTime;
int init()
{
return(0);
}
int deinit()
{
ObjectDelete("LongFibo"+Fibo_Num+"");
ObjectDelete("ShortFibo"+Fibo_Num+"");
ObjectDelete("IntradayFibo"+Fibo_Num+"");
ObjectDelete("Fibo"+Fibo_Num+""); ObjectDelete("Fibo1"+Fibo_Num+"");
return(0);
}
//+------------------------------------------------------------------+
//| Draw Fibo
//+------------------------------------------------------------------+
int DrawFibo()
{ string TF="",TF2="";
if(TimeFrame==1){return(-1);}
if(TimeFrame==5){return(-1);}
if(TimeFrame==15){return(-1);}
if(TimeFrame==30){return(-1);}
if(TimeFrame==60){TF="H1";}
if(TimeFrame==240){TF="H4";}
if(TimeFrame==1440){TF="Daily";}
if(TimeFrame==10080){TF="Weekly";}
if(TimeFrame==43200){TF="Monthly";}
if(TimeFrame==60){TF2="1 Hourly";}
if(TimeFrame==240){TF2="4 Hourly";}
if(TimeFrame==1440){TF2="IntraDay";}
if(TimeFrame==10080){TF2="IntraWeek";}
if(TimeFrame==43200){TF2="IntraMonth";}
if(ObjectFind("LongFibo"+Fibo_Num+"") == -1)
ObjectCreate("LongFibo"+Fibo_Num+"",OBJ_FIBO,0,StartTime,HiPrice+Range,StartTime,HiPrice);
else
{
ObjectSet("LongFibo"+Fibo_Num+"",OBJPROP_TIME2, StartTime);
ObjectSet("LongFibo"+Fibo_Num+"",OBJPROP_TIME1, StartTime);
ObjectSet("LongFibo"+Fibo_Num+"",OBJPROP_PRICE1,HiPrice+Range);
ObjectSet("LongFibo"+Fibo_Num+"",OBJPROP_PRICE2,HiPrice);
}
ObjectSet("LongFibo"+Fibo_Num+"",OBJPROP_LEVELCOLOR,Upper_color);
ObjectSet("LongFibo"+Fibo_Num+"",OBJPROP_FIBOLEVELS,4);
ObjectSet("LongFibo"+Fibo_Num+"",OBJPROP_FIRSTLEVEL+0,0.34); ObjectSetFiboDescription("LongFibo"+Fibo_Num+"",0,""+TF+" Long Target 1 - %$");
ObjectSet("LongFibo"+Fibo_Num+"",OBJPROP_FIRSTLEVEL+1,0.55); ObjectSetFiboDescription("LongFibo"+Fibo_Num+"",1,""+TF+" Long Target 2 - %$");
ObjectSet("LongFibo"+Fibo_Num+"",OBJPROP_FIRSTLEVEL+2,0.764); ObjectSetFiboDescription("LongFibo"+Fibo_Num+"",2,""+TF+" Long Target 3 - %$");
ObjectSet("LongFibo"+Fibo_Num+"",OBJPROP_FIRSTLEVEL+3,1.764); ObjectSetFiboDescription("LongFibo"+Fibo_Num+"",3,""+TF+" Long Target 4 - %$");
ObjectSet("LongFibo"+Fibo_Num+"",OBJPROP_RAY,true);
ObjectSet("LongFibo"+Fibo_Num+"",OBJPROP_BACK,true);
if(ObjectFind("ShortFibo"+Fibo_Num+"") == -1)
ObjectCreate("ShortFibo"+Fibo_Num+"",OBJ_FIBO,0,StartTime,LoPrice-Range,StartTime,LoPrice);
else
{
ObjectSet("ShortFibo"+Fibo_Num+"",OBJPROP_TIME2, StartTime);
ObjectSet("ShortFibo"+Fibo_Num+"",OBJPROP_TIME1, StartTime);
ObjectSet("ShortFibo"+Fibo_Num+"",OBJPROP_PRICE1,LoPrice-Range);
ObjectSet("ShortFibo"+Fibo_Num+"",OBJPROP_PRICE2,LoPrice);
}
ObjectSet("ShortFibo"+Fibo_Num+"",OBJPROP_LEVELCOLOR,Lower_color);
ObjectSet("ShortFibo"+Fibo_Num+"",OBJPROP_FIBOLEVELS,4);
ObjectSet("ShortFibo"+Fibo_Num+"",OBJPROP_FIRSTLEVEL+0,0.34); ObjectSetFiboDescription("ShortFibo"+Fibo_Num+"",0,""+TF+" Short Target 1 - %$");
ObjectSet("ShortFibo"+Fibo_Num+"",OBJPROP_FIRSTLEVEL+1,0.55); ObjectSetFiboDescription("ShortFibo"+Fibo_Num+"",1,""+TF+" Short Target 2 - %$");
ObjectSet("ShortFibo"+Fibo_Num+"",OBJPROP_FIRSTLEVEL+2,0.764); ObjectSetFiboDescription("ShortFibo"+Fibo_Num+"",2,""+TF+" Short Target 3 - %$");
ObjectSet("ShortFibo"+Fibo_Num+"",OBJPROP_FIRSTLEVEL+3,1.764); ObjectSetFiboDescription("ShortFibo"+Fibo_Num+"",3,""+TF+" Short Target 4 - %$");
ObjectSet("ShortFibo"+Fibo_Num+"",OBJPROP_RAY,true);
ObjectSet("ShortFibo"+Fibo_Num+"",OBJPROP_BACK,true);
if(ObjectFind("IntradayFibo"+Fibo_Num+"") == -1)
ObjectCreate("IntradayFibo"+Fibo_Num+"",OBJ_FIBO,0,StartTime,HiPrice,StartTime+TimeFrame*60,LoPrice);
else
{
ObjectSet("IntradayFibo"+Fibo_Num+"",OBJPROP_TIME2, StartTime);
ObjectSet("IntradayFibo"+Fibo_Num+"",OBJPROP_TIME1, StartTime+TimeFrame*60);
ObjectSet("IntradayFibo"+Fibo_Num+"",OBJPROP_PRICE1,HiPrice);
ObjectSet("IntradayFibo"+Fibo_Num+"",OBJPROP_PRICE2,LoPrice);
}
ObjectSet("IntradayFibo"+Fibo_Num+"",OBJPROP_LEVELCOLOR,Intra_color);
ObjectSet("IntradayFibo"+Fibo_Num+"",OBJPROP_FIBOLEVELS,7);
ObjectSet("IntradayFibo"+Fibo_Num+"",OBJPROP_FIRSTLEVEL+0,0.0); ObjectSetFiboDescription("IntradayFibo"+Fibo_Num+"",0,""+TF2+" Low - %$");
ObjectSet("IntradayFibo"+Fibo_Num+"",OBJPROP_FIRSTLEVEL+1,0.191); ObjectSetFiboDescription("IntradayFibo"+Fibo_Num+"",1,""+TF2+" S1 - %$");
ObjectSet("IntradayFibo"+Fibo_Num+"",OBJPROP_FIRSTLEVEL+2,0.382); ObjectSetFiboDescription("IntradayFibo"+Fibo_Num+"",2,""+TF2+" Short - %$");
ObjectSet("IntradayFibo"+Fibo_Num+"",OBJPROP_FIRSTLEVEL+3,0.500); ObjectSetFiboDescription("IntradayFibo"+Fibo_Num+"",3,""+TF2+" Pivot - %$");
ObjectSet("IntradayFibo"+Fibo_Num+"",OBJPROP_FIRSTLEVEL+4,0.618); ObjectSetFiboDescription("IntradayFibo"+Fibo_Num+"",4,""+TF2+" Long - %$");
ObjectSet("IntradayFibo"+Fibo_Num+"",OBJPROP_FIRSTLEVEL+5,0.809); ObjectSetFiboDescription("IntradayFibo"+Fibo_Num+"",5,""+TF2+" R1 - %$");
ObjectSet("IntradayFibo"+Fibo_Num+"",OBJPROP_FIRSTLEVEL+6,1.000); ObjectSetFiboDescription("IntradayFibo"+Fibo_Num+"",6,""+TF2+" High - %$");
ObjectSet("IntradayFibo"+Fibo_Num+"",OBJPROP_RAY,true);
ObjectSet("IntradayFibo"+Fibo_Num+"",OBJPROP_BACK,true);
}
//+------------------------------------------------------------------+
//| Indicator start function
//+------------------------------------------------------------------+
int start()
{
int shift = iBarShift(NULL,TimeFrame,Time[0]) + 1; // 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();
string Caution="",Caution2="";
if(TimeFrame==1){Caution="ERROR: Incorrect Fibo TimeFrame";Caution2="Use only H1/H4/D1/W1/MN1";}
if(TimeFrame==5){Caution="ERROR: Incorrect Fibo TimeFrame";Caution2="Use only H1/H4/D1/W1/MN1";}
if(TimeFrame==15){Caution="ERROR: Incorrect Fibo TimeFrame";Caution2="Use only H1/H4/D1/W1/MN1";}
if(TimeFrame==30){Caution="ERROR: Incorrect Fibo TimeFrame";Caution2="Use only H1/H4/D1/W1/MN1";}
ObjectDelete("Fibo"+Fibo_Num+"");
ObjectCreate("Fibo"+Fibo_Num+"", OBJ_LABEL,0, 0, 0);
ObjectSetText("Fibo"+Fibo_Num+"",Caution,20, "Verdana",Intra_color);
ObjectSet("Fibo"+Fibo_Num+"", OBJPROP_CORNER, 1);
ObjectSet("Fibo"+Fibo_Num+"", OBJPROP_XDISTANCE, 20);
ObjectSet("Fibo"+Fibo_Num+"", OBJPROP_YDISTANCE, 36);
ObjectDelete("Fibo1"+Fibo_Num+"");
ObjectCreate("Fibo1"+Fibo_Num+"", OBJ_LABEL,0, 0, 0);
ObjectSetText("Fibo1"+Fibo_Num+"",Caution2,20, "Verdana",Intra_color);
ObjectSet("Fibo1"+Fibo_Num+"", OBJPROP_CORNER, 1);
ObjectSet("Fibo1"+Fibo_Num+"", OBJPROP_XDISTANCE, 20);
ObjectSet("Fibo1"+Fibo_Num+"", OBJPROP_YDISTANCE, 66);
return(0);
}
//+------------------------------------------------------------------+
Comments