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 Brevo, Today, 01:45 AM
          0 responses
          6 views
          0 likes
          Last Post Brevo
          by Brevo
           
          Started by aussugardefender, Today, 01:07 AM
          0 responses
          3 views
          0 likes
          Last Post aussugardefender  
          Started by pvincent, 06-23-2022, 12:53 PM
          14 responses
          242 views
          0 likes
          Last Post Nyman
          by Nyman
           
          Started by TraderG23, 12-08-2023, 07:56 AM
          9 responses
          384 views
          1 like
          Last Post Gavini
          by Gavini
           
          Started by oviejo, Today, 12:28 AM
          0 responses
          6 views
          0 likes
          Last Post oviejo
          by oviejo
           
          Working...
          X