Why is it that the call to `ExitRemove` in `die` did not immediately exit the EA?
The Expert Advisor is not stopped immediately as you call ExpertRemove(); just a flag to stop the EA operation is set. That is, any next event won't be processed, OnDeinit() will be called and the Expert Advisor will be unloaded and removed from the chart.
Esfan: ensure(OrderModify(order_ticket_number, OrderOpenPrice(), new_stop_loss, OrderTakeProfit(), OrderExpiration(), Red), "Unable to modify SL");
- When you post code please use the CODE button (Alt-S)!
(For large amounts of code, attach it.)
Please edit
your (original) post.
General rules and best pratices of the Forum. - General - MQL5 programming forum
Messages Editor - Your code doesn't appear to select a ticket, therefor OrderOpenPrice, OrderTakeProfit, and OrderExpiration are undefined.
- You don't show the code that would call those functions. We are not mindreaders.
- You don't show the declaration of order_ticket_number. We are not mindreaders.

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I wrote an EA for my wife. On reaching a specified price it closes a portion of the lots and moves the stop loss.
i.e.
```
input double new_stop_loss;
...
// modify the SL
ensure(OrderModify(order_ticket_number, OrderOpenPrice(), new_stop_loss, OrderTakeProfit(), OrderExpiration(), Red), "Unable to modify SL");
ensure(OrderClose(order_ticket_number, tp_1_close_lots, Bid, 3, Red), "Unable to close order");
void ensure(bool predicate, string msg) {
if (!predicate) {
die(msg);
}
}
void die(string msg) {
MessageBox("Exiting: " + msg + ": " + IntegerToString(GetLastError()));
ExpertRemove();
}
```
As you can see, the EA attempts to change the stop. But if it fails it will exit using `ExpertRemove`.
Yesterday she ran the EA with a SL value that equaled the existing SL. As such, when the price was hit overnight, OrderModify died because the values hadn't changed. However, hours later when we hit "OK" on the dialog box, the script continued to run! It exited half the trade at a completely different price than intended!
Why is it that the call to `ExitRemove` in `die` did not immediately exit the EA?