How to calculate current profit in pips

To add comments, please log in or register
Francesco Fava
1052
Francesco Fava  
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 ? 
William Roeder
20214
William Roeder  

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.
Francesco Fava
1052
Francesco Fava  
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;
}
Francesco Fava
1052
Francesco Fava  
I used this function 
Cornelis Duiker
1787
Cornelis Duiker  
  
   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

Francesco Fava
1052
Francesco Fava  
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 
Francesco Fava
1052
Francesco Fava  
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 ? 
Francesco Fava
1052
Francesco Fava  
I used EquitySentry and my EA and the floating profit / loss doesn't correspond
Icham Aidibe
11676
Icham Aidibe  
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;
To add comments, please log in or register