Error when placing two pending CFD orders

 

Hi coders,

I always receive an error #130 when I place two pending CFD orders. Placing two forex orders is no problem. But when I want to trade oil, gold, dax, s&p (anything where MODE_PROFITCALCMODE = 1) only one order is sent and for the second order I receive error #130. But WHY?? I don't change the Stoploss before sending the second order. So how can it be that the Stop is ok when sending the first order but not with the second?

Ticket1 = OrderSend(NULL,Order_Type,lotSize,Entry,3,SL,TP1,"",0,0,CLR_NONE);
if (TwoOrders) Ticket2 = OrderSend(NULL,Order_Type,lotSize,Entry,3,SL,TP2,"",0,0,CLR_NONE);
if(Ticket1 < 0) {
   Alert("OrderSend #1 failed with error #",GetLastError());
   Print("OrderSend #1 failed with error #",GetLastError());
}
else {
   Print("Order #1 sent successfully");
}
if (TwoOrders) {
   if(Ticket2 < 0) {
      Alert("OrderSend #2 failed with error #",GetLastError());
      Print("OrderSend #2 failed with error #",GetLastError());
   }
   else {
      Print("Order #2 sent successfully");
   }
}
 
hmm - just read the Book (top of this page), especially this!
 

Gooly, I don't see an error in the code. Additionally it works perfect when placing a forex order and the first CFD order. The error #130 only occurs when sending the second CFD order. I don't find anything in my code what could cause that error. As you can see, I place the second order immediately after the first without changing the SL. Therefore I am sure it must be some MT4-CFD-problem. Forex orders work without problems.

Very strange, isn't it? 

 
I just added a line which prints the SL for the second order and I tested it with the Dax30. Everything was correct, the same SL like in the first order. So error #130 is definitely not true. The SL is not invalid. I really reckon that there is a bug in the Metatrader itself.
 
Edit: I placed a lot of pending orders to test everything and unfortunately I noticed that it can also cause problems when placing a forex order. Same issue. Error #130. What's happening here? The values are correct, sometimes it works, sometimes not. ?!?!?
 
Ticket1 = OrderSend(NULL,Order_Type,lotSize,Entry,3,SL,TP1,"",0,0,CLR_NONE);
if (TwoOrders) Ticket2 = OrderSend(NULL,Order_Type,lotSize,Entry,3,SL,TP2,"",0,0,CLR_NONE);
if(Ticket1 < 0) {
   Alert("OrderSend #1 failed with error #",GetLastError());
  1. If the first send fails, you've lost GetLastError because of the second call. Process errors immediately. 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. The only difference between the two is TP1 and TP2 and you didn't bother to show them. Print the values - find out why.
 

William, as usual, you are genius! TP2 was the problem. In a calculation I used a minus instead of a plus. That caused all problems. But how can it be that a wrong TP cause an invalid stop error?

Thank you so much!

 
mar:

William, as usual, you are genius! TP2 was the problem. In a calculation I used a minus instead of a plus. That caused all problems. But how can it be that a wrong TP cause an invalid stop error?

Thank you so much!

You misinterpreted error 130, it's not about stoploss, but about stops : "Invalid stops". TP is a stop order.

 
Ok, that makes sense to me. Thank you!
 
angevoyageur:

TP is a stop order.

( A t/p is more usually regarded as a limit order. If you sell at 1.00 with a s/l at 1.1 and a t/p at 0.9, then it's equivalent to a buy-stop at 1.1 and a buy-limit at 0.9. In a platform such as Ninjatrader, which doesn't have an MT4-style s/l or t/p as an "attribute" of a position, you would create pending stop and limit orders and bind them together in an OCO group. )
 
jjc:
( A t/p is more usually regarded as a limit order. If you sell at 1.00 with a s/l at 1.1 and a t/p at 0.9, then it's equivalent to a buy-stop at 1.1 and a buy-limit at 0.9. In a platform such as Ninjatrader, which doesn't have an MT4-style s/l or t/p as an "attribute" of a position, you would create pending stop and limit orders and bind them together in an OCO group. )

You are right, I should have said : TP is a stop value (like SL and so subject to error 130). It's MT4 terminology.

Reason: