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 NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        62 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        134 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        75 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        45 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        50 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X