How to get the close price from Bars array

Hi, can someone please clarify the name convention for bars in an array of type Open, Close, High, Low. If bar[0] is the current open bar on the chart, then how can it have a close price, since it’s not closed yet? Or is bar[0] the last closed bar before the current open bar?

Close[0] is the current price

I know it says that in the array definition. But if it’s the current price, how can the bar be closed? Isn’t the current bar an open bar? Sorry if this is obvious to everyone else. Or to put another way, if I want to reference the most recent closed bar, is that Close[1] or Close[0]?

watch out for what type of array you are analyzing - Did you use ArraySetAsSeries() to true? - if so, your bar[0] is your current bar, and so, the close price is the last traded price. You will only have the real bar close price when a new bar is open, obviously, so you canl access bar[1] to have that real closing price…

:wink:

Close[0] == current price of the current filling bar; can change

Close[1] == the close price of the first fully filled bar; does not change

Close[2] == the close price of the second fully filled bar; does not change

Close[3] . . .

Thanks all, that’s cleared it up. So essentially, Close[0] is the current bid price in the open candle, and Close[1] is the close price of the most recent candle. Got it!

You are close, but look here:

I would treat that value as undefined since it has no logical meaning as you well understood before. Since it makes no sense to have a closing value in a bar that is still not closed, just do not use that value at all. Anything may be stored there, and it will be a wrong value whatever it is.