Hi all,
I am trying to put together an EA but have a few issues. I can only get the EA to open buy orders. I am unable to placea stoploss due to error 130m so i tried ordermodify. I am new to coding my own ea so I am struggling with this. Can anyone have a look and point out my errors and how to fix them.
Thanks.
Hi.
StopLoss and TakeProfit levels cannot be too close to the market. The minimal distance of stop levels in points can be obtained using the MarketInfo() function with MODE_STOPLEVEL parameter. In the case of erroneous or unnormalized stop levels, the error 130 (ERR_INVALID_STOPS) will be generated.
At placing of a pending order, the open price cannot be too close to the market. The minimal distance of the pending price from the current market one in points can be obtained using the MarketInfo() function with the MODE_STOPLEVEL parameter. In case of false open price of a pending order, the error 130 (ERR_INVALID_STOPS) will be generated.
Applying of pending order expiration time can be disabled in some trade servers. In this case, when a non-zero value is specified in the expiration parameter, the error 147 (ERR_TRADE_EXPIRATION_DENIED) will be generated.
On some trade servers, the total amount of open and pending orders can be limited. If this limit has been exceeded, no new order will be opened (or no pending order will be placed) and trade server will return error 148 (ERR_TRADE_TOO_MANY_ORDERS)
Here is a part of Help guide code:
double minstoplevel=MarketInfo(Symbol(),MODE_STOPLEVEL); Print("Minimum Stop Level=",minstoplevel," points"); double price=Ask; //--- calculated SL and TP prices must be normalized double stoploss=NormalizeDouble(Bid-minstoplevel*Point,Digits); double takeprofit=NormalizeDouble(Bid+minstoplevel*Point,Digits);
ticket=OrderSend(Symbol(), OP_BUY, Lots, Ask, 10, StopLoss, Bid+TakeProfit*Point()); OrderModify ( ticket , 0 , Bid-3*StopLoss*Point, Bid+3*TakeProfit*Point,0);
- If the send fails, how can you modify it? Check your return codes (OrderSend) and find out why.
What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
- Make sure your stops are beyond STOPLEVEL. A 70 point (7 pips on a 5 digit broker) stop on a broker with a 30point/3 pip STOPLEVEL and a 4 pip spread will fail.
- Adjust for 4/5 digit brokers
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi all,
I am trying to put together an EA but have a few issues. I can only get the EA to open buy orders. I am unable to placea stoploss due to error 130m so i tried ordermodify. I am new to coding my own ea so I am struggling with this. Can anyone have a look and point out my errors and how to fix them.
Thanks.