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 ?

20214

**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 ?

- You've got it correct
- "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.

1052

- You've got it correct
- "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.

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;

}

1787

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

1052

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

1052

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 ?

1052

11676

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;