Download MetaTrader 5

returning multiple values from a method

To add comments, please log in or register
What is MetaQuotes ID? Find that out from the article!
amin_mohammadi
88
amin_mohammadi 2014.02.24 15:15 

Hello,

I need to return multiple values from a method.

Actually I'm already using a struct but it doesn't work properly (sometimes it returns true value but sometimes returns EMPTY_VALUE).

struct orderValue
  {
   double            price;
   double            tp;
   double            vol;
   datetime          time;

  };
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
class OrderManagement 
  {

public:
   orderValue        OrderCount(string pSymbol,int type);
                     OrderManagement(void);
                    ~OrderManagement(void);
  };


OrderManagement::OrderManagement(void)
  {

  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
OrderManagement::~OrderManagement(void)
  {
  }


orderValue OrderManagement::OrderCount(string pSymbol,int type)
  {
   orderValue order;
   
   

   for(int i=0; i<PositionsTotal(); i++)
     {

      if(PositionGetSymbol(i)==pSymbol && (int)PositionGetInteger(POSITION_TYPE)==type)
        {
         order.tp=PositionGetDouble(POSITION_TP);
         order.price= PositionGetDouble(POSITION_PRICE_OPEN);
         order.vol=PositionGetDouble(POSITION_VOLUME);
        break;
        }
     }
   return order;
  }


// The code using class OrderManagement 


void TradeForPairCurrencies(string symbol,ENUM_TIMEFRAMES tf,int flag)
  {
  
  OrderManagement order;
   orderValue buyOrder=order.OrderCount(symbol,ORDER_TYPE_BUY);
   orderValue sellOrder=order.OrderCount(symbol,ORDER_TYPE_SELL);
.
.
.
  }




Alain Verleyen
Moderator
30702
Alain Verleyen 2014.02.24 16:16  
amin_mohammadi:

Hello,

I need to return multiple values from a method.

Actually I'm already using a struct but it doesn't work properly (sometimes it returns true value but sometimes returns EMPTY_VALUE).

And what is your problem concretely ?
amin_mohammadi
88
amin_mohammadi 2014.02.24 20:28  
angevoyageur:
And what is your problem concretely ?
Is this a true approach? if yes why is it working wrong?
Alain Verleyen
Moderator
30702
Alain Verleyen 2014.02.24 21:34  
amin_mohammadi:
Is this a true approach? if yes why is it working wrong?
I don't see a problem with this approach. What is working wrong ? That doesn't mean anything useful to help you, "wrong" !
To add comments, please log in or register