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