[SOLVED] Indicators are not properly instantiated when called/created from an Indicator of different working time-frame. - page 2

 
Alain Verleyen:

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.

Perhaps I didn't properly articulate that no matter how many loops and waiting, you will not be able to access the indicator data (of different TF) until after the first pass of (*edit) OnCalculate();

I'm perfectly willing to accept that I may be wrong, which is why I have a $10 bounty if you can demonstrate otherwise. Please... prove me wrong. I need a workaround for this stupid bug, sorry, I mean "feature".

 
nicholishen:

Perhaps I didn't properly articulate that no matter how many loops and waiting, you will not be able to access the indicator data (of different TF) until after the first pass of (*edit) OnCalculate();

I'm perfectly willing to accept that I may be wrong, which is why I have a $10 bounty if you can demonstrate otherwise. Please... prove me wrong. I need a workaround for this stupid bug, sorry, I mean "feature".

Why do you need it on the first "pass" ? If needed data are not available, wait until they are, that's all.
 
Alain Verleyen:
Why do you need it on the first "pass" ? If needed data are not available, wait until they are, that's all.

Because I am developing an indicator that requires the access of data from the same indicator (same symbol) on a different time-frame.  Since it will not process until after the second tick, this means the indicator will not work offline, and only works when the second tick comes in. 

Why should we have to compromise because of this bug? What's in it for you to so furiously defend it?

 
nicholishen:

Because I am developing an indicator that requires the access of data from the same indicator (same symbol) on a different time-frame.  Since it will not process until after the second tick, this means the indicator will not work offline, and only works when the second tick comes in. 

Why should we have to compromise because of this bug? What's in it for you to so furiously defend it?

???

I don't defend anything, and certainly not "furiously". Please stay cool. 

 
Alain Verleyen:

???

I don't defend anything, and certainly not "furiously". Please stay cool. 

OK.

 

I posted this job in case anyone is interested in taking a crack at it.

 

https://www.mql5.com/en/job/57516 

 
nicholishen:

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)

You understand the word "availability" too literally. While some data can exist in the terminal memory, the terminal itself may contain some synchronization logic which block updates for any timeframes while underlying data is checked for one (probably another) timeframe. Or they can block data requests from an indicator until it finishes its own creation (please, remember that indicators are managed by so called handles, whereas experts and scripts do not) and this is logical to me. These are just guesses, which I made from the point of view of MQ developers. You can ask them directly via th service desk.

Your job is impossible to accomplish due to the point 3:

3. Must access buffer on Initialization 

This is just against the terminal architecture and documentation:

You can't refer to the indicator data right after it has been created, because calculation of indicator values requires some time

 Also please read about CopyBuffer function:

Note

When requesting data from the indicator, if requested timeseries are not yet built or they need to be downloaded from the server, the function will immediately return -1, but the process of downloading/building will be initiated.

When requesting data from an Expert Advisor or scriptdownloading from the server will be initiated, if  the terminal does not have these data locally, or building of a required timeseries will start, if data can be built from the local history but they are not ready yet. The function will return the amount of data that will be ready by the moment of timeout expiration.

 

 So, experts and scripts are processed synchronously until a predefined timeout, but indicators - asynchronously.

Documentation on MQL5: Technical Indicators
Documentation on MQL5: Technical Indicators
  • www.mql5.com
Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
 
As for your specific task, it can be easily done in other way. You're not the first who builds an indicator on indicator and wants it to work offline. Use a timer.
 
Stanislav Korotky:
As for your specific task, it can be easily done in other way. You're not the first who builds an indicator on indicator and wants it to work offline. Use a timer.
Tried it. Didn't work.
 
nicholishen:
Tried it. Didn't work.
Post more specific question with a sample code. It may be buggy. The approach works for me.
 
Stanislav Korotky:
Post more specific question with a sample code. It may be buggy. The approach works for me.
I don't understand how I can be more specific than I already have...

 No amount of timers or loops can overcome the fact that the indicator won't instantiate until after Oncalculate returns at least once. Recursion doesn't work either.
Reason: