Do you update current prices before submitting a trade order?
Yes. In the request I updated the price to market bid price.
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
ArthurEzenwanne # :
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); }
![Documentation on MQL5: Standard Library / Trade Classes / CSymbolInfo / NormalizePrice Documentation on MQL5: Standard Library / Trade Classes / CSymbolInfo / NormalizePrice](https://c.mql5.com/36/55/documentation-on-mql5-standard__8.png)
Documentation on MQL5: Standard Library / Trade Classes / CSymbolInfo / NormalizePrice
- www.mql5.com
NormalizePrice(double) - CSymbolInfo - Trade Classes - Standard Library - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
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
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: