The error is stating it is coming from OnOrderUpdate() and not the .Click event handler method.
Further, "After exit" is printing which suggests the run-time error is not occurring in this this code as if it were, no code below the code causing the error would be reached.
I don't think that code is causing the run-time error.
"No Pop ups, no errors and the strategy remains enabled."
A run-time error will disable the script unless you are circumventing the the default behavior by using a try and catch.
The syntax error was my mistake, the second pair of parenthesis is not needed.
Try the following:
TriggerCustomEvent((Action) =>
{
Print("Position.Quantity: " + Position.Quantity);
if (Position.MarketPosition == MarketPosition.Long && Position.Quantity != 0)
{
Print("Trying to exit long");
ExitLong();
Print("After exit");
}
}, null);

Comment