Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Double Instantiation of Indicator

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

    Double Instantiation of Indicator

    I wrote my own indicator with a public data series and it generates graphics on the screen (line and dots - no plots)

    When I use the indicator in the Initialize method of the strategy - that works fine and I see all of the drawings.

    But then when I want to retrieve the data series in the OnBarUpdate() - I can not figure out how to retrieve the data from the indicator added at the beginning.

    If I simply call my indicator again in OnBarUpdate() like this:
    double myvalue = MyIndicator(a,b,c,d,e,f,g)[0]

    Then it seems to me that this is wasting memory because I am in essence creating another instance of the Indicator in memory - and it is having to process the 256 bars backwards.

    Is there a best practice on how to limit the # of times an indicator is created?

    TODDL

    #2
    Hello TODDLINDSTROM,

    Thank you for writing in. You can just initialize the indicator into a variable. For example:
    Code:
    	private SMA mySMA;
            protected override void Initialize()
            {
                CalculateOnBarClose = true;
    	    Add(mySMA = SMA(14));
            }
            protected override void OnBarUpdate()
            {
    	    Print(mySMA[0]);
    	    Print(mySMA[1]);
            }
    Please let me know if I may be of further assistance.
    Michael M.NinjaTrader Quality Assurance

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    115 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    161 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    83 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    127 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    87 views
    0 likes
    Last Post PaulMohn  
    Working...
    X