[SERVICE DESK] Error in getting the time of the senior TF in the timer! - page 6
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
It seems that the most reliable solution is really to wait for call of OnCalculate() with obligatory check of connection to trade server. If we do not check for connection (IsConnected()), then even in OnCalculate() we will get it at terminal loading:
However, it does not remove all questions:
1. Why doesn't it written in documentation to IsConnected() that it must be necessarily called before receiving data (at least) from the senior TF in OnCalculate()?
2. Why IsConnected() in OnTimer() actually does not work? Isn't the fact of establishing connection with a trade server supposed to tell us that data can be obtained?
3. Once we have established a connection with the trade server and are trying to receive data in OnTimer(), shouldn't functions iTime(), iBarShift(), SeriesInfoInteger() and functions similar to them return errors if data from this particular trade server, from which they take information, are not yet synchronized? Otherwise it turns out some nonsense, like we return error 4066 to you once and then you can use the data you have.
I have talked to the developers and one of my friends there and I am telling them the following: 1 What do I do?
1 Nonsense, you can call it whenever and from anywhere.
2 IsConnected can be called from anywhere in the code and it works, but it is a function that does not write anything on the error stack it returns true/false and that's it. Considering that the connection procedure is quite (minimum 1 sec) long and IsConnected is triggered at login time, it is necessary to check the connection status and wait for the start of quotes flow when starting the terminal.
3 These functions don't write anything to the error stack, they return the result themselves.
Why did we get 4066? That error was caused by the TimeCurrent function. Terminal logged in and requested time from the server depending on the connection quality it also takes some time, so we have a quick timer. And then we got 4066 on our request from TimeCurrent. And then we got the time and our functions started working normally and they themselves return an error as a result of their work bypassing the error stack.
As a recommendation in such situation, quick timer and terminal start, be sure to check that we started getting data from the server. My version is a bit crutchy, it would be correct to get a signal from OnCalculate to start receiving data.
What do you suggest to solve the problem (is there, in your opinion)? Wait until OnCalculate() is called 1-2 times?
Yes, exactly. In OnInit() just call the required TFs without checking the result (you cannot rely on it there), and in OnCalculate call the function IsTFDataReady(). As soon as true is returned for all requested TFs, you can start to execute the indicator's algorithm.
1. Why doesn't the documentation for IsConnected() say that it must always be called before receiving data (at least) from the senior TF in OnCalculate()?
IsConnected() is quite a tricky function. It returns state of only one connection to server. But the terminal uses more than one connection. There are 8 trade threads by itself. So even if IsConnected() returns true, it is not quite clear what it means. At least, we cannot expect that timeseries will be requested and built. But if IsConnected() returns false, then we can be sure that the terminal is still offline.
What is the task, for which the presence of the terminal connection is so crucial? As far as I understand, the indicator is a tool for visualizing data. The data that is available. When new data arrives, it will update the visualization. It should not be required to check whether the data is up to date. That is the task of the terminal.
I guess we are talking about MQL5, OHLC preparation is not the same as in MT4
I'm talking about MT4. About 2-3 years ago I was catching a bug with Time[0]. The developers seem to have fixed it, but then, over time, it showed up again. The problem is that it's impossible to unambiguously reproduce this bug.
IsConnected() is a rather tricky function. It only returns the status of one of the connections to the server. But the terminal uses more than one connection. There are 8 trade threads alone. So even if IsConnected() returns true, it is not quite clear what it means. At least, we cannot expect that timeseries will be requested and built. But if IsConnected() returns false, then we can be sure that the terminal is still offline.
What is the task, for which the presence of the terminal connection is so crucial? As far as I understand, the indicator is a tool for visualizing data. The data that is available. When new data arrives, it will update the visualization. It should not be required to check the relevance of data. This is the task of the terminal.
For indicators I don't remember the necessity to check the connection with the server, what we have in the history is drawn, when the history is loaded it means that all indicator buffers are recalculated
I have developed and use the following function in my EA. It is generally satisfying and it checks the connection with the server correctly:
I specifically use Sleep() in it to transmit control to the terminal and then check connection to the server and possibility to trade
I'm talking about MT4. About 2-3 years ago I was catching a bug with Time[0]. The developers seemed to have fixed it, but then, over time, it showed up again. The problem is that it's impossible to unambiguously reproduce this bug.
If it's not too much trouble, here's the topic of the topic - correct downloading of history from the major TF, here's the indicator: "I need to draw the MA" from the major TF on the bars of the minor TF, I made it within 5 minutes, it will work for 98% correctly, where in this code 2% "pitfalls" that will cause bugs?
I am interested in correct code for MT4
I talked to the developers and a friend I know there, and I'll tell you one thing at a time.
1 Nonsense, you can call it whenever and from any place.
2 IsConnected can be called from anywhere in the code and it works, but it is a function that does not put anything on the error stack, it returns true/false and that's it. Considering that the connection procedure is quite (minimum 1 sec) long and IsConnected is triggered at login time, it is necessary to check the connection status and wait for the start of quotes flow when starting the terminal.
3 These functions don't write anything to the error stack, they return the result themselves.
Why did we get 4066? That error was caused by the TimeCurrent function. Terminal logged in and requested time from the server depending on the connection quality it also takes some time, so we have a quick timer. And then we got 4066 on our request from TimeCurrent. And then we got the time and our functions started working normally and they themselves return an error as a result of their work bypassing the error stack.
As a recommendation in such situation, quick timer and terminal start, be sure to check that we started getting data from the server. My variant is a bit crutchy, it would be correct to get a signal from OnCalculate to start receiving data.
1. Read carefully what I write. It's not the first time I told you so! I didn't say anything about not calling somewhere!
Are you saying that all functions iBarShift(), iTime(), SeriesInfo...() request TimeCurrent()?