Check for SYMBOL_TRADE_STOPS_LEVEL. It defines the minimum distance to place stop orders. If I'm not mistaken, it should work for placing tp/sl. Also check for SYMBOL_TRADE_FREEZE_LEVEL.

Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties
- www.mql5.com
To obtain the current market information there are several functions: SymbolInfoInteger() , SymbolInfoDouble() and SymbolInfoString() . The first...
Also check freeze level:
if(entry>Bid+SYMBOL_TRADE_FREEZE_LEVEL*_Point) trade.SellLimit(...);
Type of order/position | Activation price | Check |
---|---|---|
Buy Limit order | Ask | Ask-OpenPrice >= SYMBOL_TRADE_FREEZE_LEVEL |
Buy Stop order | Ask | OpenPrice-Ask >= SYMBOL_TRADE_FREEZE_LEVEL |
Sell Limit order | Bid | OpenPrice-Bid >= SYMBOL_TRADE_FREEZE_LEVEL |
Sell Stop order | Bid | Bid-OpenPrice >= SYMBOL_TRADE_FREEZE_LEVEL |
Buy position | Bid | TakeProfit-Bid >= SYMBOL_TRADE_FREEZE_LEVEL Bid-StopLoss >= SYMBOL_TRADE_FREEZE_LEVEL |
Sell position | Ask | Ask-TakeProfit >= SYMBOL_TRADE_FREEZE_LEVEL StopLoss-Ask >= SYMBOL_TRADE_FREEZE_LEVEL |

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 community,
when trying to place a Buy Limit order programmatically, i get error 4765.
It turned out, that the limit price is too close to market.
It seems there is no information about an offset accepted by the broker for such orders.
This is my workaround code, which simply repeatedly steps down the price by 1 point an replaces the order until the specific error disappears.
But i am not happy with that solution for obvious reasons:
alignedBid returns the current bid and UPointOffset is a positive integer as point multiplier. So alignedBid(-x) returns bid - x* Point(). td is of type CTrade. The code works and does the job. But there is no good break condition and it puts some milliseconds on runtime until order placements succeeds. In my tests with Bitcoin on FxPro, it turned out, that an offset of ~ 16000 points was required for the order being accepted and it tooks6 milliseconds in addition.
My questions: Is there a more smarter and safe method to accomplish this?
Thank you