Treat a candle as a time interval with a defined price basis, not just four numbers.
Know what a candle contains
An OHLC candle summarizes an interval using its opening, highest, lowest, and closing prices. MetaTrader’s MqlRates structure stores these alongside the period’s start time, tick volume, spread, and trade volume. Tick volume and trade volume are separate fields; do not relabel one as the other.
For your application, keep the symbol, interval, source, and price basis beside the candle values. A chart of bid prices and a chart of another price basis should be visibly distinguishable. [1]
The latest candle may still be forming
MetaTrader’s CopyRates documentation identifies position zero as the current bar. That distinction matters: the current interval’s latest close can change as new observations arrive. Your UI should distinguish a forming candle from one whose interval has ended.
A useful chart update strategy is to match candles by interval start time. Replace the matching current candle when it changes; append a new candle when a new interval begins. This avoids drawing several candles for the same time slot. Confirm the API’s ordering before choosing the first or last array item. [2]
Validate before drawing
Our suggested validation starts with finite numeric values and a parseable timestamp. For a conventional OHLC record, the high should be at least as large as the open and close, while the low should be no greater than either. Reject or flag records that break these relationships.
For example, an illustrative candle with open 2,648.10, high 2,651.20, low 2,647.80, and close 2,650.40 passes those checks. A high of 2,649.00 would not. Validation catches malformed input; it does not establish that a price is correct.
Handle missing intervals deliberately
Do not turn a missing interval into a zero-price candle. Choose an explicit gap policy and document it. If you carry a previous value forward for a particular visualization, keep that synthetic point distinguishable from an observed bar.
Keep timestamps consistent internally and label the timezone used for display. Test interval boundaries, duplicate records, out-of-order responses, and a refresh during a forming candle. A small fixture covering these cases is often more useful than testing only a long, perfectly ordered history.
References
Primary sources for the technical details in this article. Implementation suggestions are our own.