I'v tried to create a custom class "Top_Bottom" for my indicator. The code compiles. But when I add the indicator to a chart i get the error message "Object reference not set to an instance of an object."
I'v identified the line in the code below that causes the error. But I'm not sure how to adjust the code. Is it sufficient to add the variables (double v, double l, int b) like I'v done in the class or do I have to add them to the Variabels region and Properties region too?
#region Using declarations using System.Collections.Generic; #endregion { #region Variables private double x; private double y; private List< Top_Bottom > DTlist; #endregion protected override void Initialize() { List< Top_Bottom > DTlist = new List< Top_Bottom >(); } protected override void OnBarUpdate() { // This line causes the error. Add DT to dynamic list [B][COLOR=Red] DTlist.Add(new Top_Bottom(x, y, CurrentBar)); [/COLOR][/B] } // My Custom Class public class Top_Bottom { // Constructor public Top_Bottom(double v, double l, int b) { this.Value = v; this.Line = l; this.BarNo = b; } public double Value { get; set; } public double Line { get; set; } public int BarNo { get; set; } }
Comment