You can do it this way:
bool isNewBar(const string sym, const ENUM_TIMEFRAMES tf, const datetime t) { static datetime actOpn=0,nxtOpn=0; if (t>=nxtOpn) { actOpn = iTime(sym,tf,iBarShift(sym,tf,t)); nxtOpn = actOpn + PeriodSeconds(tf); return(true); } return(false); } .. if ( isNewBar(_Symbol, _Period, TimeCurrent() ) ) { ... }
How does that affect the plotting of a new price bar? i.e. does the terminal plot the bar based on "passing of" the TimeLocal(), or waits for the server's TimeCurrent() to plot the new bar?
I would guess that Terminal uses the price embedded with the tick itself in the MQLTick struct.
struct MqlTick { datetime time; // Time of the last prices update double bid; // Current Bid price double ask; // Current Ask price double last; // Price of the last deal (Last) ulong volume; // Volume for the current Last price long time_msc; // Time of a price last update in milliseconds uint flags; // Tick flags double volume_real; // Volume for the current Last price with greater accuracy };
You can do it this way:
Then the question becomes, where would you call it? in OnTick() or OnTimer()?
Then the question becomes, where would you call it? in OnTick() or OnTimer()?
OnTick().
OnTick() does not fire when no ticks have come in, thus no price changes, thus no bar is formed. Like on a weekend.
OnTick().
OnTick() does not fire when no ticks have come in, thus no price changes, thus no bar is formed. Like on a weekend.
The problem then becomes in a slow day when ticks are not being updated every second "at least", the new bar will be ploted but the isNewBar will not fire till a tick is received, (if bar ploting depends on local time which I guess it does).
No! If no new tick arrives then no new bar is plotted. The a new bar is only plotted when a tick arrives and if more then one bar's worth of time goes by then that bar is skipped.
No! If no new tick arrives then no new bar is plotted. The a new bar is only plotted when a tick arrives and if more then one bar's worth of time goes by then that bar is skipped.
Sorry for the bad explanation; I ment to say;
In a slow day when ticks are not being received passed the time when the current bar timer ends, Will the terminal close the current bar as index 1 or will it still be index 0 till a new tick is received well passed the time for a new bar?
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi
A mql5 code needs to know when a new bar arrives. various methods use "TimeCurrent()" which can remain fixed "not changing" for a long time till a new tick is received by the termnal from the server.
How does that affect the ploting of a new price bar? i.e. does the terminal plot the bar based on "passing of" the TimeLocal(), or waits for the server's TimeCurrent() to plot the new bar?
Thanks