Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 271

 
Alexey Viktorov:

And then there's this idea.

If you want the first Friday, the number must be less than 8. If the first Friday of the month is Friday, the next Friday will be the eighth. Accordingly, you can easily recalculate to any day of the week and any day of the month, second, third...


//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
void start() {
  int bs=0;

  if (DayOfWeek()==5 && Minute()<5) {  Добавьте сюда пожалуйста 
    bs=GetSignal();
    if (Hour()==lHourOpenPos && bs>0) OpenPosition();
    if (Hour()==sHourOpenPos && bs<0) OpenPosition();
  }

  if (bLastBuy) {
    if (DayOfWeek()==lDayForClose && Hour()>=lHourClosePos) CloseAllPositions();
    TrailingStop=lTrailingStop;
    if (lUseTrailing) TrailingPositions();
  } else {
    if (DayOfWeek()==sDayForClose && Hour()>=sHourClosePos) CloseAllPositions();
    TrailingStop=sTrailingStop;
    if (sUseTrailing) TrailingPositions();
  }
}
 
Darirunu:

I have no desire to remember the old mql4 functions. Here is the second working version of the script

/********************Script program start function********************/
void OnStart()
{
 MqlDateTime mqlDateTime;
 datetime arrDateTime[1];
 CopyTime(_Symbol, PERIOD_D1, 1, 1, arrDateTime);
 TimeToStruct(arrDateTime[0], mqlDateTime);
 if(mqlDateTime.day_of_week == FRIDAY && mqlDateTime.day < 8)
  {
   Print("Ура!!! Вчера была первая пятница");
   
  }
}/********************************************************************/
 
Alexey Viktorov:

I have no desire to remember the old mql4 functions. Here is the second working version of the script


I wonder how to know what week it is?

 

It's all classic. Once you ask a slightly above-average question, the result is always the same, but thank you.

 
Aleksey Vyazmikin:

I wonder how you find out what week it is?

Divide today's number by 7 and round up to the higher number, regardless of the remainder.

Last Friday was 11 divided by 7, so 1 week + 4 days is the second week. Tuesday's number was 15 divided by 7, so it was 2 weeks + 1 day, making it the third week. Right?

We can do without rounding. If the remainder of the division is greater than zero, so we have the whole week plus 1. Right?

 
Alexey Viktorov:

Divide today's number by 7 and round up to the higher number, regardless of the remainder.

Last Friday was 11 divided by 7, so 1 week + 4 days is the second week. Tuesday's number is 15 divided by 7, so it's 2 weeks + 1 day, so week 3. Right?

You can get by without rounding. If the remainder of the division is greater than zero, then the resulting number of full weeks plus 1. Right?


It's not a maths class or am I writing in the wrong place?

 
Darirunu:

All in all, it's classic. You ask a slightly above-average question, the result is always the same, but thank you.

What's this got to do with the classics? What grudges? Your code's logic is incomprehensible to me, why should I try to understand it? The question was.

Forum on trading, automated trading systems and strategy testing.

Any questions for newbies on MQL4, help and discussion on algorithms and codes

Darirunu, 2017.08.12 16:00

Afternoon ...

How to write the condition in the quad:if the first Friday of the month was bullish, and

Thesecond Monday is bearish we open a sell trade.

I showed you how to determine the first Friday. On what day you have to count is up to you.

Tell me please: why do you check the minutes when defining the day of the week? Then you check the hours. I think it is more logical to determine the day of the week, then within the fulfilled condition check the hour, minutes (if necessary), then you check bullish or bearish and decide where to open.

Maybe you'd better get a higher level of programming, instead of me going back to mql3?

 
Darirunu:

This isn't a maths class, is it, or am I writing in the wrong place?

Hello... How can you be a programmer without above-average maths skills??? Notice I'm not talking about advanced mathematics.

 
Alexey Viktorov:

Hello... How can you be a programmer without above-average maths skills? Notice I'm not talking about higher mathematics.


Then add that it's good to know about trigonometry and drafting. And a bit of philosophy.

 
Alexey Viktorov:

Divide today's number by 7 and round to the higher number, regardless of the remainder.

Last Friday was 11 divided by 7, so 1 week + 4 days is the second week. Tuesday's number is 15 divided by 7, so it's 2 weeks + 1 day, so week 3. Right?

You can do without rounding. If the remainder of the division is greater than zero, then the resulting number of full weeks plus 1. Right?


I am trying to reproduce the method you suggest - where am I wrong?

1 Week2 Week3 Week4 Week5 Week1 Week2 Week3 Week4 Week5 Week
1 8 15 22 29 0 1 2 3 4
2 9 16 23 30 0 1 2 3 4
3 10 17 24 31 0 1 2 3 4
4 11 18 25 1 2 3 4
5 12 19 26 1 2 3 4
6 13 20 27 1 2 3 4
7 14 21 28 1 2 3 4
Reason: