NullReferenceException using MT's example VA min/max indicator

Questions about MultiCharts .NET and user contributed studies.
User avatar
ernay
Posts: 14
Joined: 08 Jun 2020
Has thanked: 9 times

NullReferenceException using MT's example VA min/max indicator

Postby ernay » 06 Aug 2020

I have an indicator based on Multichart's code at the following link, where you can plot the min/max VA over the course of a session.
https://www.multicharts.com/trading-sof ... me_Profile

It works great most of the time, but about 2-3 times a day, I get this error popup, and the indicator status goes to "off". Once I turn it back "on" everything works fine again until the error happens again. Any idea what might be happening here?

ERROR POPUP
Message: Error in study "my_indicator (@ES#C-1000 Tick)":
System.NullReferenceException: Object reference not set to an instance of an object.
at
PowerLanguage.Indicator.my_indicator.CalcBar()
at PowerLanguage.CStudyAbstract.DoExecute()
at
ManagedStudies.details.CUserStudyImpl.Body(CUserStudyImpl* )
Code example from MultiCharts

Code: Select all

[SameAsSymbol(true)] public class VA_Min_Max : IndicatorObject { public VA_Min_Max(object _ctx):base(_ctx){} private IPlotObject max_VA; private IPlotObject min_VA; protected override void Create() { max_VA = AddPlot(new PlotAttributes("MaxVA", EPlotShapes.Line, Color.Red, Color.Black, 2, 0, true)); min_VA = AddPlot(new PlotAttributes("MinVA", EPlotShapes.Line, Color.Blue, Color.Black, 2, 0, true)); } protected override void StartCalc() { //subscribing for profile changes VolumeProfile.EChanged += VolumeProfileOnEChanged; } protected override void CalcBar() { int bn = Bars.FullSymbolData.Current-1; var vp = VolumeProfile.ItemForBar(bn); if (vp != null) { max_VA.Set((double)vp.HighVAForBar(bn).Dbl ); min_VA.Set((double)vp.LowVAForBar(bn).Dbl ); } } private void VolumeProfileOnEChanged(bool full) { //Recalculate if the profile has been completely changed. if (full) this.ExecControl.Recalculate(); } }

User avatar
ernay
Posts: 14
Joined: 08 Jun 2020
Has thanked: 9 times

Re: NullReferenceException using MT's example VA min/max indicator

Postby ernay » 07 Aug 2020

Note that the issue I'm observing seems to happen around 10:06am CTL every time. So probably a clue there...

darob
Posts: 207
Joined: 20 Nov 2014
Has thanked: 57 times
Been thanked: 32 times

Re: NullReferenceException using MT's example VA min/max indicator

Postby darob » 08 Aug 2020

Hi Ernay, when I was experimenting with that indicator I found forcing frequent recalculations cleared that up. I don't understand the logic, but this seems to work:
Screen Shot 2020-08-08 at 5.16.57 PM.png
(36.22 KiB) Not downloaded yet

User avatar
ernay
Posts: 14
Joined: 08 Jun 2020
Has thanked: 9 times

Re: NullReferenceException using MT's example VA min/max indicator

Postby ernay » 10 Aug 2020

thanks!


Return to “MultiCharts .NET”