Announcement

Collapse
No announcement yet.

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 Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            571 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            330 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            101 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            548 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            549 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X