In OnBarOpen event what does Bars[0] represent?
Created at 06 Dec 2021, 18:24
In OnBarOpen event what does Bars[0] represent?
06 Dec 2021, 18:24
Hello,
I have a few question about Bars.
- Does Bars[0] represent the newest or oldest bar?
- Is Bars[x] which is the most recent bar be an incomplete bar or a complete bar? If Bars[x] is accessed in BarOpened does it just have the latest opening price only or the las complete bar?
S
amusleh
07 Dec 2021, 09:23
Hi,
The Bars[0] will give you the first bar on the chart, if you want to get the latest open bar you have to use Bars[Bars.Count - 1] or Bars.LastBar or Bars.Last(0).
If you want to get the latest closed bar you can use Bars.Last(1) or Bars[Bars.Count - 2].
if you get the last bar it will be not completed or closed yet, so the bar high, low and close prices can change until the bar is finished or closed.
@amusleh