Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Accessing object of another class in c# Ninjatrader

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

    Accessing object of another class in c# Ninjatrader

    I have a question regarding class object in C# in Ninjatrader. To begin with, I am trying to build the class that will managed the MACD indicator and method that will return true value if certain conditions are met. Now, I declare my class inside the strategy class(at the bottom):
    Code:
     private class MACD_test: MACD{          public MACD_test(){          }         public int down(){             Print(MACD(14, 28, 10).Diff[0]);             Print(MACD(14, 28, 10)[0]);             return 0;         }      }
    It is just a simplifid example, but my problem is the line:
    Code:
     Print(MACD(14, 28, 10).Diff[0])
    where I refer to macd method Diff. I am getting an error: Object Reference not set to an instance of an object mybkexperience

    Wierd thing is that I can refer to Macd value in the line below without an error:
    Code:
     Print(MACD(14, 28, 10)[0]);
    Now, I thought that this is some kind of inheritance issue but after researching the topic for a while I didn't find any working answer. I udnerstand that MACD is also a class, but as far as I know it doesn't need cosntructor. I am not very fluent in C# so I would appreciate your help on how to access: MACD(14, 28, 10).Diff

    Thanks.
    Last edited by Timothy951; 01-24-2019, 04:17 AM.

    #2
    Hello Timothy951,

    While you are free to create scripts that have custom C# code, I do need to mention that inheriting from NinjaTrader classes is not supported by NinjaTrader Support.

    It appears that you are attempting to call an indicator from a class constructor before the script has reached State.DataLoaded.

    Attached is an example of how to call and print the value of the MACD() in OnBarUpdate after the script has reached State.DataLoaded.

    Also, below is a link to a forum post with helpful information about getting started with NinjaScript.

    Attached Files
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    116 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    61 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    40 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    43 views
    0 likes
    Last Post TheRealMorford  
    Started by Mindset, 02-28-2026, 06:16 AM
    0 responses
    82 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X