This script is designed to automate the visual identification of Fibonacci retracement and extension levels on a trading chart. It simplifies technical analysis by automatically calculating key price points based on specific timeframes, allowing traders to quickly see potential areas of support and resistance without manual calculation.
Core Functionality
The logic operates by identifying a specific "pivot range" within a trading day. Instead of looking at the entire history of a currency pair, the script focuses on the price movement between two user-defined times (the Pivot Start and Pivot End).
How the Logic Works
- Time Filtering: The script scans the chart history to find the highest and lowest prices reached between your specified start and end times. It is specifically optimized for intraday trading and will only function on timeframes smaller than 4 hours (H4) to ensure accuracy.
- Range Calculation: Once the high and low points of that specific period are identified, the script calculates the total "range" (the distance between the highest and lowest price).
- Fibonacci Mapping: Using that range, the script mathematically projects eight distinct Fibonacci levels:
- Standard Levels: It identifies the 0.000 (bottom), 0.382, 0.618, and 1.000 (top) points.
- Extension Levels: It projects "positive" extensions (+1.272 and +1.618) above the high and "negative" extensions (-1.272 and -1.618) below the low.
- Visual Output: Rather than just drawing a static line, the script places dynamic visual markers (arrows) on the chart at these specific price points. These labels move with the current price action, providing a real-time map of where the market might react based on Fibonacci theory.
Summary for the User
In simple terms, this tool takes a block of time—such as a trading session—finds the extremes of that session, and then automatically "draws" the important Fibonacci zones for you. It removes the need to manually click and drag tools onto your chart, ensuring that the levels remain consistent and precise every day.
//+------------------------------------------------------------------+
//| Fibonacci_Daily.mq4 |
//| Copyright © 2008, Kris |
//| Time optimised for Forex.com |
//+------------------------------------------------------------------+
#property copyright " © 2008, Kris "
#property indicator_chart_window
#property indicator_buffers 8
#property indicator_color1 C'000,100,000' // DarkGreen // 1.618
#property indicator_color2 C'000,150,000' // Green // 1.272
#property indicator_color3 C'000,255,000' // Lime // 1.000
#property indicator_color4 C'100,100,100' // Gray // 0.618
#property indicator_color5 C'100,100,100' // Gray // 0.382
#property indicator_color6 C'255,000,000' // Red // 0.000
#property indicator_color7 C'150,000,000' // Crimson //-1.272
#property indicator_color8 C'100,000,000' // Maroon //-1.618
//Input Params
extern string PivotStart = "22:00";
extern string PivotEnd = "22:00";
double Buffer1[];
double Buffer2[];
double Buffer3[];
double Buffer4[];
double Buffer5[];
double Buffer6[];
double Buffer7[];
double Buffer8[];
double LastHigh,LastLow,LastClose;
double Fib1000,Fib0618,Fib0382,Fib0000;
double FibP1272,FibP1618,FibN1272,FibN1618;
int OpenBar;
int init()
{ SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0,160);
SetIndexBuffer(0,Buffer1);
SetIndexLabel(0,"Fibonacci +1.618");
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(1,160);
SetIndexBuffer(1,Buffer2);
SetIndexLabel(1,"Fibonacci +1.272");
SetIndexStyle(2,DRAW_ARROW);
SetIndexArrow(2,167);
SetIndexBuffer(2,Buffer3);
SetIndexLabel(2,"Fibonacci 1.000");
SetIndexStyle(3,DRAW_ARROW);
SetIndexArrow(3,160);
SetIndexBuffer(3,Buffer4);
SetIndexLabel(3,"Fibonacci 0.618");
SetIndexStyle(4,DRAW_ARROW);
SetIndexArrow(4,160);
SetIndexBuffer(4,Buffer5);
SetIndexLabel(4,"Fibonacci 0.382");
SetIndexStyle(5,DRAW_ARROW);
SetIndexArrow(5,167);
SetIndexBuffer(5,Buffer6);
SetIndexLabel(5,"Fibonacci 0.000");
SetIndexStyle(6,DRAW_ARROW);
SetIndexArrow(6,160);
SetIndexBuffer(6,Buffer7);
SetIndexLabel(6,"Fibonacci -1.272");
SetIndexStyle(7,DRAW_ARROW);
SetIndexArrow(7,160);
SetIndexBuffer(7,Buffer8);
SetIndexLabel(7,"Fibonacci -1.618");
return(0); }
int deinit() {
ObjectDelete("Fib161");
ObjectDelete("Fib127");
ObjectDelete("Fib100");
ObjectDelete("Fib618");
ObjectDelete("Fib382");
ObjectDelete("Fib000");
ObjectDelete("Fib128");
ObjectDelete("Fib162");
Comment("");
return(0); }
int start()
{ string BarTime="", LastBarTime="";
string BarDay="", LastBarDay="";
int CloseBar;
for(int i=Bars; i>=0; i--)
{ if (Period() > 240) return(0); //Chart cannot be higher than H4
BarTime = TimeToStr(Time[i], TIME_MINUTES);
LastBarTime = TimeToStr(Time[i+1], TIME_MINUTES);
BarDay = TimeToStr(Time[i],TIME_DATE);
LastBarDay = TimeToStr(Time[i+1],TIME_DATE);
if ((PivotEnd == "00:00" && BarTime>=PivotEnd && BarDay>LastBarDay) || (BarTime>=PivotEnd && LastBarTime<PivotEnd))
{ CloseBar = i + 1;
if (OpenBar>0)
{ calculatePivotRangeValues(OpenBar, CloseBar); } }
if ((PivotStart == "00:00" && BarTime>=PivotStart && BarDay>LastBarDay) || (BarTime>=PivotStart && LastBarTime<PivotStart))
{ OpenBar = i; }
if (OpenBar>0)
{ drawIndicators(i); }
}
return(0);
}
void calculatePivotRangeValues(int openBar, int closeBar)
{
LastHigh = High[Highest(NULL, 0, MODE_HIGH, (openBar - closeBar + 1), closeBar)];
LastLow = Low[Lowest(NULL, 0, MODE_LOW, (openBar - closeBar + 1), closeBar)];
LastClose = Close[closeBar];
double R = (LastHigh - LastLow);
FibP1618 = LastHigh + R * 0.618;
FibP1272 = LastHigh + R * 0.272;
Fib1000 = LastHigh;
Fib0618 = LastLow + R * 0.618;
Fib0382 = LastLow + R * 0.382;
Fib0000 = LastLow;
FibN1272 = LastLow - R * 0.272;
FibN1618 = LastLow - R * 0.618;
}
void drawIndicators(int curBar)
{
Buffer1[curBar]=FibP1618;
Buffer2[curBar]=FibP1272;
Buffer3[curBar]=Fib1000;
Buffer4[curBar]=Fib0618;
Buffer5[curBar]=Fib0382;
Buffer6[curBar]=Fib0000;
Buffer7[curBar]=FibN1272;
Buffer8[curBar]=FibN1618;
DoLabel( "Fib161", Buffer1[0], indicator_color1 );
DoLabel( "Fib127", Buffer2[0], indicator_color2 );
DoLabel( "Fib100", Buffer3[0], indicator_color3 );
DoLabel( "Fib618", Buffer4[0], indicator_color4 );
DoLabel( "Fib382", Buffer5[0], indicator_color5 );
DoLabel( "Fib000", Buffer6[0], indicator_color6 );
DoLabel( "Fib128", Buffer7[0], indicator_color7 );
DoLabel( "Fib162", Buffer8[0], indicator_color8 );
return(0); }
void DoLabel( string dName, double dValue, color dColor )
{
if (ObjectFind(dName) != 0)
{
ObjectCreate(dName,OBJ_ARROW,0,Time[0],dValue);
ObjectSet(dName,OBJPROP_ARROWCODE,SYMBOL_RIGHTPRICE);
ObjectSet(dName,OBJPROP_COLOR,dColor);
}
else
{
ObjectMove(dName,0,Time[0],dValue);
}
}
//+-----------------------------------------------------------------------------------------+
//| THE END |
//+-----------------------------------------------------------------------------------------+
Comments