NewTick event per period on live trading, possible?

 

Hi,

I'm a programmer new to MQL and to this forum.  Right now I'm trying to trigger the NewTick event for an Expert Advisor attached to a chart on "open prices only" mode --which ticks for every new period for the chosen time-frame (M1, M5, M15, ...)-- so I can make use of the OnTick() function to communicate the OHLC values every -say- hour.


I know this is available when using the Strategy Tester (see Testing Trading Strategies > Ticks Generation Mode; which by the way is poorly documented on the MetaTrader 5 doc, where it says one should set the Model parameter accordingly on the Config/common.ini file, when it actuality it is the TicksMode param on Config/terminal.ini); so I was wondering if it is possible to trigger the NewTick event on every tick/1 minut OHLC/open prices on a live (eg, not testing) EA?

I've been reading throughout the documentation and couldn't figure it out, thanks in advance for any possible remark.

--

Luero 

 
Lucero:

Hi,

I'm a programmer new to MQL and to this forum.  Right now I'm trying to trigger the NewTick event for an Expert Advisor attached to a chart on "open prices only" mode --which ticks for every new period for the chosen time-frame (M1, M5, M15, ...)-- so I can make use of the OnTick() function to communicate the OHLC values every -say- hour.


I know this is available when using the Strategy Tester (see Testing Trading Strategies > Ticks Generation Mode; which by the way is poorly documented on the MetaTrader 5 doc, where it says one should set the Model parameter accordingly on the Config/common.ini file, when it actuality it is the TicksMode param on Config/terminal.ini); so I was wondering if it is possible to trigger the NewTick event on every tick/1 minut OHLC/open prices on a live (eg, not testing) EA?

I've been reading throughout the documentation and couldn't figure it out, thanks in advance for any possible remark.

--

Luero 

Hi Lucero,

Try to use OnTimer() function or check if Current_Time != Time on Bar 0, because basically we can't generate new tick in live.

:D 

 

Hola onewithzachy,

Thanks for you comment.  Look, I've myself found this way around:

long lastbar_date;

void OnTick() {
  if( lastbar_date != SeriesInfoInteger( Symbol(), PERIOD_CURRENT, SERIES_LASTBAR_DATE ) ) {
    // whatever the code you want to execute on every new bar
  }
  lastbar_date = SeriesInfoInteger( Symbol(), PERIOD_CURRENT, SERIES_LASTBAR_DATE ); // "1970.01.01 00:00:00" ????
}

This works pretty well, even if I change the time-frame during the trading, and I can even dismiss the timer.  ... well, it would work well but there seem to be something awkward with the last bar date randomly being set on Jan 1970 for no apparent reason (see SeriesInfoInteger("EURUSD",0,5) randomly returning 1970.01.01 00:00:00. bug?).  Anyway, that can be circumvented by calling the SERIES_BARS_COUNT instead of the SERIES_LASTBAR_DATE, both are of course related but the bar counts seems to be consistent and not being randomly turned back to the 1970 value.

Hope it helps to anyone dealing with something similar. 

 
I currently use this from the codebase for multi-currency EA's but you could modify it to only check the current symbol and your selected period.
Reason: