(not looked at code but ...)
The trick I use to only calc on FINAL Close values ...
.. is to work then out on Open of NEXT bar - only 1 tick late ;-)
I do something like this for any code that should only operate on closed bars:datetime Now = 0; int start() { if( Now != Time( 0 )) { Now = Time( 0 ); ...query indicators here, at bar 1 instead of 0 } }
I think that it should be
static datetime Now = 0;
Why the use of static, if I may ask?
In my own code I declare the variable as a global, and initialize it to 0 in the init() function.
I apologise - I should have looked more closely!
Yes, your global declaration is correct.
If declared *inside* start() then static is needed - and your way doesn't
Brewmanz, thanks for keeping me on my toes. I've only studied MQL4 for a few weeks now, and it has been 15 years since my last computer science class. Not hard to get me to question myself!
P.S. Is brewmanz kind of like humanzee? Are you claiming to be some hybrid of man and beer? ;)
Hi There, i am having the same issue with an inside bar indicator - i get a notification every hour.
any help would be much appreciated.

- 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 Guys
I'm having a slight problem with getting the backtester and even live trading to get an indicator calculated only after a bar is closed. Say we're looking at an MA or MACD cross system, like the EA's provided with metatrader, with each tick of a bar, the MACD or MA could go from crossing or equaling each other and not, but all i really want to know is what the values are when the bar is closed, ie, the final value, the one which is printed on the chart. I've managed to find a NewBar() function that works out if it's the first tick of a bar but not 100% sure how it works, so i can't modify it only do something on the last tick or close of bar. Does anyone know how to edit this function or of another way to ensure that i'm only calculating indicators when they've been finalised??
The code attached is the MACD sample, just with the NewBar() function added, so it will only make 1 trade if the condition is met till the MACD crosses the opposite way, but also takes the value calculated on the first tick of the bar, which is the problem i'm speaking of. Unfortunately it's in a text file as MetaTrader won't put the mq4 or ex4 files in the correct directory.
Any help would be greatly appreciated,
Anthony