How can the close of a candle be different from the open of next one?

I’m developing an automatatic candlestick patterns recognition system and I see in many patterns the close quote of one candlestick is different from the open of the next one. I can’t understand why.
Doesn’t a candlestick open when another one closes?

Or they just hang around for a while before deciding when to open? :slight_smile:

Candles charts are based on transactions within a given time frame. The price someone bought or sold for (in MT4 it’s bought only) most recently makes the candle grow or shrink.

If the next transaction after the candle closes is a higher price than the candle closed at, you have a gap up. And vice versa for gap down.

There are two basic types of ways this can happen:

  1. Price changes quickly between candle open/close which is usually only 1 or 2 pips max

  2. You are looking at a gap from the weekend

It is because the ticks that create the close price and open prices are not generated by the clock, they are generated by a change in price.
These changes in price occur at random intervals depending on the volatility of the market.
The close price is created by the last tick to arrive before the end of the candles time period, this may be several seconds before the end of the candles time period.
The next candles open price is generated by the first tick to arrive after the beginning of its time period, this tick will reflect a change in price since the tick that generated the close price of the last candle, this first tick of the new candle may be several seconds after the beginning of the candles time period.
It should not be possible for a candles close price to be equal to the next candles open price because that would mean a tick was generated without a change in price, the only time this should occur is if there is no change in price during the whole period of the candle so to prevent gaps in the chart a tick is generated to create a 1 tick, flat candle.
This is not a common occurance but you will sometimes see them on the one minute chart during periods of low trading activity.

Thank you very much. Your explications were right to the point.