NinjaTrader Support Forum  

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 01-23-2009, 08:04 AM   #1
Follow Shadan
Junior Member
 
Join Date: Jan 2008
Posts: 14
Thanks: 0
Thanked 0 times in 0 posts
Default Where to do initlization every time the strategy is started (not the Initialize())?

The Initialize() function is only called when the first time to start a strategy. If you stop the strategy (but do not remove it), and start it again, the Initialize() is not called. Is there any event that will be trigger when a user click the "start" button in the strategies tab? Thanks, Jason
Follow Shadan is offline  
Reply With Quote
Old 01-23-2009, 08:33 AM   #2
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
Default

Hi Follow Shadan,

You should never place logic in the Initialize() method. Instead you will want to place it in the OnBarUpdate() method. At the top of OnBarUpdate(), you can do something like this:

Code:
if (CurrentBar == BarsRequired && start == false)
{
     // Do something;
     start = true;
}
else if (CurrentBar == BarsRequired + 1 && start)
     start = false;
start is a bool defined in the Variables section like this:
Code:
private bool start = false;
Alternatively, maybe an easier way could be something like:
Code:
if (CurrentBar == BarsRequired && FirstTickOfBar)
{
     // Do something;
}
NinjaTrader_Josh 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
Getting Started azzurro General Programming 1 12-26-2008 10:29 AM
Some getting started questions about the Chart johannes Charting 1 10-26-2008 05:39 PM
Multiple Calls to "Initialize()" Method on Strategy Start tomcat Strategy Development 3 11-04-2007 01:12 PM
Exit Strategy in Initialize() Oli Automated Trading 10 03-30-2007 03:06 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 09:33 PM.