This is the problem I encountered today.
When I get an order update from TradeMonitor
I try to pass the changed orders through the event for processing one by one.
One of the processing steps is to check the order ‘s comment.
I found it is null which will trigger .net to generate a null Exception
I think it should be a empty string.
I modified the mq4 file. But it’s still null
I don't clear the message build process, I think you can fix this problem faster.
This problem also made me discover another place for improvement.
The code in the TimerTradeMonitor line 82 looks like this:
_timer.Elapsed -= _timer_Elapsed; //unregister from events to prevent rise condition during work with orders
Check();
_timer.Elapsed += _timer_Elapsed; //register again
There is event passing in Check() on TradeMonitor line 153
AvailabilityOrdersChanged?.Invoke(this, new AvailabilityOrdersEventArgs(openedOrders, closedOrders));
This null error is included in my processing event
The result is that Check() has an error.
Then _timer.Elapsed += _timer_Elapsed is not executed
So the TradeMonitor was interrupted.
At the same time, the upper order processing event was handled by my try catch.
The result is nothing happens, as if the TimerTradeMonitor did not start running.
I spent a lot of time to find the root cause of this problem.
I think adding and subtracting _timer.Elapsed is not a particularly good method.
You can consider another way to control the switch of the order check event.
Also consider whether to do exception handling when sending events
This is the problem I encountered today.
When I get an order update from TradeMonitor
I try to pass the changed orders through the event for processing one by one.
One of the processing steps is to check the order ‘s comment.
I found it is null which will trigger .net to generate a null Exception
I think it should be a empty string.
I modified the mq4 file. But it’s still null
I don't clear the message build process, I think you can fix this problem faster.
This problem also made me discover another place for improvement.
The code in the TimerTradeMonitor line 82 looks like this:
_timer.Elapsed -= _timer_Elapsed; //unregister from events to prevent rise condition during work with orders
Check();
_timer.Elapsed += _timer_Elapsed; //register again
There is event passing in Check() on TradeMonitor line 153
AvailabilityOrdersChanged?.Invoke(this, new AvailabilityOrdersEventArgs(openedOrders, closedOrders));
This null error is included in my processing event
The result is that Check() has an error.
Then _timer.Elapsed += _timer_Elapsed is not executed
So the TradeMonitor was interrupted.
At the same time, the upper order processing event was handled by my try catch.
The result is nothing happens, as if the TimerTradeMonitor did not start running.
I spent a lot of time to find the root cause of this problem.
I think adding and subtracting _timer.Elapsed is not a particularly good method.
You can consider another way to control the switch of the order check event.
Also consider whether to do exception handling when sending events