On trading view, I get the idea that if closing price is less than the opening price, then we will get a red candlestick on the price chart, and if closing price is greater than opening price, then we will get a green candlestick. But what determines the color of volume bar that is at the bottom of the chart. Does volume bar always gets the color of the candlestick or can there be a mismatch between the two?
The volume bar color is based on whether the price was higher (green) or lower (red) at the end of the period than it was at the beginning of the period. In other words, there should never be a mismatch between the candlestick color and the volume bar color because they are based on the same thing.
Remember that the "price" is what was paid on a trade, and a trade always executes within exactly one period, however, most candlesticks show up immediately after the close of the previous candlestick, even if no trades have happened, and the price is simply based on the bid/ask spread, which represents the difference between the highest price that buyers are willing to pay and the lowest price that sellers are willing to accept at the beginning of the period.
Of course, a specific graph software may deviate from these norms.