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 NullPointStrategies, Today, 05:17 AM
    0 responses
    49 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    126 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    66 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    42 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    46 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X