During backtesting with NT7 i discovered 2 different problems with multi-instrument strategies and LimitOrders.
But first, here is the strategy fragment i used for reproducing the behavior. It's quite simple, for both instruments (primary and XLF) a Limit Order 3% below the close valid for one bar will be submitted.
public class Test_LimitOrders: Strategy
{
private bool[] m_OrdersSubmitted;
protected override void Initialize()
{
TraceOrders = true;
m_OrdersSubmitted = new bool[2];
m_OrdersSubmitted[0] = false;
m_OrdersSubmitted[1] = false;
Add("XLF", PeriodType.Day, 1);
}
protected override void OnBarUpdate()
{
if (m_OrdersSubmitted[BarsInProgress])
{ // Limit Order already submitted
return;
}
EnterLongLimit(BarsInProgress, false, 100, Closes[BarsInProgress][0] * 0.97, BarsInProgress.ToString());
m_OrdersSubmitted[BarsInProgress] = true;
}
}
Here the output:
17.02.2011 06:00:00 Cancelled expired order: BarsInProgress=0: Order='NT-00000/Backtest' Name='0' State=Working Instrument='XLK' Action=Buy Limit price=26,0348 Stop price=0 Quantity=100 Strategy='Test_LimitOrders' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='b6a4d143d3f74f0b82b5e6a6e9fa9d80' Gtd='01.12.2099 00:00:00'
17.02.2011 06:00:00 Entered internal PlaceOrder() method at 17.02.2011 06:00:00: BarsInProgress=1 Action=Buy OrderType=Limit Quantity=100 LimitPrice=16,65 StopPrice=0 SignalName='1' FromEntrySignal=''
18.02.2011 06:00:00 Cancelled expired order: BarsInProgress=1: Order='NT-00001/Backtest' Name='1' State=Working Instrument='XLF' Action=Buy Limit price=16,6452 Stop price=0 Quantity=100 Strategy='Test_LimitOrders' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='db6ae6471a454e8ca2bde1d6f4c74ea5' Gtd='01.12.2099 00:00:00'
Apart from that, EnterLongLimit performs as expected, the Orders are cancelled one bar later. So, let's restart again with 16.02.2011 as starting day (one day later)...
18.02.2011 06:00:00 Cancelled expired order: BarsInProgress=0: Order='NT-00000/Backtest' Name='0' State=Working Instrument='XLK' Action=Buy Limit price=26,1803 Stop price=0 Quantity=100 Strategy='Test_LimitOrders' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='2e8928e303fa4b95af3a19d6c08e1632' Gtd='01.12.2099 00:00:00'
18.02.2011 06:00:00 Entered internal PlaceOrder() method at 18.02.2011 06:00:00: BarsInProgress=1 Action=Buy OrderType=Limit Quantity=100 LimitPrice=16,63 StopPrice=0 SignalName='1' FromEntrySignal=''
Thank you, Robin

Comment