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 many times are indicators loaded?

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

    How many times are indicators loaded?

    I have an indicator that loads a large amount of data into memory. So I figured I would place this load in Indicator.Initialize. But it looks like this gets called quite a bit of times. I placed a simple:

    MessageBox.Show( "Count: " + count);

    Inside of Initialize. I put a count there just so I could make sure that Initialize was not being called multiple times. Which it was not. Rather, each was a new instantiation. And given I am loading quite a bit of data, this does not work. I find that it got called at each of the following points:

    1. When I had a chart up and clicked the "Add Indicator" button
    2. A 2nd time when I actually clicked on my indicator(on the list with the others)
    3. A 3rd and 4th time when I click apply to add my indicator to the chart

    Everything else works fine, but the indicator gets instantiated a total of four times. Which ends up chewing up a bunch of memory.

    Do you have any sort of "true" Initialize that only gets called when an indicator class is really actually going to be used? Or do I need to sort of simulate my own by using a temp variable and detecting the first time that OnBarUpdate is called. Then if so, when is Initialize actually supposed to use, given that NT seems to be creating quite a few temporary objects before it actually uses my indicator.

    Also, is any sort of method called when an indicator is "closed", like when the chart it is attached to is closing? So I can unload things?

    #2
    jeff,

    When you use apply it will reset the indicator and call the initialize method. The initialize method is called each time the indicator is instantiated.

    I will attempt to replicate and discuss with our tech leader to see if I can explain further.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Jeff, can you try your loading in NT7's OnStartUp() instead?



      To clean up custom resources used, you can use OnTermination().

      BertrandNinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by benmarkal, Yesterday, 12:52 PM
      3 responses
      22 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by helpwanted, Today, 03:06 AM
      1 response
      17 views
      0 likes
      Last Post sarafuenonly123  
      Started by Brevo, Today, 01:45 AM
      0 responses
      11 views
      0 likes
      Last Post Brevo
      by Brevo
       
      Started by aussugardefender, Today, 01:07 AM
      0 responses
      6 views
      0 likes
      Last Post aussugardefender  
      Started by pvincent, 06-23-2022, 12:53 PM
      14 responses
      244 views
      0 likes
      Last Post Nyman
      by Nyman
       
      Working...
      X