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