In principle it was, the error was probably in the fact, that my indicator handle is created in the OnTick function and data is copied immediately on the same tick. I have understood it at night, now I will try to transfer indicator handles to OnInit function.
sss20192: The error was in the indicator handle created in the OnTick function and data are copied on the same tick. I have understood it at night, now I will try to transfer indicator handles to OnInit function.
But so far you have neither a check for successful creation of handles, nor a check for successful calculation of indicators and check for copying. The idea to move initialization of handles to OnInit() is correct.
Also, add the Print(MacdArray[0]) line at the beginning of OnTick() - to see what rubbish value is contained in the array before you start copying buffers.
To add. Of course, using GetLastError() after the function itself may be a peculiarity of programming style. But I still would check it relying on the example from the Reference. If I'm not mistaken, a null value of GetLastError() does not always mean that the function worked successfully.
Yedelkin: But so far you have neither a check for successful creation of handles, nor a check for successful calculation of indicators and check for copying. The idea to move initialization of handles to OnInit() is correct.
But only for the first time. If in any other place of the program it turns out that some handle is invalid, we have to try to get it again. Therefore, we cannot say that code written for getting handles in OnInit() will completely solve the issue and be 100% correct. ))
Yedelkin: The idea to move initialization of handles to OnInit() is a good one.
But only for the first time. If anywhere else in the program it turns out that some handle is invalid, you have to try to get it again. Therefore, we cannot say that code written for getting handles in OnInit() will completely solve the issue and be 100% correct. ))
Are you saying that the idea of moving the initialization of handles to OnInit() from OnTick() is wrong in itself?
Yedelkin: Are you saying that the idea to move handler initialization to OnInit() from OnTick() is wrong by itself?
If only in OnInit() and nowhere else, then yes - wrong. The first time we try to get a handle in OnInit(). Then, before each attempt to obtain indicator data, we check if the handle is valid. If it is valid, we get the data, if not, we try to get the handle again.
Yedelkin: Are you saying that the idea of moving the initialisation of handles to OnInit() from OnTick() is wrong by itself?
If only in OnInit() and nowhere else, yes - wrong. The first time we try to get a handle in OnInit(). Then, before each attempt to get indicator data, we check if the handle is valid. If it is valid, we get the data, if not, we try to get the handle again.
And without "if"? And in relation to this particular situation? The indicator handle was created in the OnTick functionduring every tick, and the data is copied during the same tick. It means that the same indicator handle was requested each time, without checking for validity/invalidity. Against this background, will you continue to argue that the idea of transferring the initialization of handles to OnInit() from OnTick() is wrong by itself?
PS. It seems that you have helped the man, so the question may be considered exhausted.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
The error was in the indicator handle created in the OnTick function and data are copied on the same tick. I have understood it at night, now I will try to transfer indicator handles to OnInit function.
It didn't work. Here's the code now
The following messages appear in the log
2013.04.13 15:21:31 2010.01.04 00:00:01 6.187448020344988e-005 0
2013.04.13 15:21:31 2010.01.04 00:00:01 6.187448020344988e-005 0
2013.04.13 15:21:31 2010.01.04 00:00:01 6.187448020344988e-005 0
And it's always like that. There doesn't seem to be a copying error.
But so far you have neither a check for successful creation of handles, nor a check for successful calculation of indicators and check for copying. The idea to move initialization of handles to OnInit() is correct.
Also, add the Print(MacdArray[0]) line at the beginning of OnTick() - to see what rubbish value is contained in the array before you start copying buffers.
To add. Of course, using GetLastError() after the function itself may be a peculiarity of programming style. But I still would check it relying on the example from the Reference. If I'm not mistaken, a null value of GetLastError() does not always mean that the function worked successfully.
But so far you have neither a check for successful creation of handles, nor a check for successful calculation of indicators and check for copying. The idea to move initialization of handles to OnInit() is correct.
tol64:
But only for the first time. If anywhere else in the program it turns out that some handle is invalid, you have to try to get it again. Therefore, we cannot say that code written for getting handles in OnInit() will completely solve the issue and be 100% correct. ))
I checked how much data was copied with CopyBuffer function, it always writes 1. And there is no error, but data is still wrong.
I have this result of this code in the tester:
//---
The only thing I did before the test was just converted indicator values before output to the log:
Are you saying that the idea to move handler initialization to OnInit() from OnTick() is wrong by itself?
I got this result of this code in the tester:
//---
The only thing I did before the test was to simply convert the indicator values before outputting to the log:
And without "if"? And in relation to this particular situation? The indicator handle was created in the OnTick function during every tick, and the data is copied during the same tick. It means that the same indicator handle was requested each time, without checking for validity/invalidity. Against this background, will you continue to argue that the idea of transferring the initialization of handles to OnInit() from OnTick() is wrong by itself?
PS. It seems that you have helped the man, so the question may be considered exhausted.