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 sjsj2732, 03-23-2026, 04:31 AM
    0 responses
    42 views
    0 likes
    Last Post sjsj2732  
    Started by NullPointStrategies, 03-13-2026, 05:17 AM
    0 responses
    295 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    290 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    135 views
    1 like
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    98 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Working...
    X