Announcement

Collapse
No announcement yet.

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 ntbone, Today, 02:30 PM
        0 responses
        3 views
        0 likes
        Last Post ntbone
        by ntbone
         
        Started by tuliomgui, Yesterday, 10:07 PM
        3 responses
        12 views
        0 likes
        Last Post NinjaTrader_ShawnB  
        Started by Learner Trader, Today, 08:36 AM
        1 response
        24 views
        0 likes
        Last Post NinjaTrader_ShawnB  
        Started by GeorgeW, Today, 03:15 AM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_ShawnB  
        Started by timko, Today, 11:55 AM
        4 responses
        10 views
        0 likes
        Last Post NinjaTrader_ShawnB  
        Working...
        X