I wrote the following sophisticated function to check for bar close:
int init() { // if you don't want to execute on the first tick IsBarClosed(-1,false); } int start() { // check if bar is closed if(!IsBarClosed(0,true)) // true/false here allows to keep old bar for check again later in the code and reset return(0); } //+------------------------------------------------------------------+ //| check if new bar has formed //+------------------------------------------------------------------+ bool IsBarClosed(int timeframe,bool reset) { static datetime lastbartime; if(timeframe==-1) { if(reset) lastbartime=0; else lastbartime=iTime(NULL,timeframe,0); return(true); } if(iTime(NULL,timeframe,0)==lastbartime) // wait for new bar return(false); if(reset) lastbartime=iTime(NULL,timeframe,0); return(true); }
Thanks.
Thank aswell.. you rock! :)
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
Thanks in advance,
Ed