NinjaTrader Support Forum  
X

Attention!

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


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 02-16-2010, 04:32 PM   #1
aascotty
Junior Member
 
Join Date: Jul 2009
Posts: 19
Thanks: 0
Thanked 1 time in 1 post
Default 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?
aascotty is offline  
Reply With Quote
Old 02-16-2010, 05:04 PM   #2
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

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&
NinjaTrader_RyanM is offline  
Reply With Quote
Old 02-18-2010, 04:33 PM   #3
aascotty
Junior Member
 
Join Date: Jul 2009
Posts: 19
Thanks: 0
Thanked 1 time in 1 post
Default 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 at 04:38 PM.
aascotty is offline  
Reply With Quote
Old 02-18-2010, 04:58 PM   #4
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

Hi aascotty,

I'll have someone reply to you tomorrow.
Last edited by NinjaTrader_RyanM; 02-18-2010 at 05:05 PM.
NinjaTrader_RyanM is offline  
Reply With Quote
Old 02-19-2010, 04:21 AM   #5
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,404
Thanks: 252
Thanked 973 times in 956 posts
Default

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)
{
}
NinjaTrader_Bertrand is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

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


All times are GMT -6. The time now is 02:17 PM.