View Full Version : 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
NinjaTrader_Ray
05-14-2007, 03:47 PM
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.
Thanks Ray
ok, I didn't want to remove it my system and erase my history if I didn't have to.
Cliff
NinjaTrader_Dierk
05-14-2007, 11:07 PM
He needs to have a feed for the secondary instrument as well. No data -> no OnBarUpdate will be triggered.
imisuno
05-15-2007, 08:25 AM
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...).
NinjaTrader_Ray
05-15-2007, 08:51 AM
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
imisuno
05-15-2007, 09:08 AM
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.
NinjaTrader_Ray
05-15-2007, 09:18 AM
You have to perform the check in OnBarUpdate().
if (BarsArray[1] != null)
Print(Instruments[1].FullName);