Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to create a Custom Class?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to create a Custom Class?

    Hi!
    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?

    Code:
    #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; }
            }
    /Best regards

    #2
    Hi poseidon_sthlm,

    Creating a custom array list is, unfortunately, something I cannot provide support for.

    However, as a hint, you will need to ensure the array or any object within is not empty, when you try to access/call it.
    TimNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    579 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    334 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    554 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    551 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X