Reputation: 8791
I'm trying to modify an Order, but I always get Error #1
.
From my research, I have discovered that error 1 means I have input parameter in a wrong way. How can I fix my OrderModify()
function?
stoploss = NormalizeDouble(Ask - Point * TrailingStop,Digits);
int ticket;
takeprofit = NormalizeDouble(Ask + Point * TrailingStopTP,Digits);
double minstoplevel = MarketInfo( Symbol(), MODE_STOPLEVEL );
if(stoploss > NormalizeDouble(Ask - Point*minstoplevel,Digits)) {
stoploss = NormalizeDouble(Ask - Point*minstoplevel,Digits);
}
if(takeprofit < NormalizeDouble( Ask + Point*minstoplevel2, Digits )) {
takeprofit = NormalizeDouble( Ask + Point*minstoplevel2, Digits );
}
if(AccountFreeMarginCheck(Symbol(),OP_SELL,lotsize)>0) {
ticket=OrderSend(Symbol(),OP_BUY,lotsize,Ask, 0, 0.0, 0.0, "comment", MagicNumber, 0, Lime);
if(ticket<0) {
Print("Order send failed with error #",GetLastError());
} else {
Print("Order send sucesso!! Ticket#", ticket);
res=OrderModify(ticket,OrderOpenPrice(),stoploss,takeprofit,0,Blue);
if(res==false) {
Print("Error modifying order!, error#",GetLastError());
} else {
Print("Order modified successfully, res#", res);
}
}
} else {
Print("Sem dinheiro na conta D=");
}
}
Upvotes: 2
Views: 10538
Reputation: 31
The problem is that even though the entry price, stoploss, and take profit parameters to the OrderModify()
call appear to be the same, they likely differ by a fraction of a unit ( smaller than "Digits" ).
To fix this,
simply normalize the parameters to make sure they are a maximum of Digits
decimal places long.
double entryPrice = NormalizeDouble( entryPrice, Digits );
double stoploss = NormalizeDouble( stoploss, Digits );
double target = NormalizeDouble( target, Digits );
Then pass them into the OrderModify()
call.
Upvotes: 3
Reputation: 1
OrderModify()
legally sets _LastError == 1
There might be a bit surprise, but OrderModify()
has an obligation to signal _LastError == 1
in case, the call was both syntactically and semantically correct, however, the values supplied for modification(s) were actually the very same, as the identified ticket#
has already had in database.
This means, there was nothing to modify, as all the attributes already had the "quasi-new" target value(s).
One may pre-check all fields for a potential identity, which might allow our code to skip the OrderModify()
call in this very case of an identity-of-{ current | target } values.
ERR_NO_RESULT == 1 // No error returned, but the result is unknown
GetLastError()
- returns a last generated error-code. The same value is available via a system variable named _LastError
. It's value can be reset before a critical activity to zero by calling ResetLastError()
.
Error codes are defined in stderror.mqh
.
To print the error description you can use the ErrorDescription()
function, defined in stdlib.mqh
file
#include <stderror.mqh>
#include <stdlib.mqh>
Upvotes: 4