Update values of symbols different from chart

 

Hi all,

 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.

int start()
   {
   while(IsConnected()){
   RefreshRates();

   double eubid=Bid;
   double euask=Ask;
   double euav=(eubid*euask)/2;

   double ejbid=MarketInfo("EURJPY",MODE_BID);
   double ejask=MarketInfo("EURJPY",MODE_ASK);
   double ejav=(ejbid*ejask)/2;

   ObjectCreate("X100",OBJ_LABEL,0,0,0);
   ObjectSetText("X100","EUav: " + DoubleToStr(euav,5),12,"Arial",White);
   ObjectSet("X100",OBJPROP_CORNER,2);
   ObjectSet("X100",OBJPROP_XDISTANCE,10);
   ObjectSet("X100",OBJPROP_YDISTANCE,2);

   ObjectCreate("X101",OBJ_LABEL,0,0,0);
   ObjectSetText("X101","EJav: " + DoubleToStr(ejav,3),12,"Arial",White);
   ObjectSet("X101",OBJPROP_CORNER,2);
   ObjectSet("X101",OBJPROP_XDISTANCE,10);
   ObjectSet("X101",OBJPROP_YDISTANCE,20);

   Sleep(10);
   }

return(0);
}

 

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?

 Thanks 

 

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.

 

Hi gooly,

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?

Hi honest_knave,

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? 

 
clausdp:

Hi gooly,

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?

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..

 

clausdp:

Hi honest_knave,

.. 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!)

Reason: