Trade Failed Due to retcode: 10009, with comment: Request executed
Found the culprit:
"volume": (trade.volume/2), #close half of the position
So some of the trade volume returns float values with like 3 or more decimal places. But the volume for my broker is to a max of 2 decimal places.
I've modified it and the problem went away.
Thanks for your help @Valdimir
Found the culprit:
So some of the trade volume returns float values with like 3 or more decimal places. But the volume for my broker is to a max of 2 decimal places.
I've modified it and the problem went away.
Thanks for your help @Valdimir
In MQL5 I use trading classes. In particular, I normalize Stop Loss and Take Profit with CSymbolInfo::NormalizePrice, and for volume normalization I use the following function:
//+------------------------------------------------------------------+ //| Lot Check | //+------------------------------------------------------------------+ double LotCheck(double lots,CSymbolInfo &symbol) { //--- calculate maximum volume double volume=NormalizeDouble(lots,2); double stepvol=symbol.LotsStep(); if(stepvol>0.0) volume=stepvol*MathFloor(volume/stepvol); //--- double minvol=symbol.LotsMin(); if(volume<minvol) volume=0.0; //--- double maxvol=symbol.LotsMax(); if(volume>maxvol) volume=maxvol; //--- return(volume); }
- www.mql5.com
Hello,
I am writing an EA using the MT5 Python library (https://www.mql5.com/en/docs/integration/python_metatrader5)
I have a working EA, however some of my trades do not close. It usually fails with the comment "Trade Failed Due to retcode: 10009, with comment: Request executed". This usually happens (maybe 1 in 4 tries) when I try close out half of the position.
Has anyone experienced such issues and can I know how it was resolved?
Thanks in advance!
Snippet: