Error 4002 while calling OrderCalcProfit function, any hint please

 
   ResetLastError();
   double total=0;
   double profit=0;
   for(int i = 0; i < PositionsTotal(); i++)
     {
      if(PositionSelectByTicket(PositionGetTicket(i)))
         if(PositionGetSymbol(i) == Symbol())
           {
            if((ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
               if(OrderCalcProfit(ORDER_TYPE_BUY,Symbol(),PositionGetDouble(POSITION_VOLUME),PositionGetDouble(POSITION_PRICE_OPEN),targetPrice,profit))
                  total+= profit;
               else
                  Print("Eorror in OrderCalcProfit: "+GetLastError());
 
MOHAMED AMR MOHAMED OSAMA I ABDELWAHAB:
Never used this function before but I can tell it is for order profit calculation not positions. Both are different.
 
Navdeep Singh #:
Never used this function before but I can tell it is for order profit calculation not positions. Both are different.

Hum, so I can't use it for the potions (Oh so bad) 

 

I think I will be back to my function which calculate the profit, I though this would be more accurate but as you said it look like it is for pending orders only 

thank you