VolumeProfile ItemForBar returns allways null

Questions about MultiCharts .NET and user contributed studies.
radekj
Posts: 113
Joined: 28 Apr 2008
Has thanked: 20 times
Been thanked: 1 time

VolumeProfile ItemForBar returns allways null

Postby radekj » 19 Jun 2019

int bn = Bars.FullSymbolData.Current-1;
var vp = VolumeProfile.ItemForBar(bn);

ItemForBar returns allways null
for any instrument

(Volume footprint is visible on chart, so the data is populated)

MC.Net x64 Version: 12.0.18187
Win10 x64
IqFeed

et1hugo
Posts: 9
Joined: 25 Oct 2017
Has thanked: 5 times
Been thanked: 1 time

Re: VolumeProfile ItemForBar returns allways null

Postby et1hugo » 19 Jun 2019

Hi radekj

To get the volume profile collection for the current bar you should pass in the IInstrument CurrentBar (not the CurrentBar - 1). I used the following code to access the volume profiles for two data streams on a short and long term chart , I include only the code for the short term chart and the "..." represent other irrelevant lines of code:

private IInstrument _ShortTermBars; //short term chart instrument
private IProfilesCollection _ShortTermVolumeProfiles; //declare the shrort term collection to access ALL the profiles on the chart
....
_ShortTermBars = BarsOfData(1); //get the first data stream, this should point the same IInstrument as Bars
_ShortTermVolumeProfiles = VolumeProfileByDataStream(1); // get the profiles collection using the data stream
....
IProfile shortTermVolumeProfile = _ShortTermVolumeProfiles.ItemForBar(_ShortTermBars.CurrentBar);
....
Price shortTermPOCPrice = shortTermVolumeProfile.POCForBar(_ShortTermBars.CurrentBar);
if (shortTermVolumeProfile != null && !shortTermVolumeProfile.Empty) {
Price shortTermPOCPrice = shortTermVolumeProfile.POCForBar(_ShortTermBars.CurrentBar);

if (shortTermPOCPrice != null) {
_ShortTermPOC = shortTermPOCPrice.Dbl;
// do what you need to do with the POC price
}
}

This might be obvious but make sure you have the volume profile enabled on the chart.

Good luck

Emmanuel
Posts: 355
Joined: 21 May 2009
Has thanked: 109 times
Been thanked: 28 times

Re: VolumeProfile ItemForBar returns allways null

Postby Emmanuel » 15 Feb 2020

Thank you very much et1hugo !

you must use _ShortTermBars.FullSymbolData.Current - 1 to have a correct bar number

Otherwise your vp.Close won't match Bar.Close[0].

https://www.multicharts.com/trading-sof ... me_Profile

-1 is necessary, I checked it.

Code: Select all

IProfile shortTermVolumeProfile = _ShortTermVolumeProfiles.ItemForBar(_ShortTermBars.FullSymbolData.Current - 1);


Return to “MultiCharts .NET”