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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    156 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    90 views
    1 like
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    140 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    130 views
    1 like
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    107 views
    0 likes
    Last Post CarlTrading  
    Working...
    X