How to get the volume of each bar drawn?
How to get the volume of each bar drawn?
10 May 2014, 22:57
I am trying to get the last bar volume, open, high, low, and close in the 15m,30m,1h, ect... but so far it has been giving it to me in each tick. Please advise. Thanks.
Replies
Spotware
12 May 2014, 09:37
OnBar event happens when new bar is opened. At that moment MarketSeries collection already contains tick from new bar. It means that last bar is not formed and in general cases open = high = low = close and TickVolume equals 1. If you want to access last formed bar you need take previous one.
You need to change your code:
protected override void OnBar() { var close = MarketSeries.Close.Last(1); var high = MarketSeries.High.Last(1); var low = MarketSeries.Low.Last(1); var tickVolume = MarketSeries.TickVolume.Last(1); ... }
@Spotware
nata2792@gmail.com
08 Jun 2024, 09:46
RE: How to get the volume of each bar drawn?
Spotware said:
OnBar event happens when new bar is opened. At that moment MarketSeries collection already contains tick from new bar. It means that last bar is not formed and in general cases open = high = low = close and TickVolume equals 1. If you want to access last formed bar you need take previous one.
You need to change your code:
protected override void OnBar() { var close = MarketSeries.Close.Last(1); var high = MarketSeries.High.Last(1); var low = MarketSeries.Low.Last(1); var tickVolume = MarketSeries.TickVolume.Last(1); ... }
So accessing the other previous bars' volumes is still not possible right? Only last bar? We still have to create arrays to store each bar volume like usual?
@nata2792@gmail.com
PanagiotisCharalampous
10 Jun 2024, 06:04
RE: RE: How to get the volume of each bar drawn?
nata2792@gmail.com said:
Spotware said:
OnBar event happens when new bar is opened. At that moment MarketSeries collection already contains tick from new bar. It means that last bar is not formed and in general cases open = high = low = close and TickVolume equals 1. If you want to access last formed bar you need take previous one.
You need to change your code:
protected override void OnBar() { var close = MarketSeries.Close.Last(1); var high = MarketSeries.High.Last(1); var low = MarketSeries.Low.Last(1); var tickVolume = MarketSeries.TickVolume.Last(1); ... }
So accessing the other previous bars' volumes is still not possible right? Only last bar? We still have to create arrays to store each bar volume like usual?
Hi there,
So accessing the other previous bars' volumes is still not possible right? Only last bar? We still have to create arrays to store each bar volume like usual?
This is not what the post says. Volume is available for all bars.
Best regards,
@PanagiotisCharalampous
dtniam8
11 May 2014, 00:36
Why does it always return 1 for TickVolume
protected override void OnBar()
{
int index = MarketSeries.Close.Count - 1;
var tickVolume = MarketSeries.TickVolume[index];
Print(tickVolume);
var currentValue = _moneyFlow.Result.LastValue;
Print(currentValue);
}
@dtniam8