The partial close bug that kept closing my position until nothing was left
Posted: Thu Oct 08, 2026 1:38 am
The partial close bug that kept closing my position until nothing was left
coded a partial close into my EA: when price reaches a first target, close half and move the stop to breakeven. It worked in testing for most of the trades, but on a live demo I found a position that shrank over a couple of minutes until it was gone.
The cause was simple. My condition was "if price is above the first target, close half". After the first partial, the trade was still above the target, so on the next tick the condition was true again and it closed half of what remained. Then again. It kept going until it hit the minimum lot size.
The fix is to keep track of whether the partial has been done for that specific position. I used the position's ticket and a flag stored in a global variable, so it can only happen once. Another way is to check whether the current volume is still equal to the original volume.
It was a good reminder to test the logic on a demo with a long time frame and look at the journal, not just the equity curve. Edge cases in the order management are where EAs go wrong.
coded a partial close into my EA: when price reaches a first target, close half and move the stop to breakeven. It worked in testing for most of the trades, but on a live demo I found a position that shrank over a couple of minutes until it was gone.
The cause was simple. My condition was "if price is above the first target, close half". After the first partial, the trade was still above the target, so on the next tick the condition was true again and it closed half of what remained. Then again. It kept going until it hit the minimum lot size.
The fix is to keep track of whether the partial has been done for that specific position. I used the position's ticket and a flag stored in a global variable, so it can only happen once. Another way is to check whether the current volume is still equal to the original volume.
It was a good reminder to test the logic on a demo with a long time frame and look at the journal, not just the equity curve. Edge cases in the order management are where EAs go wrong.