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

Created at 21 Feb 2016, 05:34
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!
AL

alibaba

Joined 21.02.2016

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;

}


@alibaba
Replies

Waxy
23 Feb 2016, 00:39

// For positions

            if (Positions != null)
            {
                foreach (var pos in Positions)
                {
                    if (_pos.SymbolCode == "EURUSD")
                    {
                        //do stuff here
                    }
                }
            }

//-----------------

// For pending orders

            if (PendingOrders != null)
            {
                foreach (var pending in PendingOrders)
                {
                    if (pending.SymbolCode == "EURUSD")
                    {
                        //Do stuff here
                    }
                }
            }

 


@Waxy

Waxy
23 Feb 2016, 00:41

//For limit pending orders

            if (PendingOrders != null)
            {
                foreach (var pending in PendingOrders)
                {
                    if (pending.SymbolCode == "EURUSD" && pending.OrderType == PendingOrderType.Limit)
                    {
                        //Do stuff here
                    }
                }
            }

 


@Waxy