Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Is using an indicator directly slower than defining it at the start?

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

    Is using an indicator directly slower than defining it at the start?

    Is there any difference in speed/computation time between these two code snippets:

    1.
    ```
    private SMA mySMA;

    mySMA = SMA(200);
    AddChartIndicator(mySMA);

    In OnBarUpdate:

    if (Close[0] > mySMA[0]) ...
    ```

    2.

    ```
    AddChartIndicator(SMA(200));

    In OnBarUpdate:
    if (Close[0] > SMA(200)) ...
    ```

    #2
    Hello haakonflaar,

    Thanks for your post.

    There would be very little to no difference in the performance of the strategy between the two scenarios you described. The difference in performance if there is any would likely not be noticeable when running the strategy.

    From the NinjaScript Best Practices for Performance help guide page: If you are reusing an indicator several times through your code (especially indicators with many parameters), you can take further steps to refine performance by storing a reference to the indicator instance yourself (although it is by no means a requirement, and this suggestion does not need to be followed strictly)

    NinjaScript Best Practices for Performance: https://ninjatrader.com/support/help...tm#Performance

    See this help guide page for more information about AddChartIndicator(): https://ninjatrader.com/support/help...tindicator.htm

    See this help guide page for more information about adding indicator's to strategies: https://ninjatrader.com/support/help..._strategie.htm
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    89 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    135 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    68 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    119 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    69 views
    0 likes
    Last Post PaulMohn  
    Working...
    X