Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 wzgy0920, 02-22-2024, 01:11 AM
    5 responses
    32 views
    0 likes
    Last Post wzgy0920  
    Started by wzgy0920, Yesterday, 09:53 PM
    2 responses
    49 views
    0 likes
    Last Post wzgy0920  
    Started by Kensonprib, 04-28-2021, 10:11 AM
    5 responses
    191 views
    0 likes
    Last Post Hasadafa  
    Started by GussJ, 03-04-2020, 03:11 PM
    11 responses
    3,230 views
    0 likes
    Last Post xiinteractive  
    Started by andrewtrades, Today, 04:57 PM
    1 response
    14 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Working...
    X