Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trying to add my own Custom Indicator into an unlocked Strategy Code

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

    Trying to add my own Custom Indicator into an unlocked Strategy Code

    Hi,

    I've created my own custom indicator for drawing levels based on an Opening Range and I'm now looking to use this in a custom strategy. However, I don't know how to add my indicator within the strategy code. Could someone please explain how I can import/add the indicator into the Ninjascript code for the strategy? Or should I just add all of the code for the indicator into the strategy?

    Thank you for the help!

    #2
    Hello, thanks for writing in and welcome in to the NinjaTrader forum. After creating an indicator you can make a variable of the same class name and call its constructor to initalize it. e.g.

    Code:
    //class level
    private MyCustomIndicatorName _MyVar;
    
    //in OnStateChanged, during State.DataLoaded:
    _MyVar = MyCustomIndicatorName(); //if the indicator has inputs, they will be available through the constructor
    
    //in OnBarUpdate:
    Print(_MyVar[0]);  //prints the latest value of the first Plot of the indicator.
    Note that the indicators must add at least one plot and fill the plot with values or add a public Series<T> object for the strategy to read its data. See the examples here:




    Kind regards,
    -ChrisL​

    Comment


      #3
      Can I just add my entire custom indicator code into the strategy code and then reference everything from the indicator within the strategy code like that?
      Last edited by rjm1903; 03-09-2023, 02:08 PM.

      Comment


        #4
        Hi, that would also work should you wish to do this. See here for an extra example:

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        47 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        23 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        33 views
        1 like
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        51 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        42 views
        0 likes
        Last Post CarlTrading  
        Working...
        X