Announcement

Collapse
No announcement yet.

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.
      <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

      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 CarlTrading, 03-31-2026, 09:41 PM
          1 response
          43 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by CarlTrading, 04-01-2026, 02:41 AM
          0 responses
          21 views
          0 likes
          Last Post CarlTrading  
          Started by CaptainJack, 03-31-2026, 11:44 PM
          0 responses
          30 views
          1 like
          Last Post CaptainJack  
          Started by CarlTrading, 03-30-2026, 11:51 AM
          0 responses
          50 views
          0 likes
          Last Post CarlTrading  
          Started by CarlTrading, 03-30-2026, 11:48 AM
          0 responses
          41 views
          0 likes
          Last Post CarlTrading  
          Working...
          X