UPDATE: See the workaround below
CopyBuffer() throws an error of 4806 (Indicator data not accessible) when calling an indicator with a different Time-Frame from within the code of an indicator. It happens when calling a valid Indicator handle to a different Time-Frame from the current working time-frame. The bug only appears during initialization and the first call to OnCalculate() BEFORE the first tick data. In order to isolate the bug the following methods were applied:
This is the block of code used to test the output of CopyBuffer() when called from a script, EA, and indicator.
Full indicator code:
The only way to not receive an error is to launch this on H1 charts (same TF).
Links to forum post with same issue:
The workaround was to Create the indicator in OnInit() and set EventSetMillisecondTimer to 1ms. This allowed the OnCalculate() to return after its first pass and quickly call OnTimer for a second pass. Only one call to the OnTimer event was necessary to fix it and no further time delay was required for calculations.
I am afraid this is not a bug in MT5 but a bug in your code. By the way, like all topics your reported. You have to deal with the platform/language as it was designed, not like you think it is or would like it to be.
Why are you using ima.Create() in OnCalculate() ? You get an handle but the data are not yet available, you get an error then your code is never called again.
Ok you don't believe me, that's your right, but you are wrong
I can only suggest you to write to ServiceDesk, and please report their answer here.
Because all indicators for a symbol run on the same thread. Strategy Tester, EA and script are different situations.
Though let's see ServiceDesk answer. Maybe I am wrong :-)
Let's consider this to be the case...
This means that if the data is immediately available to a script or EA then it would be equally available to Indicator (as in this is not a data availability issue). The indicator is simply failing to instantiate before the second pass of OnCalculate() (aka the first tick)
I took this into consideration during the diagnostics. I even incorporated loops and waiting period, just in case. Like everyone before me, I'm having the same issues with this particular bug.
You are repeating "failing to instantiate", but that's not exact. The indicator is instantiated in all cases.
The problem is the data are not available synchronously, you have to deal with it. It's NOT an MT5 bug, it's a FEATURE.
I propose to stop the discussion and wait SD answer.