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

 
Nikolay Ivanov #:

Your code prints 0, not -1...

Maybe -1 is printed somewhere else, most likely the whole code is in the printers...

Yes, you're right, each step is preprinted to see where it "stalled".

Example is incorrect, sorry, the code itself is big.

But, Konstantin's solution solved the problem! Really swapped i-- and zero check everywhere, and now the logic works as it should, instead of -1 it outputs 0 or 1. (before 0 or -1, with the latter an error immediately).

 
Nikolay Ivanov #:

Your code prints 0, not -1...

It is possible that -1 is printed somewhere else, most likely the whole code is in the printers...

Before you try to solve the problem, you need to identify it... Make sure it's there and locate it before you solve it...

Get a pen and a piece of paper. And write down how the loop counts. In this code.

void OnStart()
  {
int i=10;
for (i; i>0; i--)
{
i--;
if (i==0) break;
}

Print(i);
  }

checking

if (i==0) break;

will never work in this code. Unless you initially set

int i=11;

an odd value. If it's even, this code will

int i=10;
for (i; i>0; i--)
{
i--;
if (i==0) break;
}

to

if (i==0) break;

will come with an odd value.

 
Nikolay Ivanov #:

Before trying to solve a problem, you need to identify it... Make sure it's there and localise it, and then solve it...

I see what you mean.

 
Konstantin Nikitin #:

Get a pen and a piece of paper. And write down how the cycle counts. In this code.

Why would I take pen and paper if the condition says print =-1, but in fact (I checked) it prints as 0, i.e. the example is given incorrectly. And it is impossible to give a correct answer to an incorrect example...

 
Nikolay Ivanov #:

Why would I take pen and paper if the condition says print =-1, but in fact (I checked) it prints as 0, so the example is incorrect. And it is impossible to give a correct answer to an incorrect example...

Zero is printed from this line

for (i; i>0; i--)

and not from the check and break output.

In general, the correct way to pass an array is to write

for (i; i>= 0; i--)

because arrays start with a zero index

 
Konstantin Nikitin #:

Zero is printed from this line

not from break check and exit.

0 is printed from this line, for that code which was given...

Print(i);

The question wasn't why break doesn't work, the question was why the printer printed -1... that's all. And it doesn't matter whether the i start is even or odd, it never prints -1...

 
Can you please tell me how to calculate ticks or candles over a long period of time? (A year, for example).

Trying Close[], but the index does not give more than 5000.
 
Ivan Butko #:
Can you please tell me how to calculate ticks or candles over a long time period? (A year, for example).

I tried Close[], but the index does not give more than 5000.

Ticks or candles make such a big difference, it's scary to say the least...

 
Alexey Viktorov #:

There's so much difference between ticks and candles that it's scary to say...

For example, an EA, if you specify any period for it, in the tester it will go by ticks or by M1 bars, everyone will take it into account.

But if you take an EA that goes to the long history in real time and takes data from there, I don't understand how to organise it. Terminal doesn't give more than 5000 candles.


UPD
I will try to use this thing, code is on the net

MqlRates rates[];

   int copied=CopyRates(NULL,0,0,100,rates);

   if(copied<=0)

      Print("Ошибка копирования ценовых данных ",GetLastError());

   else Print("Скопировано ",ArraySize(rates)," баров");


UPD
Strange. All of a sudden it works. Even millionth bar is checked. Didn't do anything, read documentation, drank tea. Just ran it again and it worked. I had error all day long, although I had downloaded the history and changed the settings yesterday.
So, there was no need to check additional code (above) either.
MT4 is some temperamental. Or maybe forex chif has such a peculiarity. I'll have to put the standard one instead of the broker's one.

 
Ivan Butko #:

For example, an Expert Advisor, if you give it any period, it will go through the tester by ticks or by M1 bars, everyone will take it into account.

But if you take an Expert Advisor, which in the real time mode goes to the long history and takes data from there, I do not understand how to organise it. Terminal doesn't give more than 5000 candles.


UPD
I will try to use this thing, code is on the net

MqlRates rates[];

   int copied=CopyRates(NULL,0,0,100,rates);

   if(copied<=0)

      Print("Ошибка копирования ценовых данных ",GetLastError());

   else Print("Скопировано ",ArraySize(rates)," баров");


UPD
Strange. All of a sudden it works. Even millionth bar is checked. Didn't do anything, read documentation, drank tea. Just ran it again and it worked. I had error all day long, although I had downloaded the history and changed the settings yesterday.
So, there was no need to check additional code (above) either.
MT4 is some temperamental. Or maybe forex chif has such a feature. I'll have to put the standard one, not the brokerage one.

The first call to CopyRates() has initiated pumping of historical data (don't run it for a week and you will get the same thing again, well, maybe not a week, but some time).
You just need to check how much data there is on the server and compare the available amount to the Expert Advisor. If it is less than it is required - leave the EA until the next tick. At the next tick, check again. If for some amount of attempts the required history is not obtained - then this error should be processed as it is required.

Reason: