Download MetaTrader 5
To add comments, please log in or register
Find out the latest MQL5.community news!
Mccallum28
243
Mccallum28 2015.07.20 20:34 

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. 

Files:
sig11.mq4 5 kb
Eduard Vavrin
843
Eduard Vavrin 2015.07.21 08:29  
ryangillSL:

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);
whroeder1
13590
whroeder1 2015.07.21 11:47  
ticket=OrderSend(Symbol(), OP_BUY, Lots, Ask, 10, StopLoss, Bid+TakeProfit*Point());

OrderModify ( ticket , 0 , Bid-3*StopLoss*Point, Bid+3*TakeProfit*Point,0);
  1. 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 
  2. 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.
  3. Adjust for 4/5 digit brokers
/
To add comments, please log in or register