Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator with multiple public properties, is it cloned on each call, or cached?

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

    Indicator with multiple public properties, is it cloned on each call, or cached?

    Hi,

    I have a conceptual question about an indicator script which can return multiple public properties.

    When I assign those values in a third indicator (or strategy) for example:
    Code:
    double M_I_PV1 = MyIndicator(Close, 14)[0].PublicValue1  ;
    double M_I_PV2 = MyIndicator(Close, 14)[0].PublicValue2  ;
    does NinjaTrader make a clone or copy of the referenced indicator script to get Public Value2, or does it "know" it is already loaded in memory and it uses the same object instance to return the PV2?

    It doesn't seem to matter from a performance standpoint, I'm just wondering.

    If it does matter, then would it be better to have the indicator return an object which encapsulates multiple properties, and then access those properties during assignment to local variables?

    Code:
    object MyIndReturnObj = MyIndicator(Close, 14)[0] ;
    double M_I_PV1 = MyIndReturnObj.PublicValue1;
    double M_I_PV2 = MyIndReturnObj.PublicValue2;




    If I reference a third line to the same indicator, but using different arguments / parameters, I believe NT must create a separate instance of that object because it is using different input arguments / parameters, is that correct?

    Thanks.

    #2
    Hello balltrader,

    The indicator system would know in this case, that is the reason why you don't need to call new MyIndicator(...) and just call MyIndciator(...). There is a cache and as long as the parameters you use didn't change it should use the same instance. You can also store the indicator as a variable like the SampleMACrossOver does to ensure you use the same instance.

    As for the return value, that really depends on your use case. If you need an object or think that would be better you could do that otherwise a simple property will work as well.


    I look forward to being of further assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    647 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    368 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    108 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    571 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    573 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X