How to know there is a EURUSD open position or limit position?

Created at 21 Feb 2016, 05:04
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
33

3330904

Joined 21.02.2016

How to know there is a EURUSD open position or limit position?
21 Feb 2016, 05:04


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;

}


@3330904
Replies

Spotware
24 Feb 2016, 17:40

Dear Trader,

Please have a look at the following code snippet:

            foreach (Position position in Positions)
            {
                Print("{0}", position.SymbolCode);

            }

            foreach (PendingOrder order in PendingOrders)
            {
                Print("{0}", order.SymbolCode);

            }

 


@Spotware