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 05-14-2007, 03:35 PM   #1
ct
Senior Member
 
Join Date: Dec 2006
Location: Nelson, New Zealand
Posts: 371
Thanks: 1
Thanked 3 times in 3 posts
Question Optional instrument

Scenario: I have an strategy that uses an instrument that comes from a secondary data feed. I have a friend that wants to use my strategy. They don't have the secondary data feed.

Question: If they don't have the feed or instrument active what will the NT strategy do? I didn't know if I needed to modify it to make the check optional or if it would just return zeros on the values.

Cliff
ct is offline  
Reply With Quote
Old 05-14-2007, 03:47 PM   #2
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,164
Thanks: 6
Thanked 46 times in 32 posts
Default

Good question. Although I believe I know what will happen, I will need to double check with Dierk. He will likely reply later on late this evening.
NinjaTrader_Ray is offline  
Reply With Quote
Old 05-14-2007, 06:42 PM   #3
ct
Senior Member
 
Join Date: Dec 2006
Location: Nelson, New Zealand
Posts: 371
Thanks: 1
Thanked 3 times in 3 posts
Wink

Thanks Ray

ok, I didn't want to remove it my system and erase my history if I didn't have to.

Cliff
ct is offline  
Reply With Quote
Old 05-14-2007, 11:07 PM   #4
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

He needs to have a feed for the secondary instrument as well. No data -> no OnBarUpdate will be triggered.
NinjaTrader_Dierk is offline  
Reply With Quote
Old 05-15-2007, 08:25 AM   #5
imisuno
Junior Member
 
Join Date: Apr 2007
Location: , ,
Posts: 6
Thanks: 0
Thanked 0 times in 0 posts
Default Detecting if datafeed/instrument is available?

In addition to this topic, how one can detect programmatically if a call to BaseStrategy.Add() was successful, and corresponding instrument will be available in OnBarUpdate at expected index through BarsArray/Opens/Closes etc properties?

Scenario:
Initialize()
{
Add("Secondary feed instrument", Ticks, 50);
Add("Primary feed instrument");
}
OnBarUpdate()
{
BarsArray[1] // <-- what instrument it will refer to if there was no secondary feed?
}

Thanks!

p.s. Testing whether BarsArray.Length increased after Add() causes run-time exception (cannot access BarsArray property in Initialize() method...).
Last edited by imisuno; 05-15-2007 at 08:27 AM.
imisuno is offline  
Reply With Quote
Old 05-15-2007, 08:51 AM   #6
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,164
Thanks: 6
Thanked 46 times in 32 posts
Default

Hi,

1) If there was no instrument in BarsArray[1] then the strategy would throw an exception (seen in the Log tab) and terminate

2) Correct, you can not access BarsArray from the Initialize() method
NinjaTrader_Ray is offline  
Reply With Quote
Old 05-15-2007, 09:08 AM   #7
imisuno
Junior Member
 
Join Date: Apr 2007
Location: , ,
Posts: 6
Thanks: 0
Thanked 0 times in 0 posts
Default

Ray, thank you very much.
Sorry, I have not described in details what I am trying to achieve. I need to know at runtime whether instrument was added successfully or not, i.e., which instrument BarsArray[1] would refer to, in the example below, "Secondary feed" or "Primary", so that my strategy will know which instruments it is using.

Sure, I can add all primary instruments first and then detect that there are no secondary ones, and to disable all checks involved. Ok, I think this is acceptable.

Thank you again.
imisuno is offline  
Reply With Quote
Old 05-15-2007, 09:18 AM   #8
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,164
Thanks: 6
Thanked 46 times in 32 posts
Default

You have to perform the check in OnBarUpdate().

Code:
if (BarsArray[1] != null)
    Print(Instruments[1].FullName);
NinjaTrader_Ray 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
Instrument Manager Oli Automated Trading 2 02-26-2007 01:35 AM
How do I check for the instrument name? NinjaTrader_Ray General Programming 0 02-07-2007 01:24 AM
Instrument Manager Quicktrader10 Miscellaneous Support 2 01-17-2007 07:57 AM
Name Of Instrument guym Indicator Development 2 11-27-2006 09:21 AM
IB trying to Add Instrument ER2 Ripcat Miscellaneous Support 4 09-25-2005 01:51 PM


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