Invalid stops error 130

 

I have been using XM brokers and appear to get Invalid Stops occurring more often tyhan elsewhere but in any event don't quite understand what factors can lead to this error 

I read the following with WHRoeder's comments - interesting but don't don't think they apply to my circumstances 

https://www.mql5.com/en/forum/157900

 

The following is from my own log file showing a StopLoss of 0 and a TakeProfit 150 points from the OpenPrice  (OP)  - Option 1 fails Option 2 Fails.

(Just noticed my Magic # appears -ve - must check but doesn't appear to be the problem)

 OPTION 1

2017.01.11 13:52:40 EURNZD 66625 LTC Trade_Flag = UP OP = 1.50181 MyTP = 1.50331 MySL = 0.00000, My_Trading_Lots = 0.01 SL pts = 0.01273 TP pts = 0.00150

2017.01.11 13:52:40 EURNZD 50010 OBS UP TradeAllowed = 1

2017.01.11 13:52:40 EURNZD 50020 OBS My_OrderSymbol = EURNZD ASK  = 1.50252 BID  = 1.50181 BUYorSELL = UP My_Trading_Lots = 0.01 My_Slippage = 40 My_TakeProfit = 1.50331 My_StopLoss= 0.00000 My_Comment = FSC.14.13.34.40 My_Magic_Nos = -1473588448

2017.01.11 13:52:40 EURNZD 50021 OBS Ticket = -1

2017.01.11 13:52:40 EURNZD >>>>>>>>>>>.... 50010D BUYorSELL  My_error: 130 invalid stops

2017.01.11 13:52:40 EURNZD 50021 OBS Ticket = -1

Simialar log where using the same EA works

  OPTION 2

2017.01.11 13:45:02 USDCHF 66625 LTC Trade_Flag = DN OP = 1.02058 MyTP = 1.01908 MySL = 0.00000, My_Trading_Lots = 0.01 SL pts = 0.00520 TP pts = 0.00150

2017.01.11 13:45:02 USDCHF 50010 OBS DN TradeAllowed = 1

2017.01.11 13:45:02 USDCHF 50020 OBS My_OrderSymbol = USDCHF ASK  = 1.02058 BID  = 1.02035 BUYorSELL = DN My_Trading_Lots = 0.01 My_Slippage = 40 My_TakeProfit = 1.01908 My_StopLoss= 0.00000 My_Comment = FSC.27.13.34_.2 My_Magic_Nos = -173588486

2017.01.11 13:45:02 USDCHF 50021 OBS Ticket = 113085977

2017.01.11 13:45:02 USDCHF 50027 OBS Created Ticket = 113085977, OP = 1.02035 Magic = -173588486, MyTP = 1.01908, MySL = 0.00000

2017.01.11 13:45:02 USDCHF 50028 OBS Margin_Used  = 7.61

2017.01.11 13:45:02 USDCHF 50021 OBS Ticket = 113085977 

 any help appreciated

Error 130 : invalid stops
Error 130 : invalid stops
  • www.mql5.com
I get the 130 error from time to time and i cannot figure out why this happens. I place two pending trades - a Buy stop and a Sell stop...
 
any code appreciated
 
Without the code it's impossible to help. We are not soothsayers. Regards.
 
peterhw: https://www.mql5.com/en/forum/157900
Please use the link button (control-K.) for links Use
the link button See the difference: https://www.mql5.com/en/forum/157900
 
Marco vd Heijden:
any code appreciated
   if( BUYorSELL == "DN" ) My_Ticket = OrderSend(My_OrderSymbol,  OP_SELL,       My_Trading_Lots,  MarketInfo(My_OrderSymbol,MODE_BID), My_Slippage,
                                                 My_StopLoss,     My_TakeProfit, My_Comment ,      My_Magic_Nos,  0, CLR_NONE); //CLR_NONE instaed  of colour
   if( BUYorSELL == "UP" ) My_Ticket = OrderSend(My_OrderSymbol,  OP_BUY ,       My_Trading_Lots,  MarketInfo(My_OrderSymbol,MODE_ASK), My_Slippage,
                                                 My_StopLoss,     My_TakeProfit, My_Comment ,      My_Magic_Nos,  0, CLR_NONE);
   FileWrite(My_Handle,MyDT+"50021 OBS Ticket = "+IntegerToString(My_Ticket));
   if (My_Ticket <=0 ) Write_my_Error("50010D BUYorSELL ");

Thanks Marco,

This is the code and haven't seen this error code for a long time (when the S/L & T/P were really wrong) .  

I have only seen this with XM

In th examples above the Takeprofit is 150 points and StopLoss 0  for both.  

(I put the S/L as zero in attempt to locate the problem).

With zero s/l and T/P 150 points I wouldn't envisage SPREAD being a problem 

 

What a piece of junk !

if(BUYorSELL=="DN")
  {
   Print("DN ",
         " Lots: ",DoubleToString(My_Trading_Lots),
         " Symbol: ",My_OrderSymbol,
         " SL: ",DoubleToString(My_StopLoss),
         " TP: ",DoubleToString(My_TakeProfit));
  }


And incomplete as well you are not showing where these values come from.

 
Marco vd Heijden:

What a piece of junk !

if(BUYorSELL=="DN")
  {
   Print("DN ",
         " Lots: ",DoubleToString(My_Trading_Lots),
         " Symbol: ",My_OrderSymbol,
         " SL: ",DoubleToString(My_StopLoss),
         " TP: ",DoubleToString(My_TakeProfit));
  }


And incomplete as well you are not showing where these values come from.

Fine - if you don't like it but no need to be insulting.

How about we answer the question - if you wish - rather than throw insults.  I do appreciate you guys help of your own accord but I have been coding in my own way for years trying to pick up the best when I can and I am happy that the code normally works fine.

I'm happy with the values and how they are calculated but one example fails with incorrect STOPS and another just a few minutes later does not.

 
peterhw:

Fine - if you don't like it but no need to be insulting.

How about we answer the question - if you wish - rather than throw insults.  

Marco has posted code to add to yours (for fault finding) not to replace yours. Once you have printed those values, it may become obvious where your problem is.

You might also want to check your broker's stop level:

Print(SymbolInfoInteger(_Symbol,SYMBOL_TRADE_STOPS_LEVEL));
 
peterhw:

Fine - if you don't like it but no need to be insulting.

How about we answer the question - if you wish - rather than throw insults.  I do appreciate you guys help of your own accord but I have been coding in my own way for years trying to pick up the best when I can and I am happy that the code normally works fine.

I'm happy with the values and how they are calculated but one example fails with incorrect STOPS and another just a few minutes later does not.

How are we able to help if you post incomplete code and do not show how these values are calculated ?

That's like going to a garage with only your spare tire and asking them to fix your car. 

 
Marco vd Heijden:

How are we able to help if you post incomplete code and do not show how these values are calculated ?

That's like going to a garage with only your spare tire and asking them to fix your car. 

Exactly, that's not the first time, with exact same code snippet.

And you don't have follow people advice, it's all there already :

Forum on trading, automated trading systems and testing trading strategies

Error 130 : invalid stops

whroeder1, 2016.01.04 12:51

  1. When I tried stops, I couldn't get them to work. I think it was comparing current market to the TP/SL. Perhaps that problem is back; try setting the pending first and then set the stops.
  2. There is no reason to use pending orders in a EA. Humans can't look at the market continuously, EAs can. Just wait until the market reaches your price.
Fix your code. And if you cant post ALL the relevant code.
 
honest_knave:

Marco has posted code to add to yours (for fault finding) not to replace yours. Once you have printed those values, it may become obvious where your problem is.

You might also want to check your broker's stop level:

Print(SymbolInfoInteger(_Symbol,SYMBOL_TRADE_STOPS_LEVEL));

Thanks for the response

I do write them to my own log file with results as above ( I don't believe where they are written to changes the results or problem):-

2017.01.11 13:45:02 USDCHF 50020 OBS My_OrderSymbol = USDCHF ASK  = 1.02058 BID  = 1.02035 BUYorSELL = DN My_Trading_Lots = 0.01 My_Slippage = 40 My_TakeProfit = 1.01908 My_StopLoss= 0.00000 My_Comment = FSC.27.13.34_.2 My_Magic_Nos = -173588486

I just happen to write the details to my own log rather using the PRINT statement 

The error refers to invalid stops which I understand to mean the STOPLOSS & TAKEPROFIT figures. The STOPLOSS in all cases is ZERO (used to try track the other problem / snippet Alain refers to). The Takeprofit is 150 points in all cases and I suspect your suggestion WRT the stop level is a possible answer

The following is taken from the JOURNAL at another time

 

0 00:15:11.250 '8108742': order sell market 0.01 GBPCAD sl: 0.00000 tp: 1.61267

1 00:15:11.377 '8108742': order sell 0.01 GBPCAD opening at market sl: 0.00000 tp: 1.61267 failed [Invalid S/L or T/P]

0 00:15:11.377 '8108742': order sell market 0.01 GBPCHF sl: 0.00000 tp: 1.23777

1 00:15:11.505 '8108742': order sell 0.01 GBPCHF opening at market sl: 0.00000 tp: 1.23777 failed [Invalid S/L or T/P]

0 00:15:11.507 '8108742': order sell market 0.01 GBPUSD sl: 0.00000 tp: 1.21779

0 00:15:11.671 '8108742': order was opened : #112910659 sell 0.01 GBPUSD at 1.21904 sl: 0.00000 tp: 1.21779 

The failures occur where the STOPLEVELS are Higher.  The attached shows a table I created and using with XM broker and shows some high STOPLEVELS (all figures are points based)

 

Again Alain's response refers to me to WHRoeders previous post - I already referred to that and  believe I understand the content

 

Marco 

That's like going to a garage with only your spare tire and asking them to fix your car." - I disagree it's more like going to the garage and asking them to figure out what's wrong with the tyre that I know is faulty.

If they fix the tyre and the same problem occurs then my fault and probably need to look deeper at what is causing the problem.  honest_knave 's suggestion seems most relevant

Apologies but the way the figures are calculated appears irrelevant to me at the moment - unless there is some hidden meaning behind the error message.

 

 Thanks everyone for contributions

Reason: