![]() |
This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Junior Member
Join Date: Jul 2009
Posts: 19
Thanks: 0
Thanked 1 time in 1 post
|
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 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
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 |
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Jul 2009
Posts: 19
Thanks: 0
Thanked 1 time in 1 post
|
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:
Last edited by aascotty; 02-18-2010 at 04:38 PM.
|
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
Hi aascotty,
I'll have someone reply to you tomorrow.
Ryan M
NinjaTrader Customer Service
Last edited by NinjaTrader_RyanM; 02-18-2010 at 05:05 PM.
|
|
|
|
|
|
#5 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,404
Thanks: 252
Thanked 973 times in 956 posts
|
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) { }
Bertrand
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| when does initialize get called | junkone | Market Analyzer | 1 | 01-27-2010 06:07 AM |
| Single Initialize()-like event called only once for a backtest of many products? | ChiTrader2000 | Strategy Development | 4 | 01-24-2009 10:39 AM |
| Indicator's OnBarUpdate() is called twice | mgbloomfield | Automated Trading | 1 | 04-20-2008 12:07 AM |
| OnBarUpdate() - never seems to be called? | altrader | Miscellaneous Support | 5 | 03-10-2008 07:09 AM |
| Is there a counterpart of Initialize, called when strategy is stopped? | californiaruby | Automated Trading | 2 | 02-20-2007 03:39 AM |