PDA

View Full Version : When is "Initialize" called?


stevent
08-23-2010, 08:54 AM
I have some code I was testing that sends email notifications. I put it into the "Initialize" method of my test strategy so that I could see if it worked or not.

However, now I find that whenever I open the "Strategy" dialog box, regardless of which strategy I am invoking, I get an email notification for my test strategy.

Why is Initialize for my strategy that I'm not using getting called, and under what circumstances does Initialize get called? It is unexpected that it would get called when the Strategy dialog box is opened...

thanks for any help,

Steve

NinjaTrader_RyanM
08-23-2010, 09:14 AM
Hello Stevent,

Initialize() is called for all strategies and can be called more than once. It's used to load up the list of strategies whenever you need to select one from the dialog window.

If you would like items to run only once for a particular strategy, you can do this on the first bar of the series, within OnBarUpdate.

if (CurrentBar == 0)
{
//Startup logic here
}

NinjaTrader 7 introduces OnStartup() (http://www.ninjatrader.com/support/helpGuides/nt7/onstartup.htm)method for this that works similar.