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 10-09-2009, 11:36 AM   #1
ScoobyStoo
Senior Member
 
Join Date: Apr 2009
Posts: 161
Thanks: 0
Thanked 5 times in 5 posts
Default Strategy start hook

Hi guys

I need a hook which will allow me to run some code when a custom strategy is started. At the moment I've overridden the Initialize() method and placed my setup code in there. However, I've got all kinds of problems (such as TickSize not being accessible) because that method is called any time an instance strategy is created. Obviously this can happen before any instrument has been selected.

There must be some way for me to determine when the strategy has started and pick up info such as the TickSize.

Thanks.
ScoobyStoo is offline  
Reply With Quote
Old 10-09-2009, 11:42 AM   #2
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

Please try this:
- define a boolean flag variable, set to true
- first time OnBarUpdate is called check if flag is true and then
* run your Init() stuff
* set flag variable to false
NinjaTrader_Dierk is offline  
Reply With Quote
Old 10-09-2009, 12:14 PM   #3
ScoobyStoo
Senior Member
 
Join Date: Apr 2009
Posts: 161
Thanks: 0
Thanked 5 times in 5 posts
Default

Already tried that. The problem is the L2 order book gets built before OnBarUpdate() is called for the first time. What I need is a hook which allows me to setup my strategy before any market data events get fired.
ScoobyStoo is offline  
Reply With Quote
Old 10-09-2009, 12:26 PM   #4
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

ScoobyStoo,

Maybe I am missing something but I am not seeing why there is such a requirement of doing this before receiving data events. What is it that you need to build beforehand?
NinjaTrader_Josh is offline  
Reply With Quote
Old 10-12-2009, 02:15 AM   #5
ScoobyStoo
Senior Member
 
Join Date: Apr 2009
Posts: 161
Thanks: 0
Thanked 5 times in 5 posts
Default

Quote:
Originally Posted by NinjaTrader_Josh View Post
ScoobyStoo,

Maybe I am missing something but I am not seeing why there is such a requirement of doing this before receiving data events. What is it that you need to build beforehand?
It's OK, don't worry about it. I need to construct a ton of objects required by the strategy prior to it beginning to process market data. I've fixed it by including a call at the beginning on each overridden market data method to determine if the strategy has been initialised and if not to initialise it. That way I know that whichever market data event is raised first, the strategy will get correctly initialised. It's a really ugly solution though...

Would be really handy for NT7 to expose proper hooks to all the strategy lifecycle events (start, pause, stop etc). Obviously, I don't know how difficult that would be to do though...

Thanks for the help
ScoobyStoo is offline  
Reply With Quote
Old 10-12-2009, 06:08 AM   #6
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,407
Thanks: 252
Thanked 974 times in 957 posts
Default

Great you got it working, thanks for the suggestions ScoobyStoo.
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
Ross Hook and 1-2-3- Pattern razorbuzz Charting 4 09-12-2010 11:15 AM
Two CCI hook MartinBrr Strategy Analyzer 3 06-09-2009 05:55 AM
Start Strategy volpiemanuele Automated Trading 5 08-07-2008 02:14 AM
start strategy again max-td Strategy Development 5 04-24-2008 04:32 AM
MB Trading Hook-up Savage1701 Connecting 3 08-03-2005 05:11 AM


All times are GMT -6. The time now is 03:15 AM.