Build notes
MT5 Phantom Weekend Candles: Building Bars From a Feed That Never Goes Quiet
Batdorj Byambadorj · · 4 min read
MetaTrader 5's own chart shows nothing between Friday's close and Sunday's open. The first chart I built from an MT5 price feed showed plenty: a row of flat little bars marching across the weekend, on a market that was shut.
The feed was a small bridge inside the terminal that sent each price to my server. An aggregator there built the candles for nine timeframes, M1 to MN. That worked, until the market closed.
What a phantom candle looks like
When the market closes, MT5 does not go silent. It keeps repeating the last price. My aggregator did what it was told: a price arrived in a new minute, so a new minute bar was opened.
The result has a signature. Open, high, low and close are all the same number, and the tick volume is 1. One of those is nothing. Two days of them on every symbol is a chart with a weekend drawn into it. A forex chart is not supposed to have one, and a line drawn across that gap depends on it not being there.
Fix one: a clock per symbol
The aggregator now remembers, for each symbol, when its price last actually changed. If the price has not moved for more than 120 seconds, an incoming price is not allowed to open a new bar.
The rule cares about change, not arrival. A repeated price is not news, however punctually it arrives.
I checked it the only way that proves anything, by leaving it running over a weekend. No bars appeared.
Fix two: let the source win
History is a separate path. A script pulls finished bars from MT5 itself and writes them into the same store the aggregator uses. So for any stretch of time there can be two versions of the truth: what my aggregator built from the stream, and what the platform says happened.
The rule I settled on: inside the range the platform's history covers, the platform is right. A locally built bar with no counterpart in MT5's own data is dropped.
That is what removed the phantoms that were already stored. It also means a mistake in my aggregator can be corrected by the next history pull.
The candle that looks fake and is not
It is tempting to go one step further and treat every flat bar with volume 1 as fake. Natural gas showed why that would be wrong.
On a thinly traded symbol, a minute with one or two ticks at a single price is ordinary. The bar has identical open, high, low and close, a volume of 1 or 2, and it is completely real. The price ticked, once.
So the signature alone identifies nothing. A flat bar with volume 1 is a phantom when the market is closed, and a quiet minute when it is open. The 120 second rule gets this right because it never looks at the bar's shape. It only asks whether the price moved.
A cousin: the dash after a restart
One more flat bar turned up, from a different cause. When the aggregator restarted, it restored the bar in progress and wrote it out again under the same timestamp. The chart showed a candle reduced to a dash: identical prices, volume 2.
The fix went into the step that closes a bar. If a bar with that timestamp already exists, the two are merged, not stored side by side.
What the filter costs
Suppressing dead bars has a price, and I found it later from the other side.
In a truly quiet minute on a currency pair, no M1 bar is created at all. My alert engine at the time counted trading minutes by formula, without looking at the stored bars. So it counted that minute, and the chart skipped it. A trendline on an M1 to M15 chart could sit a small step away from the engine's value, about 0.1 to 0.5 pips. On H1 and above the step did not exist, and gold was clean on every timeframe.
The exact answer is to count real bars, not minutes. That would tie the engine to stored data and to its depth, so I wrote the gap down and left it.
That system is switched off now, for reasons unrelated to candles. The rules are the part worth keeping.
If you build candles from a price stream
- Open a new bar only when the price has changed recently. Arrival of a message is not enough.
- Give the platform's own history the last word, and drop local bars it does not have.
- Do not judge a bar by its shape. Flat with volume 1 can be a real, quiet minute.
- Merge on timestamp when a bar is written twice.
- Know what your filter removes. Anything that counts minutes by formula will disagree with a chart that skips some.
Batdorj Byambadorj
Batdorj Byambadorj has been trading forex for his own account since 2007, mostly gold. He is the sole developer of fx-alert and writes every article on this site himself.