How to get the volume of each bar drawn?

Created at 10 May 2014, 22:57
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!
DT

dtniam8

Joined 10.05.2014

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.


@dtniam8
Replies

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

dtniam8
11 May 2014, 00:37

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);

        }


@dtniam8

dtniam8
11 May 2014, 00:38

Why does it always return 1 for TickVolume. I'm trying to get the volume of the last bar. Please help.

        protected override void OnBar()
        {
            int index = MarketSeries.Close.Count - 1;
            var tickVolume = MarketSeries.TickVolume[index];
            Print(tickVolume);

        }


@dtniam8

dtniam8
11 May 2014, 00:39

Sorry about the double posts. My browser stuck.
 


@dtniam8

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