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

 

Salud! Help :)

From indicator (mt5) a tick history is copied for further processing. I copied the algorithm from the reference book, I only changed it a bit:

         int     attempts = 0;
         bool    success = false;
         MqlTick tick_array[];
         datetime startCopyTime = (copyTickTime < periodStartTime) ? periodStartTime : copyTickTime;
         datetime checkPoint;

         while(attempts < 3) {
            uint start = GetTickCount();
            checkPoint = TimeCurrent();
            int received = CopyTicks(_Symbol, tick_array, COPY_TICKS_ALL, startCopyTime, ticksSizeToCopy);
            if(received != -1) {
               PrintFormat("%s: received %d ticks in %d ms", _Symbol, received, GetTickCount() - start);
               if(GetLastError() == 0) {
                  success = true;
                  break;
               } else
                  PrintFormat("%s: Ticks are not synchronized yet, %d ticks received for %d ms. Error=%d",
                              _Symbol, received, GetTickCount() - start, _LastError);
            }
            attempts++;
         }
         if(!success) {
            PrintFormat("Ошибка! Не удалось получить %d тиков по %s с трех попыток", ticksSizeToCopy, _Symbol);
            return;
         }
         copyTickTime = checkPoint;

But I got a warning, the tick history is out of sync:

2020.07.12 10:07:12.092 Volumes (GBPUSD,H1)     GBPUSD: Ticks are not synchronized yet, 10103745 ticks received for 532 ms. Error=4403

And in the handbook it says:

ERR_HISTORY_TIMEOUT

4403

Timeout exceeded on history request

Captain's intuition tells me to synchronize the ticks... is this the point I'm trying to make? How to do it? Or it is possible to work without much harm even without synchronization, just by removing success check ?

 
Yevhenii Levchenko:

Salud! Help :)

A tick history is copied from an indicator (mt5) for further processing.

The indicators have asynchronous access to history data, while the Expert Advisors and scripts have synchronous access, or at least that's how the MQL programs developers call the behavior when working with data

in human language, when accessing history data in the indicator, you need to exit the calculation cycle with an error, and after a while you need to reapply to the history

And it doesn't make sense to call the history in the indicator several times in a loop - this method works only in Expert Advisors and scripts

 
Igor Makanu:

In indicators asynchronous access to historical data, in Expert Advisors and scripts - synchronous access, or at least that's how the developers call the behavior of MQL programs when working with data

in human language, when accessing history data in the indicator, you need to exit the calculation cycle with an error, and after a while you need to reapply to the history

and it doesn't make sense to call the history several times in the indicator - this method works only in Expert Advisors and scripts

Thank you!

Is synchronous related to multithreading? "Ticks are not synchronized yet" - it turns out more like a warning?

 
ANDREY:

Nonsense... You are not good at logic, you are not good at maths ..... and at the same time you have long and successfully moderated a forum whose theme is permeated by both logic and maths.

Where did I say that I am not good at logic?

 
ANDREY:

I think that the knowledge possessed by a bunch of specialists was not the knowledge of Ford himself and never became it. Moreover - he had no need for this knowledge, because he called it unnecessary. And if these experts tried to pass on their knowledge to Ford, he would not be able to assimilate it and use it for practical purposes. It is necessary to have more than a general idea of the subject, which is associated with new knowledge, in order to absorb it. In the example given above, the experts did not provide knowledge to Ford, but to lawyers.

And in your brain, as it seems to me, you have a sufficient amount of systematized knowledge in mathematics and logic and this kit allows you to quickly and correctly formulate a search query for new and missing information and quickly and correctly interpret it. I am sure that in your brain can not be no such information, since every day for many hours spent on this forum and passed through his brain a lot of information associated specifically with mathematics and logic. It is like learning a foreign language by immersion. It is learned automatically, spontaneously and maybe even against the will of the learner.

If 100 academicians start explaining to me the rules of calculating the integral equations, I will not learn how to do it until they fill my head with all the maths and algebra textbooks, which I had to study at school before the teacher started explaining integral equations.

If you don't understand what a variable is and what it's for, it's hard to understand even knowing what a variable is, to say nothing of other concepts that aren't even very complicated.

Ford didn't say that he would be taught the right thing in his area of interest. He said that he was surrounded by so many specialists in different fields that he could get answers to the questions he needed at any given moment. Why does a manager need to know what 200 specialists can know, each of them will give the right answer in his area? It is impossible to know everything in principle. But to quickly get the answers to the problems you need with the help of specialists - this is what Ford was talking about, this is what I said about reference books and using the right information. And that is in some narrow area this resource provides in the form of CodeBase and a forum.

 
Yevhenii Levchenko:

Thank you!

Is synchronised related to multithreading? "Ticks are not synchronized yet" turns out to be more of a warning?

no

The developers imply that synchronous means some kind of guaranteed processing of historical data when calling history functions, but it doesn't guarantee that the data is necessarily returned when queries are made

... here's the non-human language ))))


asynchronous is a query and data or an error. After an error occurs, synchronization starts, but the end time of synchronization (or TF building) is unknown and because of the high performance of MT5 you get an error every time instead of synchronized data

ZS: in MT5 everything is complicated there.... there is a server, there is a terminal and finally our MQL-program. When requesting the history you have to synchronize the server - terminal and then the terminal - MQL-program, someone may not have ready timeframes or tick data

 
Igor Makanu:

no

The developers imply that the synchronisation is some kind of guaranteed processing of historical data when calling history functions, but it does not necessarily guarantee the return of the data when queried...

... here's the non-human language ))))


asynchronous is a query and data or an error. After an error occurs, synchronization starts, but the end time of synchronization (or TF building) is unknown and because of the high performance of MT5 you get an error every time instead of synchronized data

ZS: in MT5 everything is complicated there.... there is a server, there is a terminal and finally our MQL-program. When requesting the history you should synchronize the server - terminal and then the terminal - MQL-program, someone may not have ready timeframes or tick data

The easier answer is something like this:

To wait for synchronization in the indicator, you should simply exit OnCalculate() with return 0 after receiving an error;

In this case first access to historical data starts the process of data synchronization and it is only left to check its completion. If there is an error receiving data, then return zero - since zero indicates the amount of already calculated data on the previous call (prev_calculated), and at current call and successful loading of historical data OnCalculate() will be calculated on the entire history depth (since by returning 0 we thereby indicated at previous call that nothing has been calculated).

 
a.lxrn:

Good afternoon everyone, can you please help me to solve this problem, the problem is in logic, I've broken my brain today and I've come to the point where I'm in a mess.

I have written an elementary code sample, there is a signal if candle's close is bigger than waggon, one order is opened.

The signal will stay and stay true for a long time. I am sure you know what I mean,

I am sure you understand what I mean. Actually, how should I make a signal to buy open one order and that's it, until the situation changes and the close price is lower than the price of the wave.

I can use flags, but they will not save the order when it closes and it opens or delays for 15 minutes. It is even cooler when the conditions for opening and closing orders are true at the same time. On every tick an order)))) Flags are if the signal to open the order is true and the flag that the order is open is false, then we open the order. And if the flag that the order is open is true, the order will not open). A delay is easier and more efficient. After the order is closed, we set a delay.

 
Igor Makanu:

asynchronous is a query and data or an error, and after an error the synchronization starts, but the time of the end of synchronization (or TF building) is unknown and because of the high performance of MT5 you get an error every time you call again instead of synchronized data

ZS: in MT5 everything is complicated there.... You have a server, a terminal and finally our MQL-program. When requesting the history you need to synchronize server - terminal and then the terminal - MQL-program, someone may have unready timeframes or tick data


Approximately got it ... Thanks :)

Artyom Trishkin:

It was easier to answer approximately like this:

In order to wait for synchronization in an indicator, you have to exit OnCalculate() with return 0 after receiving an error;

In this case the first access to historical data starts the process of data synchronization and it is only left to check its completion. If there is an error receiving data, then return zero - since zero indicates the amount of data already calculated on the previous call (prev_calculated), and at current call and successful loading of historical data OnCalculate() will be calculated on the entire history depth (since by returning 0 we thereby indicated on the previous call that nothing has been calculated).

Simpler does not mean clearer :)

Switched to stock instruments and it only printed once that they were out of sync. Subsequent queries didn't show anything else like that.

Can you tell me why the tester doesn't show volumes?
 
Yevhenii Levchenko:

Roughly understood... Thanks :)

Simpler doesn't mean clearer :)

Switched to stock instruments and it only printed once that they were out of sync. Subsequent queries didn't show anything else like that.

Can you tell me why the tester doesn't show volumes?

To keep historical data in actual "hot" state, you need to access this data once every two minutes using any of CopyXXX, iXXX functions, for example CopyTime(), iTime(), etc...

I don't know what volumes you don't get in the tester. There are real and tick volumes. Without code it's impossible to answer in essence.

Reason: