Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Are indicators instantiated 4 times?

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

    Are indicators instantiated 4 times?

    Hello there,
    I'm a NinjaScript newbie, so be comprehensive for the silly question.

    I created an indicator using NinjaScript with only the Name and the Description. Than I added a private static field as a counter of the number of instances that are created by NinjaTrader when you add it to a chart. I then defined a default contrustructor (i.e. with no parameters) for the indicator to increment the counter and print its value.

    It seems that during the life cycle of an indicator it get instantiated 4 times and destroyed 3 times.

    1. when first I open the dialog to add an indicator to the chart
    2. when I add the indicator to the chart
    3. when I apply the association (or click ok)
    4. Before the indicator get truly attached to the chart.

    At the end survives just the last instance of the indicator. Did I do something wrong or is the standard way NinjaTrader manages indicators?

    Best regards


    #2
    Hi magomimmo, thanks for posting.

    The indicator object is created in a factory by the NinjaTrader core, that is why the "new" keyword is not used when instantiating indicators. e.g. dynamic MySMA = SMA(14);

    The 4 instantiations are used to populate indicators in the property grid. The final instance is the one that will run on the chart which will be destroyed when the chart is closed or the platform shuts down.

    There is a full description of the lifecycle here:


    Best regards,
    -ChrisL

    Comment


      #3
      Thanks so much NinjaTrader_ChrisL.

      My best

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      77 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      40 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      63 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      63 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      53 views
      0 likes
      Last Post CarlTrading  
      Working...
      X