Day_Of_Week_Lables

Author: Copyright 2018, MetaQuotes Software Corp.
Price Data Components
Series array that contains the highest prices of each barSeries array that contains the lowest prices of each bar
0 Views
0 Downloads
0 Favorites
Day_Of_Week_Lables
ÿþ//+------------------------------------------------------------------+

//|                                           Day_Of_Week_Lables.mq5 |

//|                        Copyright 2018, MetaQuotes Software Corp. |

//|                                                 https://mql5.com |

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

#property copyright "Copyright 2018, MetaQuotes Software Corp."

#property link      "https://mql5.com"

#property version   "1.00"

#property description "Day of week indicator"

#property indicator_chart_window

#property indicator_buffers 0

#property indicator_plots   0

//--- enums

enum ENUM_INPUT_YES_NO

  {

   INPUT_YES   =  1,    // Yes

   INPUT_NO    =  0     // No

  };

//--- input parameters

input uint              InpHoursOffset       =  0;             // Hours offset

input ENUM_INPUT_YES_NO InpShowDaysDate      =  INPUT_YES;     // Show days numbers

input color             InpDayLabelColor     =  clrGreen;      // Day label color

input uchar             InpDayLabelSize      =  8;             // Day label font size

input string            InpDayLabelFont      =  "Calibri";     // Day label font name

input color             InpDaySepColor       =  clrDarkGray;   // Day dividing lines color

input ENUM_LINE_STYLE   InpDaySepStyle       =  STYLE_DOT;     // Day dividing lines style

input uchar             InpDaySepWidth       =  1;             // Day dividing lines width

input ENUM_INPUT_YES_NO InpDaySepDate        =  INPUT_NO;      // Show day dividing lines date field

input color             InpMonthLabelColor   =  clrRed;        // Month label color

input uchar             InpMonthLabelSize    =  10;            // Month label font size

input string            InpMonthLabelFont    =  "Calibri";     // Month label font name

input color             InpMonthSepColor     =  clrDarkOrange; // Month dividing lines color

input ENUM_LINE_STYLE   InpMonthSepStyle     =  STYLE_SOLID;   // Month dividing lines style

input uchar             InpMonthSepWidth     =  2;             // Month dividing lines width

input ENUM_INPUT_YES_NO InpMonthSepDate      =  INPUT_YES;     // Show month dividing lines date field

//--- global variables

string         prefix;

string         days[7];

string         month[12];

string         day_date;

int            hour_offset;

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- set timer

   EventSetTimer(90);

//--- set global variables

   prefix=MQLInfoString(MQL_PROGRAM_NAME)+"_";

   hour_offset=int(InpHoursOffset>23 ? 23 : InpHoursOffset);

   days[0]=TextByLanguage(">A:@5A5=85","Sunday");

   days[1]=TextByLanguage(">=545;L=8:","Monday");

   days[2]=TextByLanguage("B>@=8:","Tuesday");

   days[3]=TextByLanguage("!@540","Wednesday");

   days[4]=TextByLanguage("'5B25@3","Thursday");

   days[5]=TextByLanguage("OB=8F0","Friday");

   days[6]=TextByLanguage("!C11>B0","Saturday");

//---

   month[0]=TextByLanguage("/=20@L","January");

   month[1]=TextByLanguage("$52@0;L","February");

   month[2]=TextByLanguage("0@B","March");

   month[3]=TextByLanguage("?@5;L","April");

   month[4]=TextByLanguage("09","May");

   month[5]=TextByLanguage("N=L","June");

   month[6]=TextByLanguage("N;L","July");

   month[7]=TextByLanguage("23CAB","August");

   month[8]=TextByLanguage("!5=BO1@L","September");

   month[9]=TextByLanguage(":BO1@L","October");

   month[10]=TextByLanguage(">O1@L","November");

   month[11]=TextByLanguage("5:01@L","December");

//--- setting indicator parameters

   IndicatorSetString(INDICATOR_SHORTNAME,"Day of week");

//---

   iTime(NULL,PERIOD_D1,1);

//---

   return(INIT_SUCCEEDED);

  }

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

//| Custom indicator deinitialization function                       |

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

void OnDeinit(const int reason)

  {

//--- delete objects

   ObjectsDeleteAll(0,prefix);

   ChartRedraw();

//---

  }

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

//| Custom indicator deinitialization function                       |

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

void OnTimer()

  {

//--- Every 1.5 minutes to keep data D1 up to date

   iTime(NULL,PERIOD_D1,1);

  }

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

//| 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[])

  {

//--- #AB0=>2:0 <0AA82>2 1CD5@>2 :0: B09<A5@89

   ArraySetAsSeries(time,true);

//--- @>25@:0 :>;8G5AB20 4>ABC?=KE 10@>2

   if(rates_total<4 || !IsTimeframeDataReady(PERIOD_D1)) return 0;

//--- @>25@:0 8 @0AGQB :>;8G5AB20 ?@>AG8BK205<KE 10@>2

   int limit=rates_total-prev_calculated;

   if(limit>1)

     {

      limit=rates_total-1;

     }



//---  0AGQB 8=48:0B>@0

   day_date="";

   static int last_month=WRONG_VALUE;

   for(int i=limit; i>=0 && !IsStopped(); i--)

     {

      if(TimeHour(time[i])==hour_offset)

        {

         day_date=(InpShowDaysDate ? IntegerToString(TimeDay(time[i]),2,'0') : "");

         //--- Day

         Separator(prefix+"day_sep_"+(string)i,time[i],InpDaySepColor,InpDaySepWidth,InpDaySepStyle,InpDaySepDate);

         ObjectMakeText(prefix+"day_"+(string)i,time[i]+(PeriodSeconds(PERIOD_D1)/2),iHigh(NULL,PERIOD_D1,iBarShift(NULL,PERIOD_D1,time[i]))+(20*Point()),days[TimeDayOfWeek(time[i])]+" "+day_date,InpDayLabelColor,InpDayLabelFont,InpDayLabelSize);

         //--- Month

         int cur_month=TimeMonth(time[i]);

         if(cur_month!=last_month)

           {

            Separator(prefix+"month_sep"+(string)i,time[i],InpMonthSepColor,InpMonthSepWidth,InpMonthSepStyle,InpMonthSepDate);

            ObjectMakeText(prefix+"month_"+(string)i,time[i]+(PeriodSeconds(PERIOD_D1)/2),iLow(NULL,PERIOD_D1,iBarShift(NULL,PERIOD_D1,time[i]))+(30*Point()),month[TimeMonth(time[i])-1],InpMonthLabelColor,InpMonthLabelFont,InpMonthLabelSize);

            last_month=cur_month;

           }

        }

     }



//--- return value of prev_calculated for next call

   return(rates_total);

  }

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

//|  8AC5B @0745;8B5;L=CN ;8=8N                                      |

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

void Separator(const string name,const datetime time,const color clr,const int width,const int style,const bool date=false)

  {

   if(ObjectFind(0,name)<1)

      ObjectCreate(0,name,OBJ_VLINE,0,0,0);

   ObjectSetInteger(0,name,OBJPROP_HIDDEN,true);

   ObjectSetInteger(0,name,OBJPROP_SELECTABLE,false);

   ObjectSetInteger(0,name,OBJPROP_TIME,0,time);

   ObjectSetInteger(0,name,OBJPROP_COLOR,clr);

   ObjectSetInteger(0,name,OBJPROP_STYLE,style);

   ObjectSetInteger(0,name,OBJPROP_WIDTH,width);

   ObjectSetInteger(0,name,OBJPROP_RAY,date);

  }

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

//| K2>48B B5:AB                                                    |

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

void ObjectMakeText(const string name,const datetime time,const double price,const string text,const color clr,const string font="Calibri",const int size=8)

  {

   if(ObjectFind(0,name)<1)

      ObjectCreate(0,name,OBJ_TEXT,0,0,0);

   ObjectSetInteger(0,name,OBJPROP_HIDDEN,true);

   ObjectSetInteger(0,name,OBJPROP_SELECTABLE,false);

   ObjectSetInteger(0,name,OBJPROP_ANCHOR,ANCHOR_CENTER);

   ObjectSetDouble(0,name,OBJPROP_PRICE,0,price);

   ObjectSetInteger(0,name,OBJPROP_TIME,0,time);

   ObjectSetInteger(0,name,OBJPROP_COLOR,clr);

   ObjectSetInteger(0,name,OBJPROP_FONTSIZE,size);

   ObjectSetString(0,name,OBJPROP_TEXT,text);

   ObjectSetString(0,name,OBJPROP_FONT,font);

   return;

  }

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

//| >72@0I05B 45=L <5AOF0 C:070==>9 40BK                            |

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

int TimeDay(const datetime time)

  {

   MqlDateTime tm;

   if(!TimeToStruct(time,tm)) return WRONG_VALUE;

   return tm.day;

  }

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

//| >72@0I05B 45=L =545;8 C:070==>9 40BK                            |

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

int TimeDayOfWeek(const datetime time)

  {

   MqlDateTime tm;

   if(!TimeToStruct(time,tm)) return WRONG_VALUE;

   return tm.day_of_week;

  }

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

//| >72@0I05B =><5@ <5AOF0 C:070==>3> 2@5<5=8                       |

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

int TimeMonth(const datetime time)

  {

   MqlDateTime tm;

   if(!TimeToStruct(time,tm)) return WRONG_VALUE;

   return tm.mon;

  }

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

//| >72@0I05B G0A C:070==>3> 2@5<5=8                                |

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

int TimeHour(const datetime time)

  {

   MqlDateTime tm;

   if(!TimeToStruct(time,tm)) return WRONG_VALUE;

   return tm.hour;

  }

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

//| >72@0I05B B5:AB =0 >4=>< 87 42CE O7K:>2                         |

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

string TextByLanguage(const string text_ru,const string text_en)

  {

   return((TerminalInfoString(TERMINAL_LANGUAGE)=="Russian") ? text_ru : text_en);

  }

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

//| @>25@:0 =0;8G8O 8AB>@8G5A:8E 40==KE ?> B09<D@59<C               |

//| https://www.mql5.com/ru/forum/280448#comment_8762312             |

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

bool IsTimeframeDataReady(ENUM_TIMEFRAMES timeframe)

  {

   ResetLastError();

   iTime(NULL,timeframe,1);

   return GetLastError()==ERR_SUCCESS;

  }

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

Comments