Errors, bugs, questions - page 2888

 
Denis Diakonov:

Can you tell me please!

Why isn't the server time updated when new ticks come in?

At the moment when EA starts, everything works as it should, but then the time goes, but new value of the current minute does not come into the variable.

I.e., the Expert Advisor works depending on the number obtained in the variable int M = TimeMinute(TimeCurrent());

Actually this code line is from the reference and it doesn't work.

For example, I start it at 12 - the current time returned by the server corresponds to the time in the variable, but the variable still stays at 12, although it is already 15-20 minutes on the clock

TimeMinute() is not available in MQL5.

Questions on MQL4 should be posted in the corresponding MetaTrader 4 branch.

If you want a cross-platform solution, use MqlDateTime.

Документация по MQL5: Константы, перечисления и структуры / Структуры данных / Структура даты
Документация по MQL5: Константы, перечисления и структуры / Структуры данных / Структура даты
  • www.mql5.com
Порядковый номер в году day_of_year в високосном году, начиная с марта, будет отличаться от порядкового номера соответствующего дня в невисокосном году.
 
That's a dubious warning:
void OnStart()
{
    for ( int i = 0, j; i < 10; i = j ) //(1) Warning: possible use of uninitialized variable 'j'
    {
        j = i+1;
    }
}

but that's fine:

void OnStart()
{
    for ( int i = 0, j; i < 10;       ) //(2) нормально
    {
        j = i+1;
                                i = j;
    }
}

what's the fundamental difference?

 
A100:
That's a rather dubious warning:

but that's fine:

what's the fundamental difference?

Correct warning. The variable j is not initialized before its first use, when the variable i is assigned a value of j.

And in the second variant, the j variable is assigned the value i+1 and only then i = j

This is how it should be without a warning, but it hasn't been tested...

void OnStart()
{
    for ( int i = 0, j = 0; i < 10; i = j )
    {
        j = i+1;
    }
}
 
Alexey Viktorov:

Correct warning.

for the alternatively gifted, these are identical cycles
 
TheXpert:
for the alternatively gifted, these are identical loops

So what, this identity of loops allows the use of unidentified variables?

 
Alexey Viktorov:

So what, this identity of loops allows the use of unidentified variables?

If the loops are identical, then the compiler behaviour should be the same, and it is different. That's where the error lies. You've explained why there is a warning in case (1), then explain why there isn't one in case (2) ? What has changed in principle? And then, if an uninitialized variable is used, why is the final result right when executing the code?

There is such a science - logic. If A and B are the same and A is red, then B should also be red, not green

 
A100:

If the loops are the same, then the compiler behaviour should be the same, and it is different. This is where the error lies. You explained why there is a warning in case (1), then explain why there isn't one in case (2) ? What has changed in principle? And then, if an uninitialized variable is used, why is the final result right when executing the code?

There is such a science - logic. If A and B are the same and A is red, B must also be red, not green.

There is no random number there. There is a zero there.
MQ has fixed it too ))

void OnStart()
{
   int val;
   
   Print(val);
   Print(IntegerToString(val));
}
 
Roman:

There is no random number there. There's a zero there.
MQ has fixed that too ))

First you need to check - then "bullshit".

void OnStart()
{
        for ( int i = 0, j; i < 10; i++ )
        {
                Print( j );
                break;
        }
}

Result: -2052256859


 
A100:

You need to check first - then "talk rubbish".

Result: -2052256859


void OnStart()
{
   for ( int i = 0, j; i < 10; i++ )
   {
      Print( j );                
   }
}
2020.10.27 17:14:46.623 TestScript (NZDUSD,M1)  0
2020.10.27 17:14:46.623 TestScript (NZDUSD,M1)  0
2020.10.27 17:14:46.623 TestScript (NZDUSD,M1)  0
2020.10.27 17:14:46.623 TestScript (NZDUSD,M1)  0
2020.10.27 17:14:46.623 TestScript (NZDUSD,M1)  0
2020.10.27 17:14:46.623 TestScript (NZDUSD,M1)  0
2020.10.27 17:14:46.623 TestScript (NZDUSD,M1)  0
2020.10.27 17:14:46.623 TestScript (NZDUSD,M1)  0
2020.10.27 17:14:46.623 TestScript (NZDUSD,M1)  0
2020.10.27 17:14:46.623 TestScript (NZDUSD,M1)  0

Maybe it's because I have the test terminal installed on VirtualBox
Also, the compiler doesn't warn that the variable is not initialized.

But it warns like this

void OnStart()
{
   for ( int i = 0, j; i < 10; i++ )
   {
      Print( IntegerToString(j) );                
   }
}
 
Roman:
Probably because I have the test terminal installed on VirtualBox

You have a random number 0, I have 540016640

2020.10.27 17:24:25.244 0011 (EURUSD,H4)        540016640
2020.10.27 17:24:25.244 0011 (EURUSD,H4)        540016640
2020.10.27 17:24:25.244 0011 (EURUSD,H4)        540016640
2020.10.27 17:24:25.244 0011 (EURUSD,H4)        540016640
2020.10.27 17:24:25.244 0011 (EURUSD,H4)        540016640
2020.10.27 17:24:25.244 0011 (EURUSD,H4)        540016640
2020.10.27 17:24:25.244 0011 (EURUSD,H4)        540016640
2020.10.27 17:24:25.244 0011 (EURUSD,H4)        540016640
2020.10.27 17:24:25.244 0011 (EURUSD,H4)        540016640
2020.10.27 17:24:25.244 0011 (EURUSD,H4)        540016640

but they're still random numbers.