bool NewBar() { static datetime lastbar = 0; datetime curbar = Time[0]; if(lastbar!=curbar) { if(lastbar==0){ lastbar=curbar; return (false); } lastbar=curbar; return (true); } else { return(false); }
//z
zzuegg:
Thanks for the quick response. Obvious when you see it :)
//z
Stevetrade:
Thanks for the quick response. Obvious when you see it :)
Thanks for the quick response. Obvious when you see it :)
Unfortunately I've just put this onto the system in question and it still triggered a false positive.
still on the firstbar after adding the ea?
or when you are switching period with the EA attached?
zzuegg:
still on the firstbar after adding the ea?
or when you are switching period with the EA attached?
I don't switch periods on these charts.
I just put your new version into my code, installed it and restarted MT4 just after I'd had a trade but while all the requirements were met to open a trade ( other than the fact that it wasn't a new bar ) and it triggered a new trade. Is it because of the restart, does it consider it a new bar?
that code works fine for me. used it in several EA's. are you shure there is no other bug in your EA?
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
Hello!
I have a new bar function that I found on the internet.
Here it is
It works very nicely except that it gives a false positive if I change the EA parameters or install a new version of the EA. I have read somewhere on here somebody suggesting a need to add something to deinit. Ideally I'd like to have something within the function itself if at all possible as I like things tidy but any solution to this problem would be appreciated.
Steve