CAlgo crashes after ModifyPosition execution
CAlgo crashes after ModifyPosition execution
28 Feb 2025, 11:10
It is possible this has been raised before, but l like to raise it again with some clarity of what we are experiencing. I have tried to modify positions using both methods available; using the ModifyPosition function on the Algo API and using the ModifyStoplossByPrice function directly on the Position object. In my case, both approsches successfully modified the position. However, in both cases, the CBot object crashes with “ CBot instance [AUDUSD, m30] process was unexpectedly terminated.”.

This is currently happening during backtesting. I have not tried it under normal trading conditions. But l expect it would probably have the same outcome. The other thing to note is that, l do not have this problem when executing a request to open a new position in OnStart or OnBar events. It only happens in the OnTick event with calls to modify an existing position. I suspect it may also crash if one attempts to open a position in OnTick.
My point is that the issue is not with the Modify Position functionality which clearly does its job effectively, there is something else going on at the conclusion of the OnTick event. You can try this out yourself with a basic OnTick with a single line of ModifyPosition to reproduce this issue. Anyone using the OnTick event as part of thier trading strategy is basically stuck at this point in time. Whatever you can do to promptly resolve this problem would be greatly appreciated.
Replies
andrewO
03 Mar 2025, 16:58
Hi CTrader Team, l have put a system exception try catch block around the OnTick event coupled with a global AppDomain Unhandledexception handler. Both cannot seem to catch the source of the Unexpected process termination error. I did not have this problem using this same code in CTrader version 4, please could you investigate this. I am unable to provide any trace as it is not showing anywhere.
@andrewO
andrewO
28 Feb 2025, 12:33
Just for completeness, l have ran the code under a demo account and the “CBot instance [AUDUSD, m30] process was unexpectedly terminated.” error is occurring after the OnStart event has executed, as can be seen the image below. I don't have this problem while backtesting incidentally. I hope this helps clarify things.
@andrewO