Questions from Beginners MQL5 MT5 MetaTrader 5 - page 116
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
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.