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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    87 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    132 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    65 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    118 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    67 views
    0 likes
    Last Post PaulMohn  
    Working...
    X