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

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​
    Chris L.NinjaTrader Customer Service

    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:

        Chris L.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by AaronKoRn, Today, 09:49 PM
        0 responses
        1 view
        0 likes
        Last Post AaronKoRn  
        Started by carnitron, Today, 08:42 PM
        0 responses
        6 views
        0 likes
        Last Post carnitron  
        Started by strategist007, Today, 07:51 PM
        0 responses
        8 views
        0 likes
        Last Post strategist007  
        Started by StockTrader88, 03-06-2021, 08:58 AM
        44 responses
        3,975 views
        3 likes
        Last Post jhudas88  
        Started by rbeckmann05, Today, 06:48 PM
        0 responses
        9 views
        0 likes
        Last Post rbeckmann05  
        Working...
        X