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