Questions from Beginners MQL5 MT5 MetaTrader 5 - page 607

 
new-rena:

No problem. I've thrown in the algorithm. The beginning only without the graph, that is to say like this:

НомерДНЯвМесяце=str.day;
you need the number of the week of the month :)
 
pako:
I need the number of the week of the month :)

I can't do it on 5 and it's not customary here on 4.

If I'm allowed, I'll write the code and post it.

 
pako:
what difference does it make 4 or 5 ???, the time is the same :)))
Paco, I don't know how to do 5 and I don't see the point anymore :)
 
new-rena:
Paco, I don't know how to write on 5 and I don't see the point anymore:)
Write in 4.
 
pako:
Write on 4

Probably not the right one. This is the beginning, criticism is welcome, we will do as required.

Put the EA in the tester, switch on visual mode, select TF D1, and watch the prints in the log.

//+------------------------------------------------------------------+
//|                                                  WeekOfMonth.mq4 |
//|                                                         new-rena |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "new-rena"
#property link      ""
#property version   "1.00"
#property strict
//--------------------------
double DayOfMonth,WeekOfMonth;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//---
//--- init
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//--- deinit
      return(0);   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
int start()
  {
      DayOfMonth=TimeDay(TimeLocal());
      Print("DayOfMonth N "+DoubleToStr(DayOfMonth,0));
      WeekOfMonth=MathCeil(DayOfMonth/7);
      Print("WeekOfMonth N "+DoubleToStr(WeekOfMonth,0));
      
//--- start
      return(0);   
  }
//+------------------------------------------------------------------+
 
new-rena:

Probably not the right one. This is the beginning, criticism is welcome, we will do as required.

Let's start the EA in the tester, switch on visual mode, select TF D1, and look at the prints in the log.

//+------------------------------------------------------------------+
//|                                                  WeekOfMonth.mq4 |
//|                                                         new-rena |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "new-rena"
#property link      ""
#property version   "1.00"
#property strict
//--------------------------
double DayOfMonth,WeekOfMonth;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//---
//--- init
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//--- deinit
      return(0);   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
int start()
  {
      DayOfMonth=TimeDay(TimeLocal());
      Print("DayOfMonth N "+DoubleToStr(DayOfMonth,0));
      WeekOfMonth=MathCeil(DayOfMonth/7);
      Print("WeekOfMonth N "+DoubleToStr(WeekOfMonth,0));
      
//--- start
      return(0);   
  }
//+------------------------------------------------------------------+

it does not show correctly

shows 3 weeks and today is week 4 22.08.2016

 
pako:
In Excel, the week=1+INT((A1-DATE(YEAR(A1+4-WEEKDAY(A1+6));1;5)+WEEKDAY(DATE(YEAR(A1+4-WEEKDAY(A1+6));1;3))/7)

//+------------------------------------------------------------------+ //|                                                  WeekOfMonth.mq4 | //|                                                         new-rena | //|                                                                  | //+------------------------------------------------------------------+ #property copyright "new-rena" #property link      "" #property version   "1.00" #property strict //-------------------------- double DayOfMonth,WeekOfMonth; int DayOfWeeks,MonthOfYear,PrevMonth,Delta=0,Show=0; //+------------------------------------------------------------------+ //| Expert initialization function                                   | //+------------------------------------------------------------------+ int init()   { //--- PrevMonth=TimeMonth(TimeLocal()); DayOfMonth=TimeDay(TimeLocal()); if(DayOfMonth==1)    {       Delta=TimeDayOfWeek(TimeLocal());       Show=1;    } //--- init    return(0);   } //+------------------------------------------------------------------+ //| Expert deinitialization function                                 | //+------------------------------------------------------------------+ int deinit()   { //--- deinit       return(0);     } //+------------------------------------------------------------------+ //| Expert tick function                                             | //+------------------------------------------------------------------+ int start()   { //---   MonthOfYear=TimeMonth(TimeLocal()); DayOfMonth=TimeDay(TimeLocal()); DayOfWeeks=TimeDayOfWeek(TimeLocal()); if(PrevMonth!=MonthOfYear && DayOfMonth==1)    {       Delta=DayOfWeeks;       Show=1;    } if(Show==1)    {       WeekOfMonth=MathCeil((DayOfMonth+Delta)/7);             Print("DayOfMonth N "+DoubleToStr(DayOfMonth,0));       Print("WeekOfMonth N "+DoubleToStr(WeekOfMonth,0));    }

PrevMonth=MonthOfYear; //--- start       return(0);     } //+------------------------------------------------------------------+

 

We should also put in when the 1st of the month falls on a weekend, as the tester doesn't spin weekends... Didn't see about the excel.

Well, and to roll in initialization from a couple of months ago AND to the current month would not hurt, so as not to wait for the end of the calculation of the number of the week a whole month. But these are all nuances ....

That's what makes MQL4 so attractive - the code is short and clear!

 
new-rena:

We should also put in when the 1st of the month falls on a weekend, as the tester doesn't spin weekends... Didn't see about the excel.

Well, and to roll in initialization from a couple of months ago AND to the current month would not hurt, so as not to wait for the end of the calculation of the number of the week a whole month. But these are all nuances ....

That's what makes MQL4 so attractive - the code is short and clear!

It does not calculate correctly
 
pako:
Doesn't count correctly
Okay. At what point? At the end of the month? I checked the calendar...
Reason: