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

External classes and functions

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

    External classes and functions

    Hi,

    I have a custom made class and several functions which I need for more than one indicator.

    Can I save the class and the functions on an external .cs file and code the indicators to read the class and the functions from that file?

    And if not, what is the best way to store the class and the functions inside NT and have the indicator access them? I really want to avoid unnecessary Update() calls etc. I just want the indicators to read the lines.

    #2
    Hello savekad,

    Custom classes and referencing external files is possible, but not something that we could support.

    The best way you can define your own functions inside of NinjaTrader by using the UserDefinedMethods.cs to be able to access those functions inside of any NinjaScript file. For a few samples on how to use the UserDefinedMethods see the following link to our Help Guide.

    http://www.ninjatrader.com/support/h...ed_methods.htm

    Let us know if we can be of further assistance.
    JCNinjaTrader Customer Service

    Comment


      #3
      Sounds good but can I also store classes in the UserDefinedMethod section?

      And does it matter if I use the one in Indicators or the one in Strategies?

      Comment


        #4
        Hello savekad,
        Yes, you can add custom classes in the UserDefinedMethods too. NinjaScript is essentially C# and will follow all the rules of C# coding.

        Code:
        namespace NinjaTrader.Indicator
        {
            /// <summary>
            /// This file holds all user defined indicator methods.
            /// </summary>
            partial class Indicator
            {
            }
        	
        
           public class MyCustomClass
           {
             //implementation here
           }
        	
        }
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          And does it matter if I use the one in Indicators or the one in Strategies?

          Comment


            #6
            Hello savekad,

            Indicators and Strategies have there own UserDefinedMethod so you would have to create your custom methods in the one(s) that you would like to use them in. For example if you want to create methods for a strategy you would go to Tools -> Edit NinjaScript -> Strategies -> UserDefinedMethods. You will know if it is a strategy or indicator by the namespace and partial class that it is referencing.
            JCNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by gentlebenthebear, Today, 01:30 AM
            2 responses
            13 views
            0 likes
            Last Post gentlebenthebear  
            Started by Kaledus, Today, 01:29 PM
            2 responses
            8 views
            0 likes
            Last Post Kaledus
            by Kaledus
             
            Started by frankthearm, Yesterday, 09:08 AM
            13 responses
            45 views
            0 likes
            Last Post frankthearm  
            Started by PaulMohn, Today, 12:36 PM
            2 responses
            16 views
            0 likes
            Last Post PaulMohn  
            Started by Conceptzx, 10-11-2022, 06:38 AM
            2 responses
            56 views
            0 likes
            Last Post PhillT
            by PhillT
             
            Working...
            X