I don't understand something . . . . how can you get the error that relates to the OrderSelect . . . before you perform the OrderSelect ? the first time through the while loop what error does error contain ? what about the last run through the loop ? what if there is an error with the final OrderSelect, how is that captured ?
The OrderSelect will work . . . why shouldn't it ? you can select a closed order just the same way as an open order when you use the ticket number . . . but you may have problems trying to close an order that is already closed.
I think I would do something like this . . . .
while (FileIsEnding(My_FileClose_Handle) == FALSE ) { temp_string = FileReadString(My_FileClose_Handle); i1++; problem_string[i1] =temp_string; problems[i1][0] = StrToInteger( StringSubstr(temp_string,55, 6)); // Magic Number problems[i1][1] = StrToInteger( StringSubstr(temp_string,33, 9)); // Ticket number ticket_nos = StrToInteger( StringSubstr(temp_string,33, 9)); // Ticket number if ( OrderSelect(ticket_nos,SELECT_BY_TICKET) ) { if(!OrderClose(OrderTicket(), OrderLots(), OrderClosePrice() ,My_Slippage,Green)) { error = GetLastError(); Print("OredrClose failed, Order: ", ticket_nos, " Error: ", error ); FileWrite(My_Handle,"IC2 "+" error: "+error+" "+ErrorDescription(error)+" My_FileClose_Handle ="+My_FileClose_Handle+ " problems[i1][1] = "+problems[i1][1]+" problems[i1][0] = "+problems[i1][0]); } FileWrite(My_Handle,"CT ticket_nos = "+ticket_nos); } else { problems[i1][1]=0; error = GetLastError(); Print("OrderSelect failed, Order: ", ticket_nos, " Error: ", error ); FileWrite(My_Handle,"IC2 "+" error: "+error+" "+ErrorDescription(error)+" My_FileClose_Handle ="+My_FileClose_Handle+ " problems[i1][1] = "+problems[i1][1]+" problems[i1][0] = "+problems[i1][0]); FileWrite(My_Handle,"P=0,ticket_nos = "+ticket_nos); } }
I don't understand something . . . . how can you get the error that relates to the OrderSelect . . . before you perform the OrderSelect ? the first time through the while loop what error does error contain ? what about the last run through the loop ? what if there is an error with the final OrderSelect, how is that captured ?
I think I would do something like this . . . .
the extract of results was a just a section - rather than start to finish - sorry if it provided the wrong information.
"....The OrderSelect will work . . . why shouldn't it ? you can select a closed order just the same way as an open order when you use the ticket number . . . but you may have problems trying to close an order that is already closed...."
I hadn't quite realised that -thank you. I have used the following in the past to read my current orders into a matrix:-
for (int i=0; i<OrdersTotal(); i++) // For all orders in the terminal { if((OrderSelect(i, SELECT_BY_POS)==true) && (OrderSymbol()==Symbol()) ) etc.
This only appears to 'list' current orders. If I want to access closed or past orders then I have used:
for (i=0; i< OrdersHistoryTotal(); i++) // For all orders in the terminal { if((OrderSelect(i, SELECT_BY_POS,MODE_HISTORY)==true) && (OrderSymbol()==Symbol()) )
This only appears to 'list' current orders. If I want to access closed or past orders then I have used:
Correct . . . but SELECT_BY_TICKET reads from the trades pool and the history pool . . . SELECT_BY_POS reads from the orders pool by default or the history pool if MODE_HISTORY is specified . . . OrderSelect()
many thanks. It had never been a problem before so the fact I didn't understand correctly had not 'mattered too much"!! Thanks again
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I am using the code below to check a log file. Most of the tickets I would expect to have been closed sometime ago and I would therefore expect the code to take the 'else' route but the FileWrite suggestions otherwise
A section of the output is as below:-
CT ticket_nos = 282712970
IC2 error: 4108 invalid ticket My_FileClose_Handle =2 problems[i1][1] = 282712970 problems[i1][0] = 988519
CT ticket_nos = 282712970
IC2 error: 4108 invalid ticket My_FileClose_Handle =2 problems[i1][1] = 282765112 problems[i1][0] = 156253
CT ticket_nos = 282765112
I figure I am missing the obvious but why does the OrderSelect appear to succeed (goes down the CloseTicket route) and then obviously have an invalid ticket. The alternative route (i.e. the else) doesn't get selected.