Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Initialize() called more than once before OnBarUpdate()?

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

    Initialize() called more than once before OnBarUpdate()?

    I open a form from the Initialize() method based on the belief that Initialize() would be called only once for a strategy. This doesn't seem to be the case since my form is being opened multiple times before OnBarUpdate() is even called.

    I tried overriding OnStartUp() to open my form but the compiler is not finding any such method to override. I'm using NT 6.5.1000.14. Is the OnStartUp() method only in NT 8?

    A different work around would be to use a flag to force a 1 time execution of certain code?

    Any other suggestions?

    #2
    Hello aascotty,

    As you're probably aware, this isn't a supported use of NinjaScript.

    You may get some helpful ideas from this thread:
    http://www.ninjatrader-support2.com/...ead.php?t=3292&
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Initialize() called 3 times on backtest

      I commented out my Form.showDialog() calls. There is no form since questions regarding forms are not supported by NT support. I created a static integer counter variable, "static int InitializeCounter", and incremented it in Initialize() to see how many times Initialize() is called. I went ahead and started a backtest. Initialize() is called 3 times during the running of the backtest. Why is that happening? What is the workaround to satisfy the need for certain code to be executed only once in the lifetime of the instantiated strategy object? All I'm doing is running a backtest on my strategy. No form or indicator dialogs are being opened. 1 timeframe is used. This question should be supported since it involves the Initialize() method which is briefly explained in the Help document:

      Definition
      The Initialize() method is called once when starting a strategy. This method can be used to configure indicator and strategy properties.

      For example:

      • <LI class=rvps1>Strategies - Call the Add() method to add indicators to charts and to add additional Bars objects to the strategy <LI class=rvps1>Indicators - Set configuration properties such as Overlay and PaintPriceMarkers
      • Although this method is called once on the start of an indicator or strategy, there are times that this method is also called (Opening an indicator dialog) when you may not expect it to. FOR ADVANCED PROGRAMMERS, DO NOT USE THIS METHOD TO RUN CUSTOM ROUTINES SUCH AS OPENING FORMS, MAKING EXTERNAL CALLS SUCH AS A LICENSE CHECK.
      Last edited by aascotty; 02-18-2010, 05:38 PM.

      Comment


        #4
        Hi aascotty,

        I'll have someone reply to you tomorrow.
        Last edited by NinjaTrader_RyanM1; 02-18-2010, 06:05 PM.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Correct, the Initialize() can be called multiple times at strategy / indicator startup, this is why we introduced the OnStartUp() method for NT7 (only available here).

          You could move those sensitive parts for example to the first OnBarUpdate() call -

          if (CurrentBar == 0)
          {
          }

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          663 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          376 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          110 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          575 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          580 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X