Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

where do the instances of indicators live constructed within the strategy class?

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

    where do the instances of indicators live constructed within the strategy class?

    I am new to Ninja as well as C# and have a conceptual question regarding the way the code is organized. Please forgive me if my question is very naïve

    If I use for example
    Add(SMA(Fast));

    I assume the code is calling a constructor of the SMA indicator class and creates an instance of this indicator within my strategy implementation. What confuses me is that I do not see the name of this instance.

    As a result, when querying the indicator I do not refer to this instance but instead I need to do

    CrossAbove(SMA(Fast), SMA(Slow), 1))

    for example. Does the statement SMA(Fast) in the above line refers to the instance or does it recreate the object every time I need it.


    many thanks



    #2
    Originally posted by alexL View Post
    I am new to Ninja as well as C# and have a conceptual question regarding the way the code is organized. Please forgive me if my question is very naïve

    If I use for example
    Add(SMA(Fast));

    I assume the code is calling a constructor of the SMA indicator class and creates an instance of this indicator within my strategy implementation. What confuses me is that I do not see the name of this instance.

    As a result, when querying the indicator I do not refer to this instance but instead I need to do

    CrossAbove(SMA(Fast), SMA(Slow), 1))

    for example. Does the statement SMA(Fast) in the above line refers to the instance or does it recreate the object every time I need it.


    many thanks


    It creates its own instances. If you look at the "wrapper code" in the indicator, you will see that among other things it used for iterating through the domain to find the correct instances of itself.

    Using a named instance is more efficient, so create your SMA's as named instances:
    1. Declare them as class variables.
    2. Assign them in the Initialize() method.
    Last edited by koganam; 07-17-2014, 06:22 AM.

    Comment


      #3
      Hello AlexL,

      Thank you for your post.

      When you use Add(), it will create an instance of that indicator and cache it.

      When you call that SMA(Fast) you are indeed calling that cached instance as to save memory.

      Let me know if I can be of further assistance.
      Cal H.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      580 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      335 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      102 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      554 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      552 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X