Orderselect always retrun false

Hi…

This is my code, when i test it, its always return false and execute OpenBuy function, why its happened please guide me :-

int TicketNumber = 12345;


int GetTicketNumber (int TicketNumber, string symbol, int timeFrame) {
int isymbol = 0;
if (symbol == “EURUSD”) isymbol = 1;
else if (symbol == “GBPUSD”) isymbol = 2;
else if (symbol == “USDJPY”) isymbol = 3;
else if (symbol == “USDCHF”) isymbol = 4;
else if (symbol == “AUDUSD”) isymbol = 5;
else if (symbol == “USDCAD”) isymbol = 6;
else if (symbol == “EURGBP”) isymbol = 7;
else if (symbol == “EURJPY”) isymbol = 8;
else if (symbol == “EURCHF”) isymbol = 9;
else if (symbol == “EURAUD”) isymbol = 10;
else if (symbol == “EURCAD”) isymbol = 11;
else if (symbol == “GBPUSD”) isymbol = 12;
else if (symbol == “GBPJPY”) isymbol = 13;
else if (symbol == “GBPCHF”) isymbol = 14;
else if (symbol == “GBPAUD”) isymbol = 15;
else if (symbol == “GBPCAD”) isymbol = 16;
else isymbol = 17;

return (TicketNumber + isymbol);
//return (StrToInteger(StringConcatenate(TicketNumber, isymbol, timeFrame)));
}

int init() {
TicketNumber = GetTicketNumber( TicketNumber, Symbol(), Period() );
return (0);
}

void OpenBuy() {
if (MinProfit > 0) {
OrderSend(Symbol(),OP_BUY,lot,Ask,1,0,Ask+MinProfi t*Point,“arnab”,TicketNumber,0,Blue);
} else {
OrderSend(Symbol(),OP_BUY,lot,Ask,1,0,0,“arnab”,Ti cketNumber,0,Blue);
}
}

void CloseSell() {
OrderClose(OrderTicket(), OrderLots(), Bid, 3, Red);
}

void OpenSell() {
if (MinProfit > 0) {
OrderSend(Symbol(),OP_SELL,lot,Bid,1,0,Bid-MinProfit*Point,“arnab”,TicketNumber,0,Red);
} else {
OrderSend(Symbol(),OP_SELL,lot,Bid,1,0,0,“arnab”,T icketNumber,0,Red);
}
}

void CloseBuy() {
OrderClose(OrderTicket(), OrderLots(), Ask, 3, Blue);
}




if (Test > 0) {
Alert("Orderselect: ", (OrderSelect(TicketNumber, SELECT_BY_TICKET)));
if (OrderSelect(TicketNumber, SELECT_BY_TICKET) == true) {
error = GetLastError();
if (error != 0) Alert(“error:”, error);

if (OrderType() == OP_SELL) {
Print ("SELL OrderType: " + OrderType());
CloseSell();
OpenBuy();
}
} else {
OpenBuy();
}
} else {
Alert("Orderselect: ", (OrderSelect(TicketNumber, SELECT_BY_TICKET)));
if (OrderSelect(TicketNumber, SELECT_BY_TICKET) == true) {
error = GetLastError();
if (error != 0) Alert(“error:”, error);

if (OrderType() == OP_BUY) {
CloseBuy();
OpenSell();
}
} else {
OpenSell();
}
}

Thank you

Why did you put the GetLastErrror() function inside the if statement? It should always be called unconditionally. Once you know the error, you can probably figure out what’s going on. It is strange that OrderSelect() would fail. I have only seen it fail due to a cdoing error.