I am trying to write an EA that needs to make calculations using the values of various symbols. The problem I have encountered is that the values of other currencies are updated only when a new tick of the chart symbols comes in, and not every time other currencies change.
To make it clearer, my EA runs on symbol X and it needs the values of currencies Z and Y. The problem is that the values of Z and Y are read only when X changes, whereas if X does not change but Z and Y change the new values of Z and Y will be updated only when a new tick of symbol X comes in.
The solution I thought of was to make the EA run a continuous loop. I'll attach a simple code that show how I was thinking of writing it.
ObjectSetText("X100","EUav: " + DoubleToStr(euav,5),12,"Arial",White);
ObjectSetText("X101","EJav: " + DoubleToStr(ejav,3),12,"Arial",White);
But even with this code the value of EURJPY is updated only when a tick of EURUSD arrives, and not when EURJPY changes. What is wrong with it?
Have you checked it with timestamps?
I think EURJPY has less ticks than EURUSD - may be this is the problem?
Remark: Either return once and a while from your endlesse loop or(and) place an isStooped() in your loop.
You can set a timer.
Thanks but IsStopped() doesn't solve the problem, and I don't understand what you mean by "return once and a while" from my loop.. how would I do that?
Thanks a lot, from what I read setting a timer would be a perfect solution! I was also thinking.. how about running a script on the charts for every currency I need and update the pricing to a common/global variable in the library? Which one would be more economical on the CPU?
It is my experience without IsStopped() I have to kill the terminal to stop the endelss loop (at least in a script). IsStopped() would allow a 'nicer' end.
I have no knowledge about the mt4-internals, but may be within the endless loop more and more memory (just a guess and example) might be allocated (by mt4 not your EA) - a return (as this is the mt4-concept) would allow mt4 to reset in a way..
.. how about running a script on the charts for every currency ...
I think a script is not the correct idea for what you want, better try it with an indicator? Could be that the access-options of the symbols are different!
BTW can you see the symbols you want in the MarketWatch (enable all symbols!)
To add comments, please log in or register