Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Performance query

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

    Performance query

    Hi,

    I've a few indicators that use other functions (or indicators), in the following manner

    for example

    temp = SMA(Volumes[0], 50)[0];

    This might be called quite often (on price change for example).

    I also have coded in some of the indicators, in a different way

    for example, in declarations

    private SMA SMA1;
    SMA1 = SMA(Volumes[0], 50);

    The access is via

    SMA1[0];

    So, my general query is, and basically just looking for your opinion, which is the most efficient to use, if being called regularly?

    My thoughts were that the first results in the whole SMA calculation and series being evaluated each time. The second keeps it up to date on the fly, but at the cost of keeping the series in memory?

    Is there a difference?
    Which method would you recommend?

    Thanks!

    #2
    Hello pjsmith,

    Thanks for your inquiry.

    If you are calling the indicator multiple times, it would be a best practice to store a reference to that instance of an indicator rather than calling the indicator method multiple times.

    This is outlined in the NinjaScript Best Practices page of the help guide. I'll provide a link to this publicly available resource below.

    NinjaScript Best Practices (Performance) - https://ninjatrader.com/support/help...tm#Performance

    Please let us know if you have any additional questions.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    637 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    366 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    107 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    569 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    571 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X