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

Best practices on writing functions in NinjaScript

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

    Best practices on writing functions in NinjaScript

    Hi, I've been using TradeStation for quite a while and I liked the straight forward approach the language offered to create functions (that could be used as input for e.g. indicators).

    I've switched to NT8 some weeks ago and I struggle a bit to figure out what the best practice are in Ninja for writing functions that I could reuse generally in my various scripts (e.g. for calculations within indicators, strategies etc.)

    Such a function could be as simple as:
    public int myFunction(int a, int b)
    {
    return <do some math>
    }

    Some thoughts/questions:
    - Where is the best place to store such functions?
    - Would it make sense to put them in a separate namespace?
    - When writing a new function, would you normally start with an indicator, defining the arguments, and omit the plotting options?

    Thank you for hints and/or resources on this.
    P

    #2
    two cents from me - you might create a file under "AddOns" folder, like "MyLibrary.cs", then there define Namespace (or class, as you wish), named i.e.
    Code:
    namespace MyLibrary {   
        public static int myFunction(){} 
     }
    and create bunch of static methods there. Will make your development easier.

    Comment


      #3
      Hello Stett0002,

      Thanks for your post.

      As ttodua stated, you could create static methods in a NinjaScript AddOn which could be referenced in other scripts.

      See the MySharedMethodsAddOnExample script in this forum thread for an example of creating static methods: https://ninjatrader.com/support/foru...est#post733956

      Let us know if we may assist further.
      Brandon H.NinjaTrader Customer Service

      Comment


        #4
        Very helpful, this is exactly what I was looking for, thanks to both!

        Comment


          #5
          thanks a lot!!!!!!!!!!!!!!!!!!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by ender_wiggum, Today, 09:50 AM
          1 response
          5 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by rajendrasubedi2023, Today, 09:50 AM
          1 response
          10 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Started by geotrades1, Today, 10:02 AM
          0 responses
          4 views
          0 likes
          Last Post geotrades1  
          Started by bmartz, Today, 09:30 AM
          1 response
          8 views
          0 likes
          Last Post NinjaTrader_Erick  
          Started by geddyisodin, Today, 05:20 AM
          3 responses
          24 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Working...
          X