How to know there is a EURUSD open position or limit position?
How to know there is a EURUSD open position or limit position?
21 Feb 2016, 05:34
How to know there is a EURUSD open position or limit position in cAlgo? Thanks
In MT4, the code is:
bool existOpenOrder(string symbol)
{
int ordersTotal = OrdersTotal();
for(int i = 0; i < ordersTotal; i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == false)
return (false);
if(OrderSymbol() == symbol && (OrderType() == OP_BUY || OrderType() == OP_SELL))
return (true);
} //end for
return (false);
}
bool existLimitOrder(string symbol, int cmd)
{
if (cmd != OP_SELLLIMIT && cmd != OP_BUYLIMIT)
{
Alert("调用existLimitOrder(string symbol, int cmd)时,cmd参数传入错误!");
return false;
}
for(int i = 0; i < OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == false)
return (false);
if(OrderSymbol() == symbol && OrderType() == cmd)
return (true);
} //end for
return (false);
}
bool existLimitOrder(string symbol)
{
if (existLimitOrder(symbol, OP_SELLLIMIT))
return true;
if (existLimitOrder(symbol, OP_BUYLIMIT))
return true;
return false;
}
Waxy
23 Feb 2016, 00:39
@Waxy