I am running a backtest of my strategy in Strategy Analyzer and run into troubles.
In this example, I have a SellShort position of 156 shares of NFLX. After conditions are met, I take a reverse position by using EnterLong(). NT triggered PlaceOrder() to close the current SellShort position, cancel the protective Stop Order for the associated SellShort position, and attempts to enter into a Long position.
TraceOrder output the follows:
19-Jan-19 3:45:00 AM Entered internal PlaceOrder() method at 19-Jan-19 3:45:00 AM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=200 LimitPrice=0 StopPrice=0 SignalName='5M_Lg0' FromEntrySignal=''
19-Jan-19 3:45:00 AM Cancelled pending exit order, since associated position is closed: Order='NT-00003/Backtest' Name='Stop loss' State=Working Instrument='NFLX' Action=BuyToCover Limit price=0 Stop price=340.65 Quantity=156 Strategy='SimpleSARStrategy' Type=Stop Tif=Gtc Oco='NT-00002-140' Filled=0 Fill price=0 Token='3cbcf12bddc3442fbbb8771e6312c1a5' Gtd='01-Dec-99 12:00:00 AM'
Then I expect NT to trigger the OnExecution() method. I override OnExecution with the following lines of code:
protected override void OnExecution(IExecution execution)
{
Print(header+" ###OnExecution### Execution: "+ execution.ToString());
Print(header+" ###OnExecution### ExecutionOrder: "+execution.Order);
......
}
NT entered OnExecution as I expected, and completed the first line of Print, but when it comes to the 2nd line of Print, it prompted "Error on calling 'OnExecution' method, Object reference not set to an instance of an object."
Output is as follow:-
(NFLX 5Min) ###OnExecution### Execution: Execution='NT-00003' Instrument='NFLX' Account='Backtest' Name='Close position' Exchange=Default Price=339.77 Quantity=156 Market position=Long Commission=0 Order='NT-00004' Time='19-Jan-19 3:50:00 AM'
(NFLX 5Min) ###OnExecution### ExecutionOrder:
**NT** Error on calling 'OnExecution' method for strategy 'SimpleSARStrategy/158d54539ad541e588d20e569e7f2ffb': Object reference not set to an instance of an object.
I wonder if execution.Order pointed to null so this error occurred?
I have no problem running this strategy in Market Replay or realtime, but somehow it comes to error when I do a backtest.
I will be very grateful if someone can shed some lights on what is going on here.
Thank you very much!
Cheers,
Hiromichi
Comment