error BUYSTOP (130) invalid stops

 

This error 130 is killing me... Does anyone have a clue or experience of the following scenario?

If the OpenPrice is too close to Ask (for a BUYSTOP order) then we should get this error, see https://book.mql4.com/appendix/limits

There it says that for a BUYSTOP order we need : OpenPrice-Ask >= StopLevel. Ok, but now I still get the error although I have moved the OpenPrice away from Ask, at at distance greater than the StopLevel.

See log below. First I detect that the OpenPrice is to close to Ask, then I increase the OpenPrice, then I send the order and get error 130.

16:57:58 2009.09.30 09:00 w key reversal GBPUSD,H1: BUYSTOP INFO: OpenPrice 1.6040 is to close to Ask price 1.6042, OpenPrice-Ask = -0.0002, StopLevel = 0.0008
16:57:58 2009.09.30 09:00 w key reversal GBPUSD,H1: BUYSTOP INFO: 1. OpenPrice has been changed to 1.6041
16:57:58 2009.09.30 09:00 w key reversal GBPUSD,H1: BUYSTOP INFO: 2. OpenPrice has been changed to 1.6042
16:57:58 2009.09.30 09:00 w key reversal GBPUSD,H1: BUYSTOP INFO: 3. OpenPrice has been changed to 1.6043
16:57:58 2009.09.30 09:00 w key reversal GBPUSD,H1: BUYSTOP INFO: 4. OpenPrice has been changed to 1.6044
16:57:58 2009.09.30 09:00 w key reversal GBPUSD,H1: BUYSTOP INFO: 5. OpenPrice has been changed to 1.6045
16:57:58 2009.09.30 09:00 w key reversal GBPUSD,H1: BUYSTOP INFO: 6. OpenPrice has been changed to 1.6046
16:57:58 2009.09.30 09:00 w key reversal GBPUSD,H1: BUYSTOP INFO: 7. OpenPrice has been changed to 1.6047
16:57:58 2009.09.30 09:00 w key reversal GBPUSD,H1: BUYSTOP INFO: 8. OpenPrice has been changed to 1.6048
16:57:58 2009.09.30 09:00 w key reversal GBPUSD,H1: BUYSTOP INFO: 9. OpenPrice has been changed to 1.6049
16:57:58 2009.09.30 09:00 w key reversal GBPUSD,H1: OrderSend error 130
16:57:58 2009.09.30 09:00 w key reversal GBPUSD,H1: error BUYSTOP(130) invalid stops
16:57:58 2009.09.30 09:00 w key reversal GBPUSD,H1: BUYSTOP - sym=GBPUSD cmd=4 lot=0.100000 OpenPrice=1.604900 slip=0 sl=0 tp=0
16:57:58 2009.09.30 09:00 w key reversal GBPUSD,H1: Ask = 1.604210
16:57:58 2009.09.30 09:00 w key reversal GBPUSD,H1: Close[0] = 1.603810
16:57:58 2009.09.30 09:00 w key reversal GBPUSD,H1: STOPLEVEL = 8.000000
16:57:58 2009.09.30 09:00 w key reversal GBPUSD,H1: FREEZELEVEL = 4.000000

Here is the code:

// Check the StopLevel Minimum Distance Limitation ( see https://book.mql4.com/appendix/limits)
// If the OpenPrice is to close to Ask, then adjust the OpenPrice.
if ( !(OpenPrice-Ask >= StopLevel))
{
Print("BUYSTOP INFO: OpenPrice ",DoubleToStr(OpenPrice, Digits), " is to close to Ask price ",DoubleToStr(Ask, Digits), ", OpenPrice-Ask = ", DoubleToStr(OpenPrice-Ask, Digits), ", StopLevel = ",DoubleToStr(StopLevel, Digits));

loopCtr = 1;
while( (!(OpenPrice-Ask >= StopLevel)) && loopCtr<=STOPLEVEL+1 )
{
OpenPrice = OpenPrice + Point;
Print("BUYSTOP INFO: ",loopCtr, ". OpenPrice has been changed to ",DoubleToStr(OpenPrice, Digits));
loopCtr++;
}
}

double stoploss = NormalizeDouble(OpenPrice-SL*Point,Digits);
double takeprofit = NormalizeDouble(OpenPrice+TP*Point,Digits);
datetime expiration = iTime( NULL, PERIOD_H1, 0 ) + 5*3600; // the order shall expire after 5 bars, 5*3600=5*1 hour.
double lot = NormalizeDouble(LOT,2);


ticket=OrderSend( Symbol(), // symbol
OP_BUYSTOP, // cmd
lot, // volume
OpenPrice, // price
0, // slippage
0, // stoploss
0 // takeprofit
);

The stoploss, takeprofit and expiration is given later with OrederModify.

 

You get a 130 error for 3 reasons:

1) Your stops (sl and tp) is too close the the open price when you place a direct trade (OP_BUY or OP_SELL)

2) Your stops are too close the the current price when you are trying to modify an existiing order

3) THIS IS THE ONE THAT IS KILLING YOU, Your open price is too close to the current price when you are placing a pending order.

If you are doing any of the above actions, you should verify that the distance between the current price and your intended target (for stops or entry for pending orders) is bigger than the allowed distance.

The allowed distance is the STOPLEVEL you pointed out in your code above.

goodluck

whocares

 

yes, now I can see the error, it's reson no 3 as you pointed out.

OpenPrice-Ask >= StopLevel

1.6049-1.6042 = 0.0007 and that is less than StopLevel. I have to loop some more in my while-loop.

Thanks!

 

Hi,

I have some issues too...

If i set the stop 0.0020 it works

If i set the stop 20/10000 it wont work...

Im trying to get the stop from a function... and it just wont work...

CODE :

double OpenTradeShort()
{
int res;
double Stop;

//---- go trading only for first tiks of new bar
if(Volume[0]>1) return;

res=OrderSend(Symbol(),OP_SELLSTOP,LotsNormal,Bid-(20/10000),3,Bid+Cover/10000,0,"",MAGICMA,0,Red);


return (Stop);

}
ERROR:

2010.02.25 11:52:18 2006.12.29 21:45 PADE_BW_v4.4.2 EURUSD,M5: OrderSend error 130

Thanks in advance guys!!

Patrick

 

hi guys i have an ea that i have been using for a while now and never had any issues with it but lately i tried using this ea on the spjun10 contract but i always get error 130 even though my stop is more then 50 pips away from the price. here is the error :

2010.05.04 17:25:52 LibOrderReliable_V1_1_4_test SPJUN10,M5: OrderSendReliableMKT v1_1_4:last error: 130:invalid stops
2010.05.04 17:25:52 LibOrderReliable_V1_1_4_test SPJUN10,M5: OrderSendReliableMKT v1_1_4:failed trade: OP_BUY SPJUN10@1169.75000000 tp@1194.75000000 sl@1119.75000000 slippage:100
2010.05.04 17:25:52 LibOrderReliable_V1_1_4_test SPJUN10,M5: OrderSendReliableMKT v1_1_4:failed to execute OP_BUY/OP_SELL, after 0 retries
2010.05.04 17:25:52 LibOrderReliable_V1_1_4_test SPJUN10,M5: OrderSendReliableMKT v1_1_4:non-retryable error: 130:invalid stops
2010.05.04 17:25:52 LibOrderReliable_V1_1_4_test SPJUN10,M5: OrderSendReliableMKT v1_1_4: attempted OP_BUY 0.10000000 lots @1169.75000000 sl:1119.75000000 tp:1194.75000000 slippage:100


can anyone help me i have tried multiple stops and take profit and the only way i got it to trade was to put no sl and tp just a trailing stop.

any insight would help.

 
Reason: