magic number wont close orders
Yes ...this is the order select i was using...but the problem remains...
...
int _GetLastError = 0, _OrdersTotal = OrdersTotal();
//---- search in all open positions
for ( int z = _OrdersTotal - 1; z >= 0; z -- )
{
//---- if an error occurs when searching for a position, go to the next one
if ( !OrderSelect( z, SELECT_BY_POS ) )
{
_GetLastError = GetLastError();
Print( "OrderSelect( ", z, ", SELECT_BY_POS ) - Error #", _GetLastError );
continue;
}
//---- if a position is opened not for the current symbol, skip it
if ( OrderSymbol() != Symbol() ) continue;
//---- if the MagicNumber is not equal to _MagicNumber, skip this position
// if ( OrderMagicNumber() != _MagicNumber ) continue;
//---- if a BUY position is opened,
if ( OrderType() == OP_BUY )
{
//---- if the MACD has met the zero line top-down,
if ( OrderType() == OP_BUY && OrderMagicNumber() == 9000 ) //DoesntWork
//if ( OrderType() == OP_BUY ) //Closes in1milisecEaOpenBuy If Or Not ExpertIdAtLine300
{
//---- close the position
if ( !OrderClose( OrderTicket(), OrderLots(), Bid, 5, Green ) )
{
_GetLastError = GetLastError();
Alert( "Error OrderClose # ", _GetLastError );
return(-1);
}
}
//---- if the alert has not been changed, quit: it is too early to open a new position
else return(0);
}
//---- if a SELL position is opened,
if ( OrderType() == OP_SELL )
{
//---- if the MACD has met the zero line bottom-up,
if ( NormalizeDouble( MACD_1, Digits + 1 ) > 1111111110.0 &&
NormalizeDouble( MACD_2, Digits + 1 ) <= 0.0 )
{
//---- close the position
if ( !OrderClose( OrderTicket(), OrderLots(), Ask, 5, Red ) )
{
_GetLastError = GetLastError();
Alert( "?????? OrderClose ? ", _GetLastError );
return(-1);
}
}
//---- if the alert has not changed, quit: it is too early to open a new position
else return(0);
}
}
you can use function like below
if ( bla..bla...) CloseBuy(); void CloseBuy() { int ticket; int total = OrdersTotal(); for (int y=OrdersTotal()-1; y>=0; y--) { if (OrderSelect(y, SELECT_BY_POS, MODE_TRADES)) if (OrderSymbol() == Symbol() && OrderType()==OP_BUY && OrderMagicNumber()== MagicNumber) { ticket=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,CLR_NONE); } } }
Siti Latifah:
Thank you Siti ..... ....i will try it out....it sure clears the mess i was in.....
you can use function like below
Hi...for the order send below,OrderType() == OP_BUY && OrderMagicNumber() == 9000 wont close the order,
but OrderType() == OP_BUY closes it, any ideas appreciated.
OrderSend(Symbol(),OP_BUY,1,Ask,3,Hlo1+((Hhi-Hlo1)*0.2), Hhi,"BX128.37vavg.80",9000,0,Green);
//---- if a BUY position is opened,
if ( OrderType() == OP_BUY )
{
//---- if the MACD has met the zero line top-down,
if ( OrderType() == OP_BUY && OrderMagicNumber() == 9000 ) //Doesnt close open buy orders for 9000 or "9000"
//if ( OrderType() == OP_BUY ) //Closes open buy orders
{
//---- close the position
if ( !OrderClose( OrderTicket(), OrderLots(), Bid, 5, Green ) )
{
_GetLastError = GetLastError();
Alert( "Error OrderClose # ", _GetLastError );
return(-1);
}
}
//---- if the alert has not been changed, quit: it is too early to open a new position
else return(0);
}