set it to true, not false
then
{
//Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );
Sleep(0);
}
un-comment the alert so that you can see what the error is.
Sleep(0) does nothing.
use OrderClosePrice()
set it to true, not false
then
{
//Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );
Sleep(0);
}
un-comment the alert so that you can see what the error is.
Sleep(0) does nothing.
use OrderClosePrice()
Thank you for your help.
I tried to simplify things just to close the trade and did try your advice.
But, doesn't seems to work.
result = OrderClose(44407768,1,Ask,3,Red);
Alert(result);
return(0);
Alert return always return 0 regardless I changed to true or false.
As I did not set any condition, I expect it to close the trade that is running with the ticket number 44407768.
Any advice is appreciated.
Thank you for your help.
I tried to simplify things just to close the trade and did try your advice.
But, doesn't seems to work.
result = OrderClose(44407768,1,Ask,3,Red);
Alert(result);
return(0);
Alert return always return 0 regardless I changed to true or false.
As I did not set any condition, I expect it to close the trade that is running with the ticket number 44407768.
Any advice is appreciated.
- 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 All,
I did checked forum example and also this https://docs.mql4.com/trading/orderclose.
But, it doesn't close any of the open trade.
The first code I uses, it return a warning as "return value of 'OrderClose' should be checked"
So, I uses this. But, it doesn't close the trade.
{
int total = OrdersTotal();
for(int i=total-1;i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS);
int type = OrderType();
bool result = false;
switch(type)
{
//Close opened long positions
case OP_BUY : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
break;
//Close opened short positions
case OP_SELL : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
}
if(result == false)
{
//Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );
Sleep(0);
}
}
If anyone can guide me on how to close a trade based on a ticket number in EA, that will be great.