Ticket = OrderTicket(); //You MUST select an order before you can use OrderTicket() if(OrderSelect(Ticket,SELECT_BY_TICKET,MODE_TRADES)==true) { Lts = OrderLots(); }
When selecting by ticket, MODE_TRADES is ignored, so you could be selecting an order that has already been closed (hence invalid ticket)
if(OrderCloseTime()!=0) // if order is closed
You must select the order first.
How do you know that it is a buy order?
hello , thank you kindly for your answer. but this cant be the problem. why in Alert it returns the correct ticket number?
and also in my EA Ticket is the global variable of TicketNumber() , and since it is open Ticket works in all the EA. and it becomes zero after the order is closed. so it cant choose an old order ticket.
i have searched for answer for days. it cant be that simple. if you have another idea why it dose not work please tell me.
also for the coders who think i have wright Bid for all close orders, i should say that this is just for closing Buy orders. so it cant be that as well.
hello , thank you kindly for your answer. but this cant be the problem. why in Alert it returns the correct ticket number?
We can only see your code. We do not know from that whether it is the correct ticket or not.
and also in my EA Ticket is the global variable of TicketNumber() , and since it is open Ticket works in all the EA.
What is TicketNumber() ?
In your code Ticket may be a global scope variable, but you possibly assign it a new value.
Ticket = OrderTicket();
As I have already said, you must select an order first. We don't know what the last selected order may be.
and it becomes zero after the order is closed. so it cant choose an old order ticket.
Does it? I don't see that in your code.
if(OrderCloseTime()!=0) // if order is closed OrderCode=0;
You assign zero to a variable named OrderCode, not to Ticket. (As I have already said, you must select the order first.)
i have searched for answer for days. it cant be that simple. if you have another idea why it dose not work please tell me.
Address the issues that I have mentioned first.
ok, i have tested your solution and it took me a while to make sure that it works.
i chose the orderTicket() first and then i put the the OrdrTicket() itself in the OrderClose(). i added a RefreshRates() at the begining of the function.
i also changed the Slippage from 3 to 5. and between 2 times of trying to close an order, i have put a 3 second Sleep() before the RefreshRates().
when i posted this problem, i had 2 issues. errors: invalid Ticket and invalid price.
the results of these changes: it works. your solution fixed the invalid Ticket error and RefreshRates() fixed the invalid Price error.
thank you for your help. i owe you one.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
hello
i have developed an EA that use to work well. but since almost a week ago when it wants to close orders, it gives me invalid Ticket and invalid Price error.
the strange part is that right after the OrderClose a put an Alert to see if the Ticket or the Price is Wrong. but it is right. Alert shows that Ticket and the price is Right !!!
i even put the Second OrderClose after the Alert and RefreshRates so if it dosent close the first time, it closes in the next try. but it gives me the same error and still Alert shows that every value is right!!!
also i use 5 different EAs in the same time on 5 different currency Pairs. but all Variables have different names including the ticket and lot. i am choosing the order by Ticket, not by index so this can not be the problem.
this is the part of my code that has problem: can anyone help me?