How to calculate current profit in pips

 
Hello to all,

I've seen several posts but no one has helped me ....
I made an EA that open several orders, I wish to calculate to the whole order with a specific magic number, the algebraic sum of profit or loss in pips .
I set a cycle for scanning all orders, and for each one:
If buy I calculated the difference between Ask-OpenOrderPrice
And if sell between OpenOrserPrice-Bid and then converting in pips . Then at the end summing  pips on each order. 
This calculation is carried out call this function from OnTick function but I have seen that calculation is wrong in something. Can you help me ? 
 

Francesco Fava:

If buy I calculated the difference between Ask-OpenOrderPrice And if sell between OpenOrserPrice-Bid and then converting in pips . Then at the end summing  pips on each order. 

This calculation is carried out call this function from OnTick function but I have seen that calculation is wrong in something. Can you help me ? 
  1. You've got it correct
  2. "wrong in something" is meaningless - just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires - meaningless. We can't see your broken code. There are no mind readers here and our crystal balls are cracked.
 
whroeder1:
  1. You've got it correct
  2. "wrong in something" is meaningless - just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires - meaningless. We can't see your broken code. There are no mind readers here and our crystal balls are cracked.
I used marketinfo function in this way:
OnInit:
if(Digits == 3 || Digits == 5) point_compat = 10;

And 


double CheckPips()
{

int total = OrdersTotal();
double diff=0;
for (int cnt =total-1 ; cnt>=0 ; cnt--)
{
bool result=OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if(OrderMagicNumber()==magico) {
   if (OrderType()==OP_BUY) {
   double diff1=OrderOpenPrice();
   double DiffPips = (NormalizeDouble(((Ask - diff1)/MarketInfo(Symbol(),MODE_POINT)),(int)MarketInfo(Symbol(),MODE_DIGITS)))/point_compat;
            diff=diff+DiffPips;
   }
   
   if (OrderType()==OP_SELL) {
   double diff1=OrderOpenPrice();
   double DiffPips = (NormalizeDouble(((diff1 - Bid)/MarketInfo(Symbol(),MODE_POINT)),(int)MarketInfo(Symbol(),MODE_DIGITS)))/point_compat;
   diff=diff+DiffPips;
            }
         }

   }
//diff=diff-spreadpips;
double tot=NormalizeDouble(diff,2);
ScriviSuChart("ObjName1","cumulated pips: " + (string)tot,20);
return tot;
}
 
I used this function 
 
  
   for (int cnt = OrdersTotal() - 1; cnt >= 0; cnt--) 
   {
      if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES) && OrderSymbol() == Symbol())
      {
               if (OrderMagicNumber() == MagicS)
               {
                  gProfit += OrderProfit(); // add Swap and Commission if you care
                  gOrdersCount += 1;
                  gLots += OrderLots();
      
                  gWeightedAverage += OrderLots() * OrderOpenPrice();
               }
      }
   }
   if (gLots > 0) gWeightedAverage /= gLots;

make sure you init the vars to 0

at the end of this you will all your heart desires -> Profit, Ordercount, Total Lot Size and and average order open price.

you now can use this average order open price similar to how you used diff1 before.  Example = ( (gWeightedAverage - Bid) / Point) / Point_Compat.  and then normalize it

 
Cornelis Duiker:
  

make sure you init the vars to 0

at the end of this you will all your heart desires -> Profit, Ordercount, Total Lot Size and and average order open price.

you now can use this average order open price similar to how you used diff1 before.  Example = ( (gWeightedAverage - Bid) / Point) / Point_Compat.  and then normalize it

But I have to calculate weighted average separately for buy and sell orders ? Because you have said Example = ( (gWeightedAverage - Bid) / Point) / Point_Compat and so you placed Bid .... This if for sell orders 
 
I will have to calculate both 
( (gWeightedAverage - Bid) / Point) / Point_Compat

And

( (Ask - gWeightedAverage - ) / Point) / Point_Compat

How to calculate PERFECTLY the number of profit pips of all opened trades ? 
 
I used EquitySentry and my EA and the floating profit / loss doesn't correspond
 
Francesco Fava:
I used EquitySentry and my EA and the floating profit / loss doesn't correspond

Your function seems correct to me. Maybe is there some commissions on your account ?

Then do not confuse points with pips.

  double DiffPips = (NormalizeDouble(((Ask - diff1)/MarketInfo(Symbol(),MODE_POINT)),(int)MarketInfo(Symbol(),MODE_DIGITS)))/_Point;
 
double GetProfitOpenPosInPips(){
   double pr=0.0;
   for(int i=0; i<OrdersTotal(); i++){
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)){
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==gMagicNumber){
            if(OrderType()==OP_BUY){
               pr+=(OrderProfit()/OrderLots()/MarketInfo(OrderSymbol(),MODE_TICKVALUE))/10;
            }
            if(OrderType()==OP_SELL){
               pr+=(OrderProfit()/OrderLots()/MarketInfo(OrderSymbol(),MODE_TICKVALUE))/10;
            }
           }
        }
   }
   return (pr);
}
Please note that MODE_TICKVALUE is used, your account currency is important at this point.
 
Ugur Catak:
Please note that MODE_TICKVALUE is used, your account currency is important at this point.

This topic is about Pips PL, nothing to do with tick value.

Reason: