Announcement

Collapse
No announcement yet.

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.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by sjsj2732, Yesterday, 04:31 AM
      0 responses
      31 views
      0 likes
      Last Post sjsj2732  
      Started by NullPointStrategies, 03-13-2026, 05:17 AM
      0 responses
      286 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      283 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      132 views
      1 like
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      91 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Working...
      X