how to be sure that a custom indicator have been already loaded into the chart?

 

Hello, I would like to know how to be sure that a custom indicator have been already loaded into the chart?

I have an script, then inside it I create an instance of a custom indicator (slower than built-in indicators) and add it to the chart.

After that I read some values of the custom indicator but I have some troubles because, for periods like: H1, M30, M20 there is no problems, but if I use M1, then when I read values from the custom indicator I don't get correct values. If I put an "Sleep(2000);" then I can read the correct values but I think this is not a good way to take. Do you know if is there some better way like callbacks/event handlers?, so I can start the reading after I know that the custom indicator have been already loaded?

Thank you!

 
you have it set a flag at the end of the calculation, and only read data once the flag is up or you make sure to pull the data to zero or to -1 for as long as it is still calculation then when the calculation is done you assign the correct value this way it can only read 0 or the correct product and you can see if it returns 0 or -1 you know it isn't done yet and try again until you get something !=0 different then zero then u can assume it is the correct value.
 
Marco vd Heijden:
you have it set a flag at the end of the calculation, and only read data once the flag is up or you make sure to pull the data to zero or to -1 for as long as it is still calculation then when the calculation is done you assign the correct value this way it can only read 0 or the correct product and you can see if it returns 0 or -1 you know it isn't done yet and try again until you get something !=0 different then zero then u can assume it is the correct value.
thank you Marco, I don't like too much that way because it add dummy stuff inside the indicator and maybe I don't have the indicator source code. what do you think about, inside the script, copying the data from the indicator to an array and then check the first and last values of that array to check if they are incorrect values?, the problem is that I have to read the buffers only for that. I don't know how good could be this.
 

im not sure how fast the data changes otherwise you would get problems just because values are changing again ,but indeed if you got a couple of the same hits it's probably loaded.

so you just check it in a for loop and once it starts to read equal values you break out of the loop and continue.

 
Marco vd Heijden:

im not sure how fast the data changes otherwise you would get problems just because values are changing again ,but indeed if you got a couple of the same hits it's probably loaded.

so you just check it in a for loop and once it starts to read equal values you break out of the loop and continue.

I think I'm going to take that way. It is a pitty that mql5 don't block until the indicator is completely loaded when you call: "IndicatorCreate", then we have to take these kind of workarounds :(

thank you Marco.