Bars, Last(0), Last(1) and LastBar Clarification
Bars, Last(0), Last(1) and LastBar Clarification
11 Jul 2021, 10:02
Hi
I'm coming from a Python background and as the title says, was hoping for some clarification.
Lets say I have the following:
protected override void OnStart()
{
// Define TimeFrames for indicators
data1Min = MarketData.GetBars(TimeFrame.Minute);
So this runs when the cBot starts. How many previous bars does this get? When new bars are formed as time moves on, do these bars get added to the data1Min variable or is the data gathers during the OnStart function all the data that will ever be in there? I'm assuming the former.
Now lets say I want to have code such as the following:
protected override void OnTick()
{
// If MA1 is above MA2 and MA2 is below MA3 (trending up)
if (ma1MovingAverage.Result.Last(1) > ma2MovingAverage.Result.Last(1) && ma2MovingAverage.Result.Last(1) > ma3MovingAverage.Result.Last(1))
{
// Enter code here...
}
Can I get confirmation one how the indexing works for the Last(i) property please?
Last(0) = current bar
Last(1) = previous bar
LastBar = Last(1) = previous bar
If Last(0) = current bar, then it will have values for Open, Low and High (Low and High could change until the bar closes) but it won't have a Close value until the bar closes?
PanagiotisCharalampous
13 Jul 2021, 10:19
Hi ctid3999979,
See below the replies to your questions
There is no specific number. It depends at which time the method is called.
Yes
This is correct
No LastBar = Last(0)
Close price for open bars is always equal to the bid price.
Best Regards,
Panagiotis
Join us on Telegram and Facebook
@PanagiotisCharalampous