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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    44 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    54 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    34 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    95 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    57 views
    0 likes
    Last Post PaulMohn  
    Working...
    X