Most frustrating and unexplainable error 130!

 

I am experiencing the most unexplainable and frustrating error 130 - invalid stops when I am testing my EA!

When the EA starts everything goes well - orders are placed without trouble:

07:25:11 2011.05.13 13:21 MartingaleEA EURUSD,M1: open #1 buy stop 2.00 EURUSD at 1.43081 sl: 1.42931 tp: 1.43241 ok
07:25:11 2011.05.13 13:21 MartingaleEA EURUSD,M1: SellTicket is 0
07:25:11 2011.05.13 13:21 MartingaleEA EURUSD,M1: open #2 sell stop 2.00 EURUSD at 1.42771 sl: 1.42931 tp: 1.42621 ok

Further orders are no problem also, for example:

07:38:39 2011.05.13 15:00 MartingaleEA EURUSD,M1: open #4 sell stop 3.85 EURUSD at 1.42771 sl: 1.42931 tp: 1.42621 ok

But then the following happens:

07:42:41 2011.05.13 15:26 MartingaleEA EURUSD,M1: open #5 buy stop 1.97 EURUSD at 1.42924 sl: 1.42774 tp: 1.43084 ok
07:42:41 2011.05.13 15:26 MartingaleEA EURUSD,M1: SellTicket is 0
07:42:41 2011.05.13 15:26 MartingaleEA EURUSD,M1: OrderSend error 130
07:42:41 2011.05.13 15:26 stdlib EURUSD,M1: loaded successfully
07:42:41 2011.05.13 15:26 MartingaleEA EURUSD,M1: Alert: Open Sell Stop Order - Error 130: invalid stops
07:42:41 2011.05.13 15:26 MartingaleEA EURUSD,M1: Lots: 1.9797 Price: 1.4261 Stop: 1.4277 Profit: 1.4246

Suddenly the orders that were no problem before are now not functioning! Check the Stop and Profit. They are correct.

Now in my opinion this is could not be a MarketInfo,MODE_STOPLEVEL problem since I use an ECN broker's data and in any case my stops are calculated at fixed levels and normalized.

Any suggestions?

 

I had a similar problem: https://www.mql5.com/en/forum/134846

I have adjusted my code to use buy and sell with TP and SL set to 0 then modify the order to set the TP and SL afterwards.

The thing you don't seem to show is where current Bid and Ask are, maybe where they are relative to the price you are trying to enter at has some bearing . . .

 
RaptorUK:

I had a similar problem: https://www.mql5.com/en/forum/134846

I have adjusted my code to use buy and sell with TP and SL set to 0 then modify the order to set the TP and SL afterwards.

The thing you don't seem to show is where current Bid and Ask are, maybe where they are relative to the price you are trying to enter at has some bearing . . .


Thanks for that advice and forum reference.

Could it be that the price at which I wanted to open the Sell trade was already lower than the price in my OrderSend and that the whole thing had nothing to do with the stops itself???

 
ernest02:


Could it be that the price at which I wanted to open the Sell trade was already lower than the price in my OrderSend and that the whole thing had nothing to do with the stops itself???

It could be . . . add a Print() to show the Bid and Ask just before the order is sent, maybe add a RefreshRates() just to be sure . . . retest, then you will know. If this was done using the Strategy Tester you can test the exact same currency and date range and look for the exact same trade . . .
 
RaptorUK:
It could be . . . add a Print() to show the Bid and Ask just before the order is sent, maybe add a RefreshRates() just to be sure . . . retest, then you will know. If this was done using the Strategy Tester you can test the exact same currency and date range and look for the exact same trade . . .


I have now run the EA again and find that the SellPrice = Current Bid Price. (stdlib only shows the prices up to the 4th decimal although i use 5 decimal prices) This is a coincidence since I dtermine SellPrice at the start of the program at a fixed level.

This what I get from the tester journal at the moment:

11:17:42 2011.05.13 15:26 MartingaleEA EURUSD,M1: SellTicket is 0
11:17:42 2011.05.13 15:26 MartingaleEA EURUSD,M1: SellPrice is 1.4261
11:17:42 2011.05.13 15:26 MartingaleEA EURUSD,M1: OrderSend error 130
11:17:42 2011.05.13 15:26 stdlib EURUSD,M1: loaded successfully
11:17:42 2011.05.13 15:26 MartingaleEA EURUSD,M1: Alert: Open Sell Stop Order - Error 130: invalid stops
11:17:42 2011.05.13 15:26 MartingaleEA EURUSD,M1: Price: 1.4261 Lots: 1.9797 SellPrice: 1.4261 Stop: 1.4277 Profit: 1.4246
11:17:42 2011.05.13 15:26 MartingaleEA EURUSD,M1: SellTicket2 is -1

When the tester reports a successful transaction it uses 5 decimal prices in the report. Does it mean anything that in the Print SellPrice and in the error report (stdlib) it reports only 4 decimals?

 

Print() does this . . . "Data of double type are printed with 4 decimal digits after point." https://docs.mql4.com/common/Print but you can get round that limitation very easily . . . use a string instead of a double

if (D1) Print("RefreshRates: Bid= ",DoubleToStr(Bid,5)," Ask= ",DoubleToStr(Ask,5) );
I think you are too close to the current price to use a pending order . . .
 
RaptorUK:

Print() does this . . . "Data of double type are printed with 4 decimal digits after point." https://docs.mql4.com/common/Print but you can get round that limitation very easily . . . use a string instead of a double

I think you are too close to the current price to use a pending order . . .


I now have the 5 decimal prices and it appears that the OrderSend SellPrice is 0.00004 (4 points) higher than the Bid price.

13:35:37 2011.05.13 15:26 MartingaleEA EURUSD,M1: RefreshRates: Bid= 1.42610 Ask= 1.42619
13:35:37 2011.05.13 15:26 MartingaleEA EURUSD,M1: DLevel = 1.42614 (Pending SellPrice)

This means that the actual price is already lower than the pending price and must be the reason that I get error 130 - invalid stops. Do you agree?

(Just for information: My ECN broker allows zero (0) pips difference between Pending and Actual price for a transaction to take place.)

 
ernest02:


I now have the 5 decimal prices and it appears that the OrderSend SellPrice is 0.00004 (4 points) higher than the Bid price.

13:35:37 2011.05.13 15:26 MartingaleEA EURUSD,M1: RefreshRates: Bid= 1.42610 Ask= 1.42619
13:35:37 2011.05.13 15:26 MartingaleEA EURUSD,M1: DLevel = 1.42614 (Pending SellPrice)

This means that the actual price is already lower than the pending price and must be the reason that I get error 130 - invalid stops. Do you agree?

(Just for information: My ECN broker allows zero (0) pips difference between Pending and Actual price for a transaction to take place.)

My broker is the same . . . the question is does the Strategy Tester faithfully reproduce this behaviour ? it has access to the MarketInfo that you and I also have access to from our Brokers . . . does this mean that it will behave as our Brokers do ? I hope so but I do not know that it does with 100% certainty.

Looking at your trade, I assume it was a SellStop ? yes I agree, if the current bid is already below the price you are trying to place your order at then it may well be the reason for your error 130. You can test this though by hard coding your price to a little above Bid then test again . . . . and then to a little below Bid and test again . . . see if your 130 isn't generated when the order price is below Bid.

(You may have identified the reason for my issues too . . will have to go back and look at the info I posted in my thread . . :-) )

 
ernest02:
This means that the actual price is already lower than the pending price and must be the reason that I get error 130 - invalid stops.
You can not open a pending order closer to market than MarketInfo(Symbol(), MODE_STOPLEVEL)*Point. (3 pips/30 points on IBFX)
 
WHRoeder:
You can not open a pending order closer to market than MarketInfo(Symbol(), MODE_STOPLEVEL)*Point. (3 pips/30 points on IBFX)

My ECN broker allows zero (0) difference in actual and pending price. I have done many transactions where the price was
less than one pip away from my transaction price, so I assume his MarketInfo(Symbol(),MODE_STOPLEVEL == 0.
RaptorUK:

My broker is the same . . . the question is does the Strategy Tester faithfully reproduce this behaviour ? it has access to the MarketInfo that you and I also have access to from our Brokers . . . does this mean that it will behave as our Brokers do ? I hope so but I do not know that it does with 100% certainty.

Looking at your trade, I assume it was a SellStop ? yes I agree, if the current bid is already below the price you are trying to place your order at then it may well be the reason for your error 130. You can test this though by hard coding your price to a little above Bid then test again . . . . and then to a little below Bid and test again . . . see if your 130 isn't generated when the order price is below Bid.

(You may have identified the reason for my issues too . . will have to go back and look at the info I posted in my thread . . :-) )

I have found a simple solution - but i don't think it is infallible - and that is to set SellTicket == -1 back to SellTicket = 0 in my Error code. The next iteration the order is placed succsessfully. Naughty I suppose but it works for some reason or other!
 
Im also facing exactly same proble. Plz! help me