Why the difference between Bars[Bars.Count -1].Low and Bars.LowPrices.Last(1)

Created at 13 Feb 2023, 13:28
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
DR

drewisdad

Joined 27.04.2022

Why the difference between Bars[Bars.Count -1].Low and Bars.LowPrices.Last(1)
13 Feb 2023, 13:28


Hi all,

Could someone please explain why Bars[Bars.Count - 1].High references the currently forming bar?  ie:- it's the same as Bars.HighPrices.Last(0).

I was expecting [Bars.Count -1] to be the same as Last(1), But I need to make it [Bars.Count - 2] to retrieve the same info as Last(1).

 

Just to be clear...

Bars[Bars.Count - 1].Low == Bars.LowPrices.Last(0)

Bars[Bars.Count - 2].Low == Bars.LowPrices.Last(1)

Bars[Bars.Count].Low == 'Specified argument was out of the range of valid values. (Parameter 'index')'

 

I know this is prolly by design... just looking to understand 'why is it so' :)


@drewisdad
Replies

PanagiotisChar
13 Feb 2023, 15:18

Hi there,

Counting C# starts from 0. So Bars[0] is the first bar and Bars[Bars.Count - 1] is the last bar.

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 


@PanagiotisChar

drewisdad
13 Feb 2023, 16:34

RE:

PanagiotisChar said:

Hi there,

Counting C# starts from 0. So Bars[0] is the first bar and Bars[Bars.Count - 1] is the last bar.

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 

Ahhh gotcha :)  Thank you kindly :) So Bars.Count will always be 1 bar in the future that we'll never get to see. 

I'm heading off to re-factor all my bots now... Maybe I Do have something that could work after all LOL :)

Thanks again for clarifying :)


@drewisdad