fail to open order

 

Ok. Here is problem. Just got home and see this stranger fail on my EA which make me didn't take 30 pips profit.

 

My EA return the order fail to open because of 130 error. yes, I know 130 error is invalid stoploss.

I'm not sure why it is invalid. I set a buy order and the stoploss is lower than open price 30 pips. That is not all about it. I check the ticket number of that fail order. it has the same exactly with my recent close ticket number? Is that possible to have the new ticket order number the same exactly the close one?

 


and this is my order command

extern double pipValue = 0.01;

extern double stopLoss = 30;
extern double takeProfit = 90; 

extern double lots = 0.01; 

OrderSend(Symbol(),OP_BUY,lots,Ask,30,Ask-stopLoss*pipValue,Ask+takeProfit*pipValue,"EA_v3",12345,0,Green) 

 

Can anyone see where the error come from?  

Thank you. 

 

shonick
:

Ok. Here is problem. Just got home and see this stranger fail on my EA which make me didn't take 30 pips profit.

 

My EA return the order fail to open because of 130 error. yes, I know 130 error is invalid stoploss.

I'm not sure why it is invalid. I set a buy order and the stoploss is lower than open price 30 pips. That is not all about it. I check the ticket number of that fail order. it has the same exactly with my recent close ticket number? Is that possible to have the new ticket order number the same exactly the close one?

 


and this is my order command

extern double pipValue = 0.01;

extern double stopLoss = 30;
extern double takeProfit = 90; 

extern double lots = 0.01; 

OrderSend(Symbol(),OP_BUY,lots,Ask,30,Ask-stopLoss*pipValue,Ask+takeProfit*pipValue,"EA_v3",12345,0,Green) 

 

Can anyone see where the error come from?  

Thank you. 

 

 

The "new" ticket order number can't same as your old ticket order, you can use your magic number "12345" to assign for your EA.

Your order command is OK, the problem is your pipValue, stopLoss and takeProfit.

stopLoss = 30, pipValue = 0.01, with equation Ask-stopLoss*pipValue  = (Ask-30*0.01), your stoploss must either 0.0030 or you need to add 4/5 digit Broker Code

 
FXEWEN:

The "new" ticket order number can't same as your old ticket order, you can use your magic number "12345" to assign for your EA.

Your order command is OK, the problem is your pipValue, stopLoss and takeProfit.

stopLoss = 30, pipValue = 0.01, with equation Ask-stopLoss*pipValue  = (Ask-30*0.01), your stoploss must either 0.0030 or you need to add 4/5 digit Broker Code

 



This is for JPY pair, which mean pip unit is 0.01, not 0.0001.

 I thought the ticket number is returned from server, isn't it? How come the server made that error and generate the same ticket number of my last manual trading for my new trade?

And this is 5 digits broker, so I put 30 as slippage for 3 pips slippage. 

 
  1. If it failed to open, then there is no ticket number. But how do you know it's 130? You never check your return codes. What are Function return values ? How do I use them ? - MQL4 forum
  2. Your code fails if you ever move it to a non-jpy pair or to metals. Why not auto-adjust?
  3. Perhaps your broker switching to ECN where you must open first and then set stops.
//++++ These are adjusted for 5 digit brokers.
int      pips2points;                  // slippage  3 pips  3=points 30=points
double   pips2dbl;                     // Stoploss 15 pips  0.0015   0.00150
int      Digits.pips;                  // DoubleToStr(dbl/pips2dbl, Digits.pips)
int      init(){                                            OptInitialization();
    if(Digits % 2 == 1){   // DE30=1/JPY=3/EURUSD=5 forum.mql4.com/43064#515262
            pips2dbl = Point*10;    pips2points = 10;    Digits.pips = 1;
   } else { pips2dbl = Point;       pips2points =  1;    Digits.pips = 0;     }
   // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
//---- These are adjusted for 5 digit brokers.
   //{On ECN brokers you must open first and THEN set stops
   // int      ticket = OrderSend(..., 0,0,...)
   // if(ticket < 0)
   //    Alert("OrderSend failed: ", GetLastError());
   // else  if(!OrderSelect(ticket, SELECT_BY_TICKET))
   //    Alert("OrderSelect failed: ", GetLastError());
   // else  if(!OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0))
   //    Alert("OrderModify failed: ", GetLastError());
   //}
 
WHRoeder:
  1. If it failed to open, then there is no ticket number. But how do you know it's 130? You never check your return codes. What are Function return values ? How do I use them ? - MQL4 forum
  2. Your code fails if you ever move it to a non-jpy pair or to metals. Why not auto-adjust?
  3. Perhaps your broker switching to ECN where you must open first and then set stops.



Wow, 3 is the explanation for my problem. I was testing my code with none ECN, and use it on Oanda, and I believe it is ECN. I didnt know that I have to open first then set stoploss and take profit. I just check and even doing it manually, I still have to do it the same way.

1. I know it is 130 because that is the error I got from GetlastError()

2. I adjust it manual for now when I understand more built-in function, i will modify the code :) 

 

Thank you