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
VolumeProfile ItemForBar returns allways null
Re: VolumeProfile ItemForBar returns allways null
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
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
Re: VolumeProfile ItemForBar returns allways null
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.
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);