Replace
ticket = OrderModify(i-1, OrderOpenPrice(), nsl, OrderTakeProfit(), 0, CLR_NONE);
to
ticket = OrderModify(OrderTicket(), OrderOpenPrice(), nsl, OrderTakeProfit(), 0, CLR_NONE);
Roger,
This is OK, SELECT_BY_POS is working with positions (1,2,3,...).
When Orderselect works with tickets (SELECT_BY_TICKET), then you are right.
Jose
Your OrderModify() call is up the left.
OrderModify() does not return a ticket number as you seem to expect in your code. It returns a success or failure.
And the first parameter you supply to the OrderModify() should be the ticket you retrieved from the OrderSelect() - not a position number.
CB
This has no influence en the result of the command itself.
As you can see, the following line is ticket < 1, only works to control error (it happens).
So I am not expecting a ticket, (lets say was a fast translation), but I am waiting a error code, no a ticket.
Your OrderModify() call is up the left.
OrderModify() does not return a ticket number as you seem to expect in your code. It returns a success or failure.
And the first parameter you supply to the OrderModify() should be the ticket you retrieved from the OrderSelect() - not a position number.
CB
Thanks, It was a stupid one.
Issue solved.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I got a trailing routing that produce these two errors: 4108 and 4051.
I revise the code but I can not find the bug.
- Revision of open trades goes from OrdersTotal() parameter to 1. With 3 orders, produce 3, 2, 1.
- OrderSelect is also decrese by 1. so i get 2, 1, 0
But the log show messages like:
2009.11.06 00:28:49 RAT_PT EURCAD,H1: invalid ticket for OrderModify function
2009.11.06 00:29:04 RAT_PT EURCAD,H1: error:4051
Also error 4108
It seems that the routime doesn't select the orders properly but I don't see why?
Could someone help me?
Thanks!
total = OrdersTotal();
// trailing routine
for(i=total;i>=1;i--) {
OrderSelect(i-1, SELECT_BY_POS);
if (trailing == true && OrderSymbol() == Symbol()) {
if (OrderType() == OP_BUY) {
if ((Ask - OrderStopLoss()) > gap1) {
nsl = NormalizeDouble(OrderStopLoss() + (Ask - OrderStopLoss()) * (inc / 100), Digits);
ticket = OrderModify(i-1, OrderOpenPrice(), nsl, OrderTakeProfit(), 0, CLR_NONE);
if (ticket<1) Print("error:",GetLastError());
}
}
if (OrderType() == OP_SELL) {
if ((OrderStopLoss() - Bid) > gap1) {
//if (order
nsl = NormalizeDouble(OrderStopLoss() - (OrderStopLoss() - Bid) * (inc / 100), Digits);
ticket = OrderModify(i-1, OrderOpenPrice(), nsl, OrderTakeProfit(), 0, CLR_NONE);
if (ticket<1) Print("error:",GetLastError());
}
}
}
}