- Why did you post your MT4 question in the Root / MT5 General
section instead of the MQL4 section, (bottom of the Root page?)
General rules and best pratices of the Forum. - General - MQL5 programming forum
Next time post in the correct place. The moderators will likely move this thread there soon. - There is no bar closing. Only a new bar opening. What if there are no ticks during a specific candle period? There can be minutes between
ticks during the Asian session, think M1 chart. Larger charts, think weekend, market holiday (country and broker specific.) requires
knowledge of when your broker stops and starts (not necessary the same as the market.)
"Free-of-Holes" Charts - MQL4 Articles
No candle if open = close ? - MQL4 programming forum - The bar should end at bar start + PeriodSeconds. You're asking about 10 seconds less. But if there is no tick,
nothing has changed, why do you care? If you do something, what happens if you get (multiple) ticks after; do you care? There is only one
tick between the last and the start of a new bar; why do you care that you are one tick late?
- If you insist, you are going to have to use a timer and server to local conversion. See attached and:
Indicators: Zero Lag Timer - Indices - Articles, Library comments - MQL5 programming forum
Files:
countdown_timer.mq4
6 kb
William Roeder:
- There is no bar closing. Only a new bar opening. What if there are no ticks during a specific candle period? There can be minutes between
ticks during the Asian session, think M1 chart. Larger charts, think weekend, market holiday (country and broker specific.)
requires knowledge of when your broker stops and starts (not necessary the same as the market.)
"Free-of-Holes" Charts - MQL4 Articles
No candle if open = close ? - MQL4 programming forum - The bar should end at bar start + PeriodSeconds. You're asking about 10 seconds less. But if there is no
tick, nothing has changed, why do you care? If you do something, what happens if you get (multiple) ticks after; do you care? There is
only one tick between the last and the start of a new bar; why do you care that you are one tick late?
- If you insist, you are going to have to use a timer and server to local conversion. See attached and:
Indicators: Zero Lag Timer - Indices - Articles, Library comments - MQL5 programming forum
Can I detect how many seconds have passed from candle open??
thanks
hamit0111: Can I detect how many seconds have passed from candle
open??
When in doubt, think! TimeCurrent() - Time[0]
hamid khateri:
hi
If there are 10 seconds left until the bar closing, I want to do something, like get position...
how can i detect 10 seconds left to 5M bar closing???
i have no idea,I couldn't find codes.
hi
If there are 10 seconds left until the bar closing, I want to do something, like get position...
how can i detect 10 seconds left to 5M bar closing???
i have no idea,I couldn't find codes.
You can do the math to get the close time for the current bar or any previous bar using PeriodSeconds(), however it gives you the standard close time and not the actual close time.
that means, by the given time the bar is closed for certain but the actual closing time could be earlier than that. consider a function like this:
//--- Returns bar close time datetime barCloseTime(ENUM_TIMEFRAMES timeframe, int index) { int period_seconds = PeriodSeconds(timeframe); datetime open_time = iTime(_Symbol, timeframe, index); datetime output = (ulong)open_time + period_seconds - 1; return(output); }
this would give me 10 seconds before the current PERIOD_D1 bar close "standard" time :
Print(barCloseTime(PERIOD_D1, 0) - 10) // returns 2024.02.06 23:59:49
but what if the market gets closed sooner?

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
If there are 10 seconds left until the bar closing, I want to do something, like get position...
how can i detect 10 seconds left to 5M bar closing???
i have no idea,I couldn't find codes.