Retry logic for order sends, handling requotes and busy servers without doubling up
Posted: Thu Oct 08, 2026 1:52 am
Retry logic for order sends, handling requotes and busy servers without doubling up
sometimes an order send fails because of a requote, a busy server or a brief disconnect. My first version of the EA either gave up on the first failure, so it missed good entries, or it retried blindly, which once led to two positions.
What I do now is check the error code and handle each type separately. For price changed or requote errors, it checks that the setup is still valid and the price hasn't moved too far, and tries again once or twice with a short pause. For a busy server or timeout, it first checks whether the order actually went through, by looking at the open positions and pending orders for that magic number, before retrying. That check is what prevents duplicates.
For errors that mean something is wrong, like not enough margin or invalid stops, it doesn't retry. It logs it and moves on. I also set a maximum number of retries and a maximum time window, since an entry that's a minute late isn't the same trade.
It's not exciting code but it's the part that keeps the EA from doing something silly in poor conditions.
sometimes an order send fails because of a requote, a busy server or a brief disconnect. My first version of the EA either gave up on the first failure, so it missed good entries, or it retried blindly, which once led to two positions.
What I do now is check the error code and handle each type separately. For price changed or requote errors, it checks that the setup is still valid and the price hasn't moved too far, and tries again once or twice with a short pause. For a busy server or timeout, it first checks whether the order actually went through, by looking at the open positions and pending orders for that magic number, before retrying. That check is what prevents duplicates.
For errors that mean something is wrong, like not enough margin or invalid stops, it doesn't retry. It logs it and moves on. I also set a maximum number of retries and a maximum time window, since an entry that's a minute late isn't the same trade.
It's not exciting code but it's the part that keeps the EA from doing something silly in poor conditions.