View Full Version : Multiple Stratergies, one symbol.
CraigC
06-22-2008, 08:16 PM
Does NT support this? When I add a second strategy for the same symbol I get all sorts of weird behavior. Calling EnterLong()/EnterShort seems to throw a null reference exception.
CraigC
06-22-2008, 10:52 PM
...more to this...it's not just multiples, I can do it with single strategies as well.
My code looks like this
protected override void OnMarketDepth(MarketDepthEventArgs e)
{
if (Historical)
{
return;
}
bool buy = yada...
bool sell = yada...
if (Position.MarketPosition == MarketPosition.Flat)
{
if (buy)
{
EnterLong();
}
if (sell)
{
EnterShort();
}
}
else
{
if (Position.MarketPosition == MarketPosition.Long && sell)
{
EnterShort();
}
if (Position.MarketPosition == MarketPosition.Short && buy)
{
EnterLong();
}
}
}
It seems that the Historical check sometimes fails when the strategy is started out of session time, leading to the 'Enter' call which throws.
NinjaTrader_Dierk
06-22-2008, 11:15 PM
I suggest debugging your strategy as per here: http://www.ninjatrader-support.com/vb/showthread.php?t=3418
CraigC
06-22-2008, 11:37 PM
I tried putting in logging statements, this is how I know the 'Historical' check fails followed by the order send which throws.
NinjaTrader_Dierk
06-22-2008, 11:39 PM
Sorry I don't follow.
Please post the critical section of your code and point to the exact line which is the last one which prints. Thanks
CraigC
06-23-2008, 01:01 AM
They are set up for overnight testing at the moment, but I will recreate and post the relevant section tomorrow.
CraigC
06-23-2008, 06:19 PM
Ok, I have attached code that has the same problem.
I set the session hours for 1:30 AM -> 7:30 AM (Auckland, NZ time).
I launch the strategy at ~12:00 PM, I instantly get a buy order and the error in the log. If you need anything else let me know.
Thanks in advance.
NinjaTrader_Josh
06-23-2008, 09:45 PM
Hi CraigC,
Please check out this tip. You are most likely running into this issue: http://www.ninjatrader-support.com/vb/showthread.php?t=4226
CraigC
06-23-2008, 10:07 PM
I'm not sure what I should checking for NULL, as I only access 'Historical' and 'EnterLong()'. Enter long is a function so I can't check that and 'Historical' is a property on the current strategy instance (which I assume is created otherwise we would not be in the function in the first place) so I can't check it for NULL either. On top of that it is the EnterLong() that is throwing the exception, should not the 'Historical' check have returned true given the setup which I quote I my previous post? Sorry if I'm missing something here.
NinjaTrader_Dierk
06-24-2008, 01:33 AM
This is a bug related to a race condition on strategy start. It will be fixed with next update. Thanks for pointing that out.
CraigC
06-24-2008, 02:33 AM
No Problem.
I have not being able to recreate this by attaching a strategy to a chart as opposed to the main window, so maybe this is a workaround for now.