- OrderClose error 4051
- I do not have the Signals tab on my OANDA MT4. Can anyone help how to activate that?
- How to start with MQL5
OrderSend(Symbol(),OP_BUY,lot,Ask,3,SL,TP,"My Order",Magic,3,Green);
https://docs.mql4.com/constants/errors
ERR_INVALID_FUNCTION_PARAMVALUE 4051 Invalid function parameter value
https://docs.mql4.com/trading/OrderSend
expiration - Order expiration time (for pending orders only).
Highlighted in Red... Expiration could be your problem.
Added: Lot should also be Double_Type.
Excellent. the https://docs.mql4.com/constants/errors is a great help. Your right I changed lot to double type. (A rookie mistake). Now I am stuck on error 130, "ERR_INVALID_STOPS". I have tried both 4 decimal places and 5 decimal places. The current price of EUR/USD is 1.3070. This Stop should work.
Current code.
string buyOrSell = "Buy"; double lot = 1.0; double SL = 1.30400; // Reasonable value double TP = 1.30900; // Reasonable value int Magic = 0; int ticket; int start() { Print("bid: "+Bid); if (buyOrSell=="Buy" ) ticket=OrderSend(Symbol(),OP_BUY,lot,Ask,3,SL,TP,"My Order",Magic,0,Green); if (buyOrSell=="Sell") ticket=OrderSend(Symbol(),OP_SELL,lot,Bid,3,SL,TP,"My Order",Magic,0,Red); if(ticket<0) { Print("OrderSend failed with error: ",GetLastError()); // error 130 return(0); } Print("=== All Done ==="); Print("=== All Done ==="); return(0); }
Yes. That's the answer. For Oanda Set Stop Loss and Take Profit to 0 when doing OrderSend.
Thanks!
Thanks everyone for the help. Here is what I found works with Oanda.
// Code tested good on Oanda Demo account February 2013 string buyOrSell = "Sell"; double lot = 0.1; // Equals 10,000 Units in Oanda double SL = 1.312; // 3 digits works double TP = 1.30800; // 5 digits works int Magic = 070156; // a Magic number works int ticket; int start() { if (buyOrSell=="Buy" ) ticket=OrderSend(Symbol(),OP_BUY,lot,Ask,3,0,0,"My Order",Magic,0,Green); // can not set SL or TP here if (buyOrSell=="Sell") ticket=OrderSend(Symbol(),OP_SELL,lot,Bid,3,0,0,"My Order",Magic,0,Red); // can not set SL or TP here if(ticket<0) { Print("OrderSend failed with error: ",GetLastError()); return(0); } if(ticket>-1) { if(OrderSelect(ticket, SELECT_BY_TICKET)) { OrderModify(ticket,OrderOpenPrice(),SL,TP,0,Orange); // must set SL and TP here through OrderModify } } Print("=== All Done ==="); return(0); }
Thanks everyone for the help. Here is what I found works with Oanda.
You might want to do a little more than this . . .
if(ticket<0) { Print("OrderSend failed with error: ",GetLastError()); return(0); }
. . . all that gives you is the Error code, what other information do you want printed to the log so you can determine the cause of the error ? the order type for example ? what else do you need ? take the opportunity and print it to the log.
You might want to do a little more than this . . .
. . . all that gives you is the Error code, what other information do you want printed to the log so you can determine the cause of the error ? the order type for example ? what else do you need ? take the opportunity and print it to the log.
This sounds like good advice. But I'm stuck 1 step short of this. When I OrderSend from an EA I keep getting the error...
ERR_OBJECT_ALREADY_EXISTS 4200 Object exists already.
And I can't figure out what this means.
And when I OrderSend from a Script there is no error, it works fine.
Two erors I can spot at a first glance;
1. int lot=1.0; (I am sure conversion will take place but you will lose the decimals. So change it to double)
2. expiration in the OrderSend is set to 3 (Is that correct. Usually we set it to 0 when no expiration i needed)
I hope this will help
This sounds like good advice. But I'm stuck 1 step short of this. When I OrderSend from an EA I keep getting the error...
ERR_OBJECT_ALREADY_EXISTS 4200 Object exists already.
And I can't figure out what this means.
And when I OrderSend from a Script there is no error, it works fine.
It's nothing to do with OrderSend() your error reporting is broken . . . and the way you draw Objects is also broken. If an Object already exists how can you create it again ? check first using ObjectFind() if it doesn't exist then create it.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use