Can I get ticks from multiple pairs in one EA/chart?

 

I have an EA with a routine that runs OnTick(). It monitors the current chart's pair.

But I want the same EA to check other pairs too.

The problem is, the routine only runs OnTick() by the current chart's ticks. It can't see ticks in other pairs.

Or can it? Is there some way to capture ticks from other pairs?

Let's say I want to monitor 20 pairs by the tick but not have 20 charts opened. Is that possible?

 
whoowl:I have an EA with a routine that runs OnTick(). It monitors the current chart's pair. But I want the same EA to check other pairs too. The problem is, the routine only runs OnTick() by the current chart's ticks. It can't see ticks in other pairs. Or can it? Is there some way to capture ticks from other pairs? Let's say I want to monitor 20 pairs by the tick but not have 20 charts opened. Is that possible?

To read other symbol's tick on a regular basis, you will have to use OnTimer in conjunction with OnTick.

EDIT: Also read the following ... https://www.mql5.com/en/forum/439507#comment_44282223

 
 

William, of all people, do I need to tell YOU that this is the MT4 section? :-)

But thank you for the link, it's an interesting read.


Fernando, you also offer an interesting read, but it also seems to be related to MT5. Is that right? CopyTicks isn't available in MT4.

 
whoowl #: William, of all people, do I need to tell YOU that this is the MT4 section? :-) But thank you for the link, it's an interesting read. Fernando, you also offer an interesting read, but it also seems to be related to MT5. Is that right? CopyTicks isn't available in MT4.

Both my post and William's are valid for MQL4+ too regarding the article. It may be a MQL5 Article but the technique is valid for MQL4+ too.

Regarding CopyTicks, yes you are correct and that was an oversight on my end. Please disregard that part, but the rest about OnTick and OnTimer is still valid for MQL4+ too, but it will miss ticks.

However, the method using custom chart events in the article is still applicable to MT4 and will miss less ticks than the OnTimer method.

Irrespective of the method used, please note that on MT4, unless your code is very efficient, you will miss ticks.

 


About the "EA to checking other pairs".  The OnTick() function gets called for ticks from the chart that the EA is placed on, and not for ticks from other charts or symbols.

Regardless of timers.. incoming ticks from your brokers various different symbols often don't arrive on the same tick.

So you need to check and match the bar-time for different symbols and wait until they do match up to prevent mismatching or read errors.
 
int wait=0; //global

// example:
  string testSymbol="USDCAD";
  if (iTime(_Symbol,_Period,0) != iTime(testSymbol,_Period,0)) { wait++; return(0); } //wait for data syncronization on new bar
  else { if (wait>0) { Print("Waited ",wait," ticks"); wait=0; } } // Chart symbols can take a few ticks to syncronize