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
The easiest way:
static datetime tlastbar=0;
datetime tnewbar=iTime(NULL,PERIOD_CURRENT,0);
bool isnewbar=tnewbar!=tlastbar;
tlastbar=tnewbar;
Here is my final version.
In fact I'm a bit worried becuase it is so easy.
Alain: It would be nice if you would issue the blessing.
// -----------------------------------------------------------------------
if(MathMod(TimeCurrent(),PeriodSeconds()) < currPeriodProgress) iNewBar = true;bool NewBar(void)
{
bool iNewBar = false;
static double currPeriodProgress = 0;
currPeriodProgress = MathMod(TimeCurrent(),PeriodSeconds());
return(iNewBar);
}
// ------------------------------------------------------------------------
void OnTick()
{
if(NewBar()) PlaySound("tick.wav");
Greetings from Cologne
Willbur
The problem is it can only be used from OnTick(). From other event handlers you are never sure if TimeCurrent() is related to the symbol you want.
And I suggest you to never do the same calculation twice :
As far as I know the topic is for mql5. Your code is mql4 only.
I used these in MQL4
What do you mean by that? Its just a snipped and can be included whereever one wants, eg within his NewBar() function. And imo its the simplest and quickest, reliable solution. I included this in a derivate of CSymbolInfo class for all timeframes separately and it works perfect.
There is no iTime() function in mql5.
MT5, really? But MQL5 is not only MT5, that is at least that how I understood it always, cause MT4 uses the MQL5 compiler. But in fact did not know that, I use mainly MT4. Anyway, thanks for the info about the restriction.
MQL4 iTime() it's easy and understandable for traders as is with most of MQL4 other Functions.
MQL5 is different, you need a degree in computer science to code that, and that is what puts most people down.
Heres an example i encountered last week, when i wanted to start and convert my MT4 EA's to MT5 and the solution i found.
No, mql4 is for MT4, mql5 is for MT5. They have a subset of functions in common, but that's 2 different languages.
The language is the same but they have a small subset of functions not in common ;) Anyway, youre probably right with this definition. MQ did a lot to generate confusion at this point.
MT5, really? But MQL5 is not only MT5, that is at least that how I understood it always, cause MT4 uses the MQL5 compiler. But in fact did not know that, I use mainly MT4. Anyway, thanks for the info about the restriction.