You have to select order with OrderSelect() before calling OrderClose() function.
Try something like this
if (Hour()==15&&Minute()==00)
{
bool found = false;
for( int i = OrdersTotal() - 1; i>=0; i--)
{
if ( ! OrderSelect( i, SELECT_BY_POS, MODE_TRADES)) continue;
if ( OrderMagicNumber() != MagicNumber) continue;
if ( found)
Alert( OrderSymbol(), " ", MagicNumber, " Double Order");
switch ( OrderType())
{
case OP_BUY:
case OP_SELL:
found = true;
OrderClose(OrderTicket(),OrderLots(),Ask,3,CLR_NONE);
break;
default:
Alert( OrderSymbol(), " ", MagicNumber, " Wrong Order Type #1");
} // switch
} // for
if ( !found)
{
}
}
Thanks a lot.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I tried close my positon at a given time this code, but it's unsuccessful.
Do somebody any idea?
brasil
[{OrderSend(Symbol(),OP_SELL,0.1,Bid,0,0,Bid-TakeProfit*Point,0,CLR_NONE);
}
if (Hour()==15&&Minute()==00)
{OrderClose(OrderTicket(),OrderLots(),Ask,0,CLR_NONE);
}]