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 judysamnt7, 03-13-2023, 09:11 AM
      4 responses
      59 views
      0 likes
      Last Post DynamicTest  
      Started by ScottWalsh, Today, 06:52 PM
      4 responses
      36 views
      0 likes
      Last Post ScottWalsh  
      Started by olisav57, Today, 07:39 PM
      0 responses
      7 views
      0 likes
      Last Post olisav57  
      Started by trilliantrader, Today, 03:01 PM
      2 responses
      21 views
      0 likes
      Last Post helpwanted  
      Started by cre8able, Today, 07:24 PM
      0 responses
      10 views
      0 likes
      Last Post cre8able  
      Working...
      X