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

Does NT create new instance of indicator class each time it's called?

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

    Does NT create new instance of indicator class each time it's called?

    Hi,

    I want to be sure I understand how NT (v7) loads custom indicators. Let's say I create a new indicator in NT called foo() that takes a single integer parameter. Since indicator parameters are private class variables, it would seem NT would have to create a new instance of the class foo for every time every time it appears in code.

    Secondly, I would expect NT only creates one instance of an indicator class per usage per chart over the lifetime of the chart (which "restarts" if you recalc the NinjaScript, etc.).

    Let's say I have a second indicator bar, and the OnBarUpdate() method of this second indicator bar includes the following:

    Plot0.Set(foo(14)[0]);
    Plot1.Set(foo(21)[0]);

    For a given use of the indicator bar, when CurrentBar == 0, at that point (or earlier) does NT create two instances of foo that live for the life of the indicator, or, does NT create a new instance of foo each time CurrentBar is called? If if it's the first scenario, which I would guess it is for the sake of efficiency, if I put two instances of the indicator bar on a chart, does that then mean that NT news up two instances of bar and therefore four instances of foo?

    The reason I need to be sure is that I want to be certain that the state of private variables in my indicator classes is not overwritten by other uses of the indicator and that the state persists between calls to OnBarUpdate.

    Thanks,

    Gordon
    Last edited by grose; 06-19-2011, 11:09 AM. Reason: Clarify question

    #2
    Gordon, I will have someone get back to you tomorrow.
    AustinNinjaTrader Customer Service

    Comment


      #3
      Gordon, NT would attempt to internally cache the instances of the indicator, so if you call the indicator again with the exact same parameters the already created instance is used.
      BertrandNinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by traderqz, Yesterday, 12:06 AM
      11 responses
      27 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by PaulMohn, Today, 03:49 AM
      0 responses
      7 views
      0 likes
      Last Post PaulMohn  
      Started by inanazsocial, Today, 01:15 AM
      1 response
      9 views
      0 likes
      Last Post NinjaTrader_Jason  
      Started by rocketman7, Today, 02:12 AM
      0 responses
      10 views
      0 likes
      Last Post rocketman7  
      Started by dustydbayer, Today, 01:59 AM
      0 responses
      4 views
      0 likes
      Last Post dustydbayer  
      Working...
      X