OrderModify error 130

 

Hello traders and coders,

I've searched this forum and found that some people have a similar problem...

When my EA tries to set new SL less than 8 pips from current price on EURUSD I get error 130 (SL too close to current price). I can set SL manually as close as 5 pips from current price.


Part of the code concerned:


for (int i=0; i<OrdersTotal(); i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if(OrderType()== OP_BUY && MarketInfo(Symbol(),MODE_ASK)>OrderOpenPrice()+SecureProfitTrig*Point){
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+SecureProfit*Point,OrderTakeProfit(),0,Yellow);



SecureProfitTrig= 80(error 130)/ 90 (works)

SecureProfit=10


my broker is 5 digit

can you help with a word of advice?

Thanks,

Tom

 

double p;

if(digits == 5 || digits == 3)

{

p = Point * 10;

}

else

{

p = Point;

}

The above will adjust the precision used based on what your broker is using. Replace Point with p in your code.

 
fxcourt:

The above will adjust the precision used based on what your broker is using. Replace Point with p in your code.

Hi fxcourt,

Thanks for your reply, but the problem is not in the number of digits used by the broker. If I got the digits wrong I wouldn't be able to set a new SL with OrderModify 8 pips from the price. That is the problem- why OrderModify is able to set new SL 8 pips lower but anything less than 8 pips gets error 130???

Cheers,

Tom

 
ziebol1:

Thanks for your reply, but the problem is not in the number of digits used by the broker. If I got the digits wrong I wouldn't be able to set a new SL with OrderModify 8 pips from the price. That is the problem- why OrderModify is able to set new SL 8 pips lower but anything less than 8 pips gets error 130???

You may need to have a closer look at the existing posts on this forum which you've already searched for - error #130 is one of the most common topics, and there's a wealth of information out there about why it happens and how to solve it.


Summarising that information briefly: you get error 130 if you try to place a pending order too close to the current market price, or if you try to set a t/p or s/l which is too tight - either too close to the market price or to the entry price on a pending order, as applicable. In all cases, "too close" is defined by MarketInfo(Symbol(), MODE_STOPLEVEL). Your 5 pips vs 8 pips query may be due to the fact that you can have a tighter s/l or t/p on a pending order than on an order which has already been filled. On a pending order, the t/p or s/l must be at least MODE_STOPLEVEL from the trigger price. On a filled order, the t/p or s/l must be at least MODE_STOPLEVEL from the price at which the order would currently be closed - i.e. from the bid on a buy order, or the ask on a sell order. In other words, the closest permissible t/p or s/l on a filled order is MODE_STOPLEVEL plus the spread.

 
If you really need such a tight stop you can store the desired price and add some logic that will close the order (using orderclose()) when the price is hit.
 

Thanks guys, problem solved. I've put the difference between BID price (buy order) and MODE_STOPLEVEL as a new SL level. Now my EA modifies orders correctly.

Thanks again,

Tom

Reason: