Summing up sell and buy orders function in mql5 help

 

The EA opens 1 buy and 1 sell order at the same time. This function is supposed to add up the sell and buy orders  and return net profit. The problem is, the code does seem 

to sum both it only sums 1 order . What is the

double Money()
  {

   double SumBuy=0;
   double SumSell=0;
   string   symbol;
   symbol=OrderGetString(ORDER_SYMBOL);
   for(int i=0; i<PositionsTotal(); i++)
     {
      bool selected=PositionSelect(symbol);
      if(selected==true) // if the position is selected
         double addM=PositionGetDouble(POSITION_PROFIT);

        {
         if(symbol==_Symbol)
           {
            if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
               SumBuy=PositionGetDouble(POSITION_PROFIT);
            if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL)
               SumSell=PositionGetDouble(POSITION_PROFIT);
           }
        }
     }
   return( SumBuy+SumSell);
  }


problem?

 
A buy order (+1) plus a sell order (-1) total up to no position at all. Unless you just love handing over your money to your broker then don't ever open a position and then instantly close it with an opposite order. 
 

This 'hedging' thing is driving me mad since a week. It's like a promise to generate money out of nothing, like the perpetuum mobile to generate energy out of nothing.

There's some badly arranged brace here:

      if(selected==true) // if the position is selected
         double addM=PositionGetDouble(POSITION_PROFIT);

        {

I think you meant:

      if(selected) // if the position is selected
        {
         double addM=PositionGetDouble(POSITION_PROFIT);

 
bool selected= PositionGetTicket(i);
Reason: