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

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 Mongo, Today, 11:05 AM
    0 responses
    1 view
    0 likes
    Last Post Mongo
    by Mongo
     
    Started by Tim-c, Today, 10:58 AM
    0 responses
    1 view
    0 likes
    Last Post Tim-c
    by Tim-c
     
    Started by traderqz, Yesterday, 09:06 AM
    3 responses
    22 views
    0 likes
    Last Post NinjaTrader_ThomasC  
    Started by f.saeidi, Today, 10:19 AM
    1 response
    5 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Started by kujista, Today, 06:23 AM
    5 responses
    18 views
    0 likes
    Last Post kujista
    by kujista
     
    Working...
    X