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

General Functions Library

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

    General Functions Library

    Hi:

    I'm coding several indicators and strategies in NT and I would like to create a library with the functions that are used here and there, so I do not need to maintain duplicated code.

    How Can I create a library with a collection of functions in NT?

    Thanks,

    #2
    Originally posted by pakricard View Post
    Hi:

    I'm coding several indicators and strategies in NT and I would like to create a library with the functions that are used here and there, so I do not need to maintain duplicated code.

    How Can I create a library with a collection of functions in NT?

    Thanks,
    Create partial classes in the Indicator and Strategy namespaces. The easiest way is to copy the UserDefinedFunctions.cs file to another name, and place your function code in there.

    You can segment your library into separate files, so that you only need to export the functions necessary for each indicator/strategy, if you choose to distribute your code.

    Comment


      #3
      Great! Simple and worked!

      BTW, i declared the functions as public, is it correct?

      Comment


        #4
        Originally posted by pakricard View Post
        Great! Simple and worked!

        BTW, i declared the functions as public, is it correct?
        public works, but I generally declare them as protected.

        Comment


          #5
          It did work to re-use functions in several indicators. but, when trying to use the functions in strategies, I get "The name namefunction does not exist in the current context" when compiling. I guess I should tell the strategy to get functions from my UserDefinedIndicator.cs file... Is there any directive to do so?

          Comment


            #6
            Originally posted by pakricard View Post
            It did work to re-use functions in several indicators. but, when trying to use the functions in strategies, I get "The name namefunction does not exist in the current context" when compiling. I guess I should tell the strategy to get functions from my UserDefinedIndicator.cs file... Is there any directive to do so?
            There are separate UserDefinedMethods.cs files for strategies and indicators. You will need to do the same for your libraries. After all, look at how the partial classes are being declared. I said as much in my first response: "Create partial classes in the Indicator and Strategy namespaces." (emphasis added).

            It is possible to use the indicators library files in a strategy, but you will then have to declare a dummy indicator in the strategy, just so that you can call its functions, as functions out of an object. Altogether too cantankerous for my liking.
            Last edited by koganam; 01-14-2013, 12:15 PM.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by chbruno, Today, 04:10 PM
            0 responses
            1 view
            0 likes
            Last Post chbruno
            by chbruno
             
            Started by josh18955, 03-25-2023, 11:16 AM
            6 responses
            436 views
            0 likes
            Last Post Delerium  
            Started by FAQtrader, Today, 03:35 PM
            0 responses
            6 views
            0 likes
            Last Post FAQtrader  
            Started by rocketman7, Today, 09:41 AM
            5 responses
            19 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by frslvr, 04-11-2024, 07:26 AM
            9 responses
            127 views
            1 like
            Last Post caryc123  
            Working...
            X