You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Sorry for the necro but a slightly better solution for MT4 was not yet posted... iTime()
Can be used to count new bars in OnTick() and or OnTimer() of multi symbol and or multi time-frame EA. For example:
(**as is, on the first call it will report a large number but will be accurate after that)
{
datetime cbartime=iTime(cursym,curtf,0);
if(cbartime!=nbartime[oslc,otlc])
{
datetime bardiftime=cbartime-nbartime[oslc,otlc];
ulong bardif=bardiftime/(curtf*60);
nbartime[oslc,otlc]=cbartime;
if(curtf==PERIOD_D1 && DayOfWeek()==0 && bardif>=1) bardif--; //Do not count Sunday bars on a daily chart
//Print(bardif," new bars found.");
return (short)bardif;
}
return 0;
I don't like that at all.
1) Over complicated for the specification
2) Bar count returned includes imaginary bars that are not on the chart. e.g. Saturday bars or out of hours bars on lower timeframes when market is closed
3) curtf*60 is not a good way to get the seconds in a period, use PeriodSeconds()
W
> How we know when a new bar is formed
When the current bar gives its first tick
You can detect this with
...
...
Good Luck
-BB-
Thank you.