Author: Kalenzo
Price Data Components
Series array that contains open time of each barSeries array that contains close prices for each barSeries array that contains the highest prices of each barSeries array that contains the lowest prices of each bar
0 Views
0 Downloads
0 Favorites
FiboPiv
ÿþ//+------------------------------------------------------------------+

//|                                                   FiboPiv_v1.mq5 |

//|                                                          Kalenzo |

//|                                      bartlomiej.gorski@gmail.com |

//+------------------------------------------------------------------+

#property copyright "Kalenzo"

#property link      "bartlomiej.gorski@gmail.com"

#property description "Port by Leonardo4"



#property indicator_chart_window

#property indicator_plots   0

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int OnInit()

  {

//---- indicators

//----

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//| Custom indicator deinitialization function                       |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

  {

//----  

   ObjectDelete(0,"S1");

   ObjectDelete(0,"S2");

   ObjectDelete(0,"S3");

   ObjectDelete(0,"R1");

   ObjectDelete(0,"R2");

   ObjectDelete(0,"R3");

   ObjectDelete(0,"PIVIOT");

   ObjectDelete(0,"Support 1");

   ObjectDelete(0,"Support 2");

   ObjectDelete(0,"Support 3");

   ObjectDelete(0,"Piviot level");

   ObjectDelete(0,"Resistance 1");

   ObjectDelete(0,"Resistance 2");

   ObjectDelete(0,"Resistance 3");

   

   Comment(" ");

//----

  }

//+------------------------------------------------------------------+

//| Custom indicator iteration function                              |

//+------------------------------------------------------------------+

int OnCalculate(const int rates_total,

                const int prev_calculated,

                const datetime &time[],

                const double &open[],

                const double &high[],

                const double &low[],

                const double &close[],

                const long &tick_volume[],

                const long &volume[],

                const int &spread[])

  {





//----

   double yesterday_close=0;

   double yesterday_high=0;

   double yesterday_low=0;



   if(DayOfWeek() == 1)

     {

      if(TimeDayOfWeek(iTime(Symbol(),PERIOD_D1,1)) == 5)

        {

         yesterday_close = iClose(_Symbol,PERIOD_D1,1);

         yesterday_high = iHigh(_Symbol,PERIOD_D1,1);

         yesterday_low = iLow(_Symbol,PERIOD_D1,1);

        }

      else

        {

         for(int d = 5; d>=0; d--)

           {

            if(TimeDayOfWeek(iTime(Symbol(),PERIOD_D1,d)) == 5)

              {

               yesterday_close = iClose(_Symbol,PERIOD_D1,d);

               yesterday_high = iHigh(_Symbol,PERIOD_D1,d);

               yesterday_low = iLow(_Symbol,PERIOD_D1,d);

              }



           }

        }

     }

   else

     {

      yesterday_close = iClose(_Symbol,PERIOD_D1,1);

      yesterday_high = iHigh(_Symbol,PERIOD_D1,1);

      yesterday_low = iLow(_Symbol,PERIOD_D1,1);

     }





//---- Calculate Pivots



   Comment("\nYesterday quotations:\nH ",

   DoubleToString(yesterday_high,5),

   "\nL ",

   DoubleToString(yesterday_low,5), 

   "\nC ",

   DoubleToString(yesterday_close,5)

   );

   

   double R = yesterday_high - yesterday_low;//range

   double p = (yesterday_high + yesterday_low + yesterday_close)/3;// Standard Pivot

   double r3 = p + (R * 1.000);

   double r2 = p + (R * 0.618);

   double r1 = p + (R * 0.382);

   double s1 = p - (R * 0.382);

   double s2 = p - (R * 0.618);

   double s3 = p - (R * 1.000);



   drawLine(r3,"R3",Lime,0);

   drawLabel("Resistance 3",r3,Lime);

   drawLine(r2,"R2",Green,0);

   drawLabel("Resistance 2",r2,Green);

   drawLine(r1,"R1",DarkGreen,0);

   drawLabel("Resistance 1",r1,DarkGreen);

   drawLine(p,"PIVIOT",Blue,1);

   drawLabel("Piviot level",p,Blue);

   drawLine(s1,"S1",Maroon,0);

   drawLabel("Support 1",s1,Maroon);

   drawLine(s2,"S2",Crimson,0);

   drawLabel("Support 2",s2,Crimson);

   drawLine(s3,"S3",Red,0);

   drawLabel("Support 3",s3,Red);





//----

   return(rates_total);

  }

//+------------------------------------------------------------------+

void drawLabel(string name,double lvl,color Color)

  {

   if(ObjectFind(0,name) != 0)

     {

      ObjectCreate(0,name, OBJ_TEXT, 0, iTime(_Symbol,0,10), lvl);

      //ObjectSetText(name, name, 8, "Arial", EMPTY);

      ObjectSetString(0,name,OBJPROP_TEXT,name);

      ObjectSetInteger(0,name,OBJPROP_FONTSIZE,8);

      ObjectSetString(0,name,OBJPROP_FONT,"Arial");

      ObjectSetInteger(0,name,OBJPROP_COLOR,CLR_NONE);

      

      

      ObjectSetInteger(0,name,OBJPROP_COLOR,Color);

     }

   else

     {

      ObjectMove(0,name, 0, iTime(_Symbol,0,10), lvl);

     }

  }





//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

void drawLine(double lvl,string name, color Col,int type)

  {

   if(ObjectFind(0,name) != 0)

     {

      ObjectCreate(0,name, OBJ_HLINE, 0, iTime(_Symbol,0,0), lvl,iTime(_Symbol,0,0),lvl);



      if(type == 1)

         ObjectSetInteger(0,name,OBJPROP_STYLE,STYLE_SOLID);

      else

         ObjectSetInteger(0,name,OBJPROP_STYLE,STYLE_DOT);



      ObjectSetInteger(0,name,OBJPROP_COLOR,Col);

      ObjectSetInteger(0,name,OBJPROP_WIDTH,1);



     }

   else

     {

      ObjectDelete(0,name);

      ObjectCreate(0,name, OBJ_HLINE, 0, iTime(_Symbol,0,0), lvl,iTime(_Symbol,0,0),lvl);



      if(type == 1)

         ObjectSetInteger(0,name,OBJPROP_STYLE,STYLE_SOLID);

      else

         ObjectSetInteger(0,name,OBJPROP_STYLE,STYLE_DOT);



      ObjectSetInteger(0,name,OBJPROP_COLOR,Col);

      ObjectSetInteger(0,name,OBJPROP_WIDTH,1);



     }

  }

//+------------------------------------------------------------------+



int DayOfWeek()

  {

   MqlDateTime tm;

   datetime vol_time;

   vol_time = TimeCurrent();

   TimeToStruct(vol_time,tm);

   return(tm.day_of_week);

  }  

  

int TimeDayOfWeek(datetime date)

  {

   MqlDateTime tm;

   TimeToStruct(date,tm);

   return(tm.day_of_week);

  }

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---