wemersonrv:
Need to know how to detect the exact moment when a candle is closed... and otherwise, also when a new candle starts.
Need this because my strategy works on the closing event of a candle, and open trade on starting next candle!
Use this when checking if the candle has opened before you send your orders:
bool IsNewCandle() { static int BarsOnChart=0; if(Bars==BarsOnChart) return(false); BarsOnChart=Bars; return(true); }
wemersonrv: Need to know how to detect the exact moment when a candle is closed... and otherwise, also when a new candle starts
- The candle closes when the new candle starts. A new candle starts when a tick comes in at or beyond the last candle time+period.
- DeanDeV posted his IsNewCandle() but I recommend that it not be placed into a function. Calling the function a second time, in the same tick, returns false. I just use
start(){ static datetime time0; bool isNewBar = time0 != Time[0]; time0 = Time[0]; if(isNewBar) ...
- If both cases, the above codes do not properly handle, first tick or deinit/init cycles. See https://www.mql5.com/en/forum/146192/page3#825991
WHRoeder:
Ok, understand!
- The candle closes when the new candle starts. A new candle starts when a tick comes in at or beyond the last candle time+period.
- DeanDeV posted his IsNewCandle() but I recommend that it not be placed into a function. Calling the function a second time, in the same tick, returns false. I just use
- If both cases, the above codes do not properly handle, first tick or deinit/init cycles. See https://www.mql5.com/en/forum/146192/page3#825991

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
Hi folks!
I'm start to learn basics to construction an Expert, and it's going well so far. Eevery day some options become clearer and easy to understand, but others, not so much.
Need to know how to detect the exact moment when a candle is closed... and otherwise, also when a new candle starts.
Need this because my strategy works on the closing event of a candle, and open trade on starting next candle!
I do a previous search here on the forum and found a lot of information, but not cleared or inserted on much code... and don't understand !
.