Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 jclose, Today, 09:37 PM
        0 responses
        4 views
        0 likes
        Last Post jclose
        by jclose
         
        Started by WeyldFalcon, 08-07-2020, 06:13 AM
        10 responses
        1,413 views
        0 likes
        Last Post Traderontheroad  
        Started by firefoxforum12, Today, 08:53 PM
        0 responses
        9 views
        0 likes
        Last Post firefoxforum12  
        Started by stafe, Today, 08:34 PM
        0 responses
        10 views
        0 likes
        Last Post stafe
        by stafe
         
        Started by sastrades, 01-31-2024, 10:19 PM
        11 responses
        169 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Working...
        X