To track account balance and use it in my backtest model I have put the following code at the end of my script:
protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time) { if (execution.Order != null && execution.Order.OrderState == OrderState.Filled) { if(execution.Order.Name == "BrunsBuy") { AcctValue = (AcctValue - ((execution.Price)* execution.Quantity)); Print(AcctValue.ToString()+" - "+(execution.OrderId)+" "+(execution.Time)); } } }
MTCH Output:
4919.42 - NT-00000-1418 12/24/2019 12:00:00 PM
AMD Output:
4953.23 - NT-00000-1435 12/26/2019 3:00:00 PM
4898.43 - NT-00002-1435 2/14/2020 3:00:00 PM
When it runs on the instrument list of the above items I get the following:
4953.23 - NT-00000-1452 12/26/2019 3:00:00 PM Order ID did not happen
4898.43 - NT-00002-1452 2/14/2020 3:00:00 PM Order ID did not happen
4919.42 - NT-00000-1453 12/24/2019 12:00:00 PM Order ID did not happen
4851.66 - NT-00000-1459 12/26/2019 3:00:00 PM This Order ID occurred
4796.86 - NT-00002-1459 2/14/2020 3:00:00 PM This Order ID occurred
4838.84 - NT-00000-1467 12/24/2019 12:00:00 PM This Order ID occurred
I'm just running this on the buy executions right now. Where are these random buy IDs coming from when I run this on two instruments at once? These are no where to be found in the strategy analyzer. Note how the output did not print them in chronological order either... which is weird to me.
Alec
Comment