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 cmtjoancolmenero, 04-29-2024, 03:40 PM
        5 responses
        25 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by Torontobluejays, Yesterday, 08:43 AM
        3 responses
        18 views
        0 likes
        Last Post NinjaTrader_Zachary  
        Started by akuntysh, 05-18-2018, 03:39 AM
        10 responses
        809 views
        0 likes
        Last Post cedavra
        by cedavra
         
        Started by Belfortbucks, 04-29-2024, 05:32 PM
        1 response
        15 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by Creamers, 04-27-2024, 05:32 AM
        5 responses
        37 views
        0 likes
        Last Post Creamers  
        Working...
        X