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

Is a function calculated each time when it is called?

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

    Is a function calculated each time when it is called?

    Just a general question:

    If I have defined a certain function that I call many times in my strategy, will it be calculated every time that I call it or just once per OnbarUpdate, i.e. NT keeps the result once calculated?

    Or should I for maximum efficiency assign it to a variable and then use that variable so that the function is called only once?

    Of course the last thing is easy to do, but maybe there is no efficiency gain doing this anyway...

    #2
    Functions are are calculated only when you call them.
    RayNinjaTrader Customer Service

    Comment


      #3
      Yes I understand that.
      But my question is if they will be calculated for example 20 times if I call them 20 times within the same OnBarUpdate.

      Will NT 'remember' the result, or should I assign a variable such that the function only has to be calculated once?

      Comment


        #4
        Yes, it would process 20 times. The function code is your code, if you call it, it will execute. Assigning the function to a local variable will be more efficient than calling it 20 times.
        RayNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by chbruno, Today, 04:10 PM
        0 responses
        3 views
        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