• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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.
    https://ninjatrader.com/support/foru...040#post786040
    Attached Files
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NinjaCustomer, Today, 01:48 AM
    0 responses
    2 views
    0 likes
    Last Post NinjaCustomer  
    Started by aligator, Yesterday, 10:11 PM
    0 responses
    2 views
    0 likes
    Last Post aligator  
    Started by psquare, Yesterday, 03:11 PM
    4 responses
    20 views
    0 likes
    Last Post psquare
    by psquare
     
    Started by ballboy11, Yesterday, 03:20 PM
    1 response
    12 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by tonynt, Yesterday, 02:18 PM
    1 response
    11 views
    0 likes
    Last Post NinjaTrader_JoshG  
    Working...
    X