Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to have multiple instances of an indicator?

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

    How to have multiple instances of an indicator?

    It seems that the indicator methods in a strategy instantiate a "singleton" or static reference to the indicator object. That means only one instance of it exists.

    However, I have an indicator called Current10MinsOHL() to calculated the same for only 10 minutes. But I now need it to be variable on 20 minutes and 5 minutes as well as 10 minutes.

    So rather than hard code the time span, it needs a property, Minutes, to set how many minutes to track the current OHL.

    Currently in the initialize method, I call the Add() method like the examples:

    Add(Current10MinsOHL());

    However, if I make this indicator property driven, can the Add function work this way instead?

    CurrentOHL slowOHL = new CurrentOHL();
    slowOHL.Minutes = slowMinutes; // from a property
    Add( slowOHL );

    CurrentOHL medOHL = new CurrentOHL(10);
    medOHL.Minutes = medMinutes; // from a property
    Add( medOHL );

    CurrentOHL fastOHL = new CurrentOHL(10);
    fastOHL.Minutes = fastMinutes; // from a property
    Add( fastOHL );

    Or will it get confused expecting a single instance of CurrentOHL();

    Sincerely,
    Wayne

    #2
    >> Add(Current10MinsOHL());
    Anything else than that is not supported. Meaning you should not try to create multiple instances.

    Note: Basically you only can multiple instances if the params of an indicator differ. Does not work here, since this indicator has no params.

    Comment


      #3
      Oh, thanks. This helps. I saw some of the auto-generated code doing something related to multiple params. That helps me understand. I'll experiment.

      Thanks,
      Wayne

      Comment


        #4
        Muliple instances

        Only way I hav found to do this is to use identical inicators with differing names

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by charlesugo_1, 05-26-2026, 05:03 PM
        0 responses
        60 views
        0 likes
        Last Post charlesugo_1  
        Started by DannyP96, 05-18-2026, 02:38 PM
        1 response
        147 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        162 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 05-10-2026, 08:12 PM
        0 responses
        97 views
        0 likes
        Last Post CarlTrading  
        Started by Hwop38, 05-04-2026, 07:02 PM
        0 responses
        284 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Working...
        X