Help a newbie - What is this error popup trying to tell me?  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
johnromeronc
Posts: 37
Joined: 18 Feb 2011
Has thanked: 10 times
Been thanked: 8 times

Help a newbie - What is this error popup trying to tell me?  [SOLVED]

Postby johnromeronc » 09 Sep 2019

I can read the error popup and it speaks to a null pointer. I started with the Volume Profile code profided by Henry and then enhanced by mirek to read Bid / Ask , and plot on bottom. I then changed it to print out the Bid / Ask and Delta, very similar to mirek. All is good. Runs - no issues. Next I wanted to have a few additional avg plots. So I added the plots, additional series, and instances of functions of avg type to explore.

So -- the code compiles with no errors, And craps out at the end of the first bar. I know this from setting multiple break points. and then once in CalcBar, I step through each line of code stopping to check variable values. I see my code load, go through the Create, StartCalc, and the eventually start CalcBar. The entire set of lines of code does execute, and then at the end on the last curly bracket of CalcBar() is when the error pops up. Any help would be appreciated to understand what this is trying to tell me. Beside Null Pointer.
- what caused it
-
MC-Net - error for help 2019-09-09_8-57-26.jpg
MC-Net - error for help 2019-09-09_8-57-26.jpg (68.85 KiB) Viewed 58 times

This is the indicator with issues JOR_Buy_Sell_Volume

Code: Select all

//=============================
//=============================
//=============================
//=============================

using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;
using PowerLanguage.VolumeProfile;

// ==============================
namespace PowerLanguage.Indicator
{
//================================================
public class JOR_Buy_Sell_Volume : IndicatorObject
{
// =====
//// Define all functions, variable series, variables, plots to be created / used
// =====

// Plots to created
private IPlotObject plot_Ask_Vol;
private IPlotObject plot_Bid_Vol;
private IPlotObject plot_Delta_Total;
private IPlotObject plot_SlowMovDelta;
private IPlotObject plot_FastMovDelta;

// Variable series to be created
private VariableSeries<double> my_Ask_Vol_series;
private VariableSeries<double> my_Bid_Vol_series;
private VariableSeries<double> my_Delta_Vol_series;
private VariableSeries<double> my_Delta_Vol_FastMA_series;
private VariableSeries<double> my_Delta_Vol_SlowMA_series;
private VariableSeries<double> my_Delta_Vol_Smooth_FastMA_series;

// Variables to be created
public Color plusColor = Color.Green;
public Color minusColor = Color.Red;

// Function instances to be used
private Function.T3MA_ my_T3MA_Slow;
private Function.T3MA_ my_T3MA_Fast;
private Function.T3MA_ my_T3MA_Smooth_Fast;
private Function.XAverage my_Xavg_Slow;
private Function.XAverage my_Xavg_Fast;
private Function.XAverage my_Xavg_Smooth_Fast;
private Function.HMA_ my_HMA_Slow;
private Function.HMA_ my_HMA_Fast;
private Function.HMA_ my_HMA_Smooth_Fast;
private Function.AverageFC my_AverageFC_Slow;
private Function.AverageFC my_AverageFC_Fast;
private Function.AverageFC my_AverageFC_Smooth_Fast;



public JOR_Buy_Sell_Volume(object _ctx) : base(_ctx)
{
my_Slow_Avg_Len = 55;
my_Fast_Avg_Len = 7;
my_Fast_Smooth_Len = 4;
use_XMA_ma = true;
use_Hull_ma = false;
use_T3_ma = false;

}
[Input]
public int my_Slow_Avg_Len { get; set; }
[Input]
public int my_Fast_Avg_Len { get; set; }
[Input]
public int my_Fast_Smooth_Len { get; set; }
[Input]
public bool use_XMA_ma { get; set; }
[Input]
public bool use_Hull_ma { get; set; }
[Input]
public bool use_T3_ma { get; set; }




// ==============================================
protected override void Create()
{

plot_Ask_Vol = AddPlot(new PlotAttributes("Ask Vol", EPlotShapes.Line, Color.FromArgb(255, 170, 170), Color.Black, 2, 0, true));
plot_Bid_Vol = AddPlot(new PlotAttributes("Bid Vol", EPlotShapes.Line, Color.FromArgb(132, 255, 132), Color.Black, 2, 0, true));
plot_Delta_Total = AddPlot(new PlotAttributes("DeltaTotal", EPlotShapes.Histogram, Color.FromArgb(255, 255, 0), Color.Black, 5, 0, true));
plot_SlowMovDelta = AddPlot(new PlotAttributes("SlowMovDelta", EPlotShapes.Histogram, Color.FromArgb(255, 128, 0), Color.Black, 4, 0, true));
plot_FastMovDelta = AddPlot(new PlotAttributes("FastMovDelta", EPlotShapes.Histogram, Color.FromArgb(0, 255, 255), Color.Black, 4, 0, true));



// Create Variable Series
my_Ask_Vol_series = new VariableSeries<double>(this);
my_Bid_Vol_series = new VariableSeries<double>(this);
my_Delta_Vol_series = new VariableSeries<double>(this);
my_Delta_Vol_FastMA_series = new VariableSeries<double>(this);
my_Delta_Vol_SlowMA_series = new VariableSeries<double>(this);
my_Delta_Vol_Smooth_FastMA_series = new VariableSeries<double>(this);


// Create Instances of Function objects
my_HMA_Fast = new Function.HMA_(this);
my_HMA_Slow = new Function.HMA_(this);
my_HMA_Smooth_Fast = new Function.HMA_(this);
my_T3MA_Slow = new Function.T3MA_(this);
my_T3MA_Fast = new Function.T3MA_(this);
my_T3MA_Smooth_Fast = new Function.T3MA_(this);
my_Xavg_Slow = new Function.XAverage(this);
my_Xavg_Fast = new Function.XAverage(this);
my_Xavg_Smooth_Fast = new Function.XAverage(this);
my_AverageFC_Slow = new Function.AverageFC(this);
my_AverageFC_Fast = new Function.AverageFC(this);
my_AverageFC_Smooth_Fast = new Function.AverageFC(this);
}
protected override void StartCalc()
{
//subscribing for profile changes
VolumeProfile.EChanged += VolumeProfileOnEChanged;

// initialize all series to 0 (zero) to start
my_Ask_Vol_series.DefaultValue = 0;
my_Bid_Vol_series.DefaultValue = 0;
my_Delta_Vol_series.DefaultValue = 0;
my_Delta_Vol_FastMA_series.DefaultValue = 0;
my_Delta_Vol_SlowMA_series.DefaultValue = 0;
my_Delta_Vol_Smooth_FastMA_series.DefaultValue = 0;

}
protected override void CalcBar()
{
int bn = Bars.FullSymbolData.Current - 1;
var vp = VolumeProfile.ItemForBar(bn);
decimal _deltaTotal = 0;
decimal _Ask_Total_Bar = 0;
decimal _Bid_Total_Bar = 0;
decimal my_Fast_Avg_Value = 0;
decimal my_Slow_Avg_Value = 0;
decimal myFast_Smooth_Value = 0;
Color _bar_color = Color.Green;

foreach (VolumeProfile.ILevel _pcol in vp.Values)
{
_Ask_Total_Bar = _Ask_Total_Bar + _pcol.AskTradedValue;
_Bid_Total_Bar = _Bid_Total_Bar + _pcol.BidTradedValue;
_deltaTotal = _Ask_Total_Bar - _Bid_Total_Bar;
}


my_Ask_Vol_series.Value = (double) _Ask_Total_Bar;
my_Bid_Vol_series.Value = (double) _Bid_Total_Bar;
my_Delta_Vol_series.Value = (double) _deltaTotal;

if (vp != null)
{
if (use_XMA_ma)
{
// set up & execute --> function call values --> long length
// - then execute func and return value
my_Xavg_Fast.Length = my_Fast_Avg_Len;
my_Xavg_Fast.Price = my_Delta_Vol_series;
my_Delta_Vol_FastMA_series.Value = my_Xavg_Fast[0];

// set up function call values --> short length
// - then execute func and return value
my_Xavg_Slow.Length = my_Slow_Avg_Len;
my_Xavg_Slow.Price = my_Delta_Vol_series;
my_Delta_Vol_SlowMA_series.Value = my_Xavg_Slow[0];

// set up function call values --> Smooth of Fast
// - then execute func and return value
my_Xavg_Smooth_Fast.Length = my_Fast_Smooth_Len;
my_Xavg_Smooth_Fast.Price = my_Delta_Vol_series;
my_Delta_Vol_Smooth_FastMA_series.Value = my_Xavg_Smooth_Fast[0];

} // end of if use_Hull_ma



// === > > Here is where I stopped coding - need to do the same for T3 and simple Avg

int jor_Temp = 1;

if (use_T3_ma)
{
jor_Temp = 1;
} // end of if use_T3_ma
if (use_Hull_ma)
{
jor_Temp = 1;
} // end of if use_XMA_ma


plot_Ask_Vol.Set((double)_Ask_Total_Bar);
plot_Bid_Vol.Set((double)_Bid_Total_Bar);
_bar_color = minusColor;
if (_deltaTotal > 0) _bar_color = plusColor;
plot_Delta_Total.Set((double)_deltaTotal, _bar_color);
if (Bars.CurrentBar > (my_Slow_Avg_Len + 5))
{
plot_FastMovDelta.Set(my_Delta_Vol_Smooth_FastMA_series[0]);
plot_SlowMovDelta.Set(my_Delta_Vol_SlowMA_series[0]);
}
}
}
private void VolumeProfileOnEChanged(bool full)
{
//Recalculate if the profile has been completely changed.
if (full)
this.ExecControl.Recalculate();
}
}
}
This is the indicator that works - but does not have setup or logic for also plotting averages.
JOR_Volume_Stats

Code: Select all

//=============================
//=============================
//=============================
//=============================

using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;
using PowerLanguage.VolumeProfile;

namespace PowerLanguage.Indicator
{

public class JOR_Volume_Stats : IndicatorObject
{
public JOR_Volume_Stats(object _ctx) : base(_ctx) { }

private IPlotObject plot_Ask_Vol;
private IPlotObject plot_Bid_Vol;
private IPlotObject Delta_Total;

public Color plusColor = Color.Green;
public Color minusColor = Color.Red;

protected override void Create()
{

plot_Ask_Vol = AddPlot(new PlotAttributes("Ask Vol", EPlotShapes.Line, Color.Red, Color.Black, 1, 0, true));
plot_Bid_Vol = AddPlot(new PlotAttributes("Bid Vol", EPlotShapes.Line, Color.Green, Color.Black, 1, 0, true));
Delta_Total = AddPlot(new PlotAttributes("DeltaTotal", EPlotShapes.Histogram, minusColor, Color.Black, 6, 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);
decimal _deltaTotal = 0;
decimal _maxAsk = 0;
decimal _maxBid = 0;
Color _bar_color;

foreach (VolumeProfile.ILevel _pcol in vp.Values)
{
_maxAsk = _maxAsk + _pcol.AskTradedValue;
_maxBid = _maxBid + _pcol.BidTradedValue;
_deltaTotal = _maxAsk - _maxBid;
}
//decimal max_delta = vp.MaxDelta.TotalValue;
//decimal min_delta = vp.MinDelta.TotalValue;

if (vp != null)
{
plot_Ask_Vol.Set((double)_maxAsk);
plot_Bid_Vol.Set((double)_maxBid);
_bar_color = minusColor;
if (_deltaTotal > 0) _bar_color = plusColor;
Delta_Total.Set((double)_deltaTotal, _bar_color);
}
}
private void VolumeProfileOnEChanged(bool full)
{
//Recalculate if the profile has been completely changed.
if (full)
this.ExecControl.Recalculate();
}
}
}

johnromeronc
Posts: 37
Joined: 18 Feb 2011
Has thanked: 10 times
Been thanked: 8 times

Re: Help a newbie - What is this error popup trying to tell me?

Postby johnromeronc » 10 Sep 2019

Problem solved. I am now able to read the Bid - Ask, sum them up. and plot after some other calculations. My issues came into play from
ass-u-me-ing. Such a bad, bad habit. This stems from my coding to try 4 different methods of averaging. I assumed they were all the same. but no. 2 were Simple and 2 were Series. I also was wrong in thinking I could feed the member "price" a VariableSeries, but it was looking specifically for an iSeries. and my other and final issue, was that I assumed, (there is that word again getting me in trouble), similar members in the 4 functions would be the same - wrong again. some where Price capital P and others were lower case price, same with Length / length. The editor and VS2019 both highlight that issue right away during coding.

So all is well that ends well. All I need now is to figure out how to not have to manually start the indicator after the volume profile loads & calculates completely.

John

darob
Posts: 178
Joined: 20 Nov 2014
Has thanked: 48 times
Been thanked: 24 times

Re: Help a newbie - What is this error popup trying to tell me?

Postby darob » 11 Sep 2019

Hi John I'm no expert but with VP indicators I've found adding recalculate after TimeSpan gets the indicator going without having to toggle it.
Screen Shot 2019-09-11 at 7.27.57 AM.png
Screen Shot 2019-09-11 at 7.27.57 AM.png (20.37 KiB) Viewed 31 times


Return to “MultiCharts .NET”