FiboPiv_Daily_DK

Author: c. 2007-08, Kalenzo
FiboPiv_Daily_DK

This script is designed to automatically generate and display key technical analysis levels on a trading chart based on the previous day's price action. It combines two popular trading concepts into one visual tool: Pivot Points and Fibonacci Retracement levels.

How the Logic Works

1. Data Collection (Looking Back) The script starts by identifying the "Range" of the previous trading day. To do this, it automatically looks for the following three pieces of information from yesterday's session:

  • The highest price reached (High)
  • The lowest price reached (Low)
  • The final closing price (Close)

It includes specific logic to handle weekends and holidays. If the current day is a Monday, it intelligently searches back to ensure it finds the last valid Friday trading session, rather than trying to use a non-trading weekend day.

2. The Core Calculations Once it has yesterday's High, Low, and Close, it performs two main sets of calculations:

  • Standard Pivot Point: It calculates a "center" price by taking the average of yesterday's high, low, and close. This serves as the primary balance point for the current day.
  • The Range: It calculates the total distance between yesterday's high and low.

3. Mapping the Levels Using that "Range" and the "Pivot Point," the script generates a massive grid of horizontal lines on your chart:

  • Resistance Levels (R1 - R18): These are calculated by adding various Fibonacci percentages to the Pivot Point. They represent potential "ceilings" where price might struggle to rise further.
  • Support Levels (S1 - S18): These are calculated by subtracting Fibonacci percentages from the Pivot Point. They represent potential "floors" where price might find buyers and stop falling.

4. Visual Display The script handles all the heavy lifting of drawing these elements for you:

  • Automatic Drawing: It draws 37 different horizontal lines (18 Support, 1 Pivot, and 18 Resistance) across your chart.
  • Dynamic Labeling: Each line is automatically labeled with its corresponding Fibonacci percentage (e.g., "FIB 61.8", "FIB 100.0", etc.) so you can identify exactly which level you are looking at.
  • Clean Management: The script includes a cleanup routine. Whenever it updates, it clears out the old lines from the previous day to ensure your chart stays clean and only shows the relevant levels for the current trading session.

Summary for the User

Instead of you having to manually calculate math formulas every morning or draw dozens of lines by hand, this script does it instantly. It gives you a complete "map" of the day's potential price movements based on yesterday’s behavior, highlighting where the market is likely to face resistance or find support.

Price Data Components
Series array that contains open time of each bar
14 Views
0 Downloads
0 Favorites
FiboPiv_Daily_DK
//+------------------------------------------------------------------+
//|                                                   Daily_FiboPiv_DK.mq4 |
//|                                                          Kalenzo |
//|                                      bartlomiej.gorski@gmail.com
//|                                                          upgrade by darkkiller
//+------------------------------------------------------------------+
#property copyright "c. 2007-08, Kalenzo"
#property link      "bartlomiej.gorski@gmail.com"
#property indicator_buffers   5
#property indicator_color1 C'62,62,62'
#property indicator_style1 1
#property indicator_color2 Red 
#property indicator_style2 1
#property indicator_color3 C'62,62,62' 
#property indicator_style3 1
#property indicator_color4 DarkGray 
#property indicator_style4 1
#property indicator_color5 SlateGray 
#property indicator_style5 1


/*extern color Resistance_3 = Sienna;
extern color Resistance_2 = Red;
extern color Resistance_1 = Magenta;
extern color Pivot = Goldenrod;
extern color Support_1 = Lime;
extern color Support_2 = Green;
extern color Support_3 = DarkGreen;
*/
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   ObjectDelete("S1");
   ObjectDelete("S2");
   ObjectDelete("S3");
   ObjectDelete("S4");
   ObjectDelete("S5");
   ObjectDelete("S6");
   ObjectDelete("S7");
   ObjectDelete("S8");
   ObjectDelete("S9");
   ObjectDelete("S10");
   ObjectDelete("S11");
   ObjectDelete("S12");
   ObjectDelete("S11");
   ObjectDelete("S12");
   ObjectDelete("S13");
   ObjectDelete("S14");
   ObjectDelete("S15");
   ObjectDelete("S16");
   ObjectDelete("S17");
   ObjectDelete("S18");
   
   ObjectDelete("R1");
   ObjectDelete("R2");
   ObjectDelete("R3");
   ObjectDelete("R4");
   ObjectDelete("R5");
   ObjectDelete("R6");
   ObjectDelete("R7");
   ObjectDelete("R8");
   ObjectDelete("R9");
   ObjectDelete("R10");
   ObjectDelete("R11");
   ObjectDelete("R12");
   ObjectDelete("R11");
   ObjectDelete("R12");
   ObjectDelete("R13");
   ObjectDelete("R14");
   ObjectDelete("R15");
   ObjectDelete("R16");
   ObjectDelete("R17");
   ObjectDelete("R18");
  
 
   ObjectDelete("PIVOT");
   ObjectDelete("                                                    Daily Pivot");
   
   ObjectDelete("                                                     -FIB 23.6");
   ObjectDelete("                                                     -FIB 38.2");
   ObjectDelete("                                                     -FIB 50.0");
   ObjectDelete("                                                     -FIB 61.8");
   ObjectDelete("                                                     -FIB 76.4");
   ObjectDelete("                                                     -FIB 100.0");
   ObjectDelete("                                                     -FIB 123.6");
   ObjectDelete("                                                     -FIB 138.2");
   ObjectDelete("                                                     -FIB 150.0");
   ObjectDelete("                                                     -FIB 161.8");
   ObjectDelete("                                                     -FIB 176.4");
   ObjectDelete("                                                     -FIB 200.0");
   ObjectDelete("                                                     -FIB 223.6");
   ObjectDelete("                                                     -FIB 238.2");
   ObjectDelete("                                                     -FIB 250.0");
   ObjectDelete("                                                     -FIB 261.8");
   ObjectDelete("                                                     -FIB 276.4");
   ObjectDelete("                                                     -FIB 300.0");
   
   ObjectDelete("                                                     +FIB 23.6");
   ObjectDelete("                                                     +FIB 38.2");
   ObjectDelete("                                                     +FIB 50.0");
   ObjectDelete("                                                     +FIB 61.8");
   ObjectDelete("                                                     +FIB 76.4");
   ObjectDelete("                                                     +FIB 100.0");
   ObjectDelete("                                                     +FIB 123.6");
   ObjectDelete("                                                     +FIB 138.2");
   ObjectDelete("                                                     +FIB 150.0");
   ObjectDelete("                                                     +FIB 161.8");
   ObjectDelete("                                                     +FIB 176.4");
   ObjectDelete("                                                     +FIB 200.0");
   ObjectDelete("                                                     +FIB 223.6");
   ObjectDelete("                                                     +FIB 238.2");
   ObjectDelete("                                                     +FIB 250.0");
   ObjectDelete("                                                     +FIB 261.8");
   ObjectDelete("                                                     +FIB 276.4");
   ObjectDelete("                                                     +FIB 300.0");
   Comment(" ");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   
//----
double rates[1][6],yesterday_close,yesterday_high,yesterday_low;
ArrayCopyRates(rates, Symbol(), PERIOD_D1);

if(DayOfWeek() == 1)
{
   if(TimeDayOfWeek(iTime(Symbol(),PERIOD_D1,1)) == 5)
   {
       yesterday_close = rates[1][4];
       yesterday_high = rates[1][3];
       yesterday_low = rates[1][2];
   }
   else
   {
      for(int d = 5;d>=0;d--)
      {
         if(TimeDayOfWeek(iTime(Symbol(),PERIOD_D1,d)) == 5)
         {
             yesterday_close = rates[d][4];
             yesterday_high = rates[d][3];
             yesterday_low = rates[d][2];
         }
         
      }  
      
   }
}
else
{
    yesterday_close = rates[1][4];
    yesterday_high = rates[1][3];
    yesterday_low = rates[1][2];
}


//---- Calculate Pivots

Comment("");
double R = yesterday_high - yesterday_low;//range
double p = (yesterday_high + yesterday_low + yesterday_close)/3;// Standard Pivot

double r18 = p + (R * 3.000);
double r17 = p + (R * 2.764);
double r16 = p + (R * 2.618);
double r15 = p + (R * 2.500);
double r14 = p + (R * 2.382);
double r13 = p + (R * 2.236);
double r12 = p + (R * 2.000);
double r11 = p + (R * 1.764);
double r10 = p + (R * 1.618);
double r9 = p + (R * 1.500);
double r8 = p + (R * 1.382);
double r7 = p + (R * 1.236);
double r6 = p + (R * 1.000);
double r5 = p + (R * 0.764);
double r4 = p + (R * 0.618);
double r3 = p + (R * 0.500);
double r2 = p + (R * 0.382);
double r1 = p + (R * 0.236);


double s1 = p - (R * 0.236);
double s2 = p - (R * 0.382);
double s3 = p - (R * 0.500);
double s4 = p - (R * 0.618);
double s5 = p - (R * 0.764);
double s6 = p - (R * 1.000);
double s7 = p - (R * 1.236);
double s8 = p - (R * 1.382);
double s9 = p - (R * 1.500);
double s10 = p - (R * 1.618);
double s11 = p - (R * 1.764);
double s12 = p - (R * 2.000);
double s13 = p - (R * 2.236);
double s14 = p - (R * 2.382);
double s15 = p - (R * 2.500);
double s16 = p - (R * 2.618);
double s17 = p - (R * 2.764);
double s18 = p - (R * 3.000);

drawLine(r18,"R18", indicator_color1,indicator_style1);
drawLabel("                                                     +FIB 300.0",r18,indicator_color5);
drawLine(r17,"R17", indicator_color1,indicator_style1);
drawLabel("                                                     +FIB 276.4",r17,indicator_color4);
drawLine(r16,"R16", indicator_color1,indicator_style1);
drawLabel("                                                     +FIB 261.8",r16,indicator_color4);
drawLine(r15,"R15", indicator_color1,indicator_style1);
drawLabel("                                                     +FIB 250.0",r15,indicator_color4);
drawLine(r14,"R14", indicator_color1,indicator_style1);
drawLabel("                                                     +FIB 238.2",r14,indicator_color4);
drawLine(r13,"R13", indicator_color1,indicator_style1);
drawLabel("                                                     +FIB 223.6",r13,indicator_color4);
drawLine(r12,"R12", indicator_color1,indicator_style1);
drawLabel("                                                     +FIB 200.0",r12,indicator_color5);
drawLine(r11,"R11", indicator_color1,indicator_style1);
drawLabel("                                                     +FIB 176.4",r11,indicator_color4);
drawLine(r10,"R10", indicator_color1,indicator_style1);
drawLabel("                                                     +FIB 161.8",r10,indicator_color4);
drawLine(r9,"R9", indicator_color1,indicator_style1);
drawLabel("                                                     +FIB 150.0",r9,indicator_color4);
drawLine(r8,"R8", indicator_color1,indicator_style1);
drawLabel("                                                     +FIB 138.2",r8,indicator_color4);
drawLine(r7,"R7", indicator_color1,indicator_style1);
drawLabel("                                                     +FIB 123.6",r7,indicator_color4);
drawLine(r6,"R6", indicator_color1,indicator_style1);
drawLabel("                                                     +FIB 100.0",r6,indicator_color5);
drawLine(r5,"R5", indicator_color1,indicator_style1);
drawLabel("                                                     +FIB 76.4",r5,indicator_color4);
drawLine(r4,"R4", indicator_color1,indicator_style1);
drawLabel("                                                     +FIB 61.8",r4,indicator_color4);
drawLine(r3,"R3", indicator_color1,indicator_style1);
drawLabel("                                                     +FIB 50.0",r3,indicator_color4);
drawLine(r2,"R2", indicator_color1,indicator_style1);
drawLabel("                                                     +FIB 38.2",r2,indicator_color4);
drawLine(r1,"R1", indicator_color1,indicator_style1);
drawLabel("                                                     +FIB 23.6",r1,indicator_color4);

drawLine(p,"PIVOT",indicator_color2,indicator_style1);
drawLabel("                                                    Daily Pivot",p,indicator_color2);

drawLine(s1,"S1",indicator_color3,indicator_style1);
drawLabel("                                                     -FIB 23.6",s1,indicator_color4);
drawLine(s2,"S2",indicator_color3,indicator_style1);
drawLabel("                                                     -FIB 38.2",s2,indicator_color4);
drawLine(s3,"S3",indicator_color3,indicator_style1);
drawLabel("                                                     -FIB 50.0",s3,indicator_color4);
drawLine(s4,"S4",indicator_color3,indicator_style1);
drawLabel("                                                     -FIB 61.8",s4,indicator_color4);
drawLine(s5,"S5",indicator_color3,indicator_style1);
drawLabel("                                                     -FIB 76.4",s5,indicator_color4);
drawLine(s6,"S6",indicator_color3,indicator_style1);
drawLabel("                                                     -FIB 100.0",s6,indicator_color5);
drawLine(s7,"S7",indicator_color3,indicator_style1);
drawLabel("                                                     -FIB 123.6",s7,indicator_color4);
drawLine(s8,"S8",indicator_color3,indicator_style1);
drawLabel("                                                     -FIB 138.2",s8,indicator_color4);
drawLine(s9,"S9",indicator_color3,indicator_style1);
drawLabel("                                                     -FIB 150.0",s9,indicator_color4);
drawLine(s10,"S10",indicator_color3,indicator_style1);
drawLabel("                                                     -FIB 161.8",s10,indicator_color4);
drawLine(s11,"S11",indicator_color3,indicator_style1);
drawLabel("                                                     -FIB 176.4",s11,indicator_color4);
drawLine(s12,"S12",indicator_color3,indicator_style1);
drawLabel("                                                     -FIB 200.0",s12,indicator_color5);
drawLine(s13,"S13",indicator_color3,indicator_style1);
drawLabel("                                                     -FIB 223.6",s13,indicator_color4);
drawLine(s14,"S14",indicator_color3,indicator_style1);
drawLabel("                                                     -FIB 238.2",s14,indicator_color4);
drawLine(s15,"S15",indicator_color3,indicator_style1);
drawLabel("                                                     -FIB 250.0",s15,indicator_color4);
drawLine(s16,"S16",indicator_color3,indicator_style1);
drawLabel("                                                     -FIB 261.8",s16,indicator_color4);
drawLine(s17,"S17",indicator_color3,indicator_style1);
drawLabel("                                                     -FIB 276.4",s17,indicator_color4);
drawLine(s18,"S18",indicator_color3,indicator_style1);
drawLabel("                                                     -FIB 300.0",s18,indicator_color5);


//----
   return(0);
  }
//+------------------------------------------------------------------+
void drawLabel(string name,double lvl,color Color)
{
    if(ObjectFind(name) != 0)
    {
        ObjectCreate(name, OBJ_TEXT, 0, Time[10], lvl);
        ObjectSetText(name, name, 8, "Arial", EMPTY);
        ObjectSet(name, OBJPROP_COLOR, Color);


    }
    else
    {
        ObjectMove(name, 0, Time[10], lvl);
    }
}


void drawLine(double lvl,string name, color Col,int type)
{
         if(ObjectFind(name) != 0)
         {
            ObjectCreate(name, OBJ_HLINE, 0, Time[0], lvl,Time[0],lvl);
            
            if(type == 1)
            ObjectSet(name, OBJPROP_STYLE, STYLE_SOLID);
            else if(type == 2)
            ObjectSet(name, OBJPROP_STYLE, STYLE_DASHDOTDOT);
            else
            ObjectSet(name, OBJPROP_STYLE, STYLE_DOT);
            
            ObjectSet(name, OBJPROP_COLOR, Col);
            ObjectSet(name,OBJPROP_WIDTH,1);
            
         }
         else
         {
            ObjectDelete(name);
            ObjectCreate(name, OBJ_HLINE, 0, Time[0], lvl,Time[0],lvl);
            
            if(type == 1)
            ObjectSet(name, OBJPROP_STYLE, STYLE_SOLID);
            else if(type == 2)
            ObjectSet(name, OBJPROP_STYLE, STYLE_DASHDOTDOT);
            else
            ObjectSet(name, OBJPROP_STYLE, STYLE_DOT);
            
            ObjectSet(name, OBJPROP_COLOR, Col);        
            ObjectSet(name,OBJPROP_WIDTH,1);
          
         }
}

Comments