Net profit in pips

 

Hi I have this following code to count net profit in pips. But the code shows positive pips in negative & data is slightly different than original.

//----------------------------------    
   double profit = 0;
   for(int cnt=0; cnt<OrdersHistoryTotal(); cnt++)
   {
         if(OrderSelect(cnt,SELECT_BY_POS, MODE_HISTORY))
         {
         if ( TimeToStr(TimeCurrent(),TIME_DATE) == TimeToStr(OrderCloseTime(),TIME_DATE) )
         {
            profit = profit + (OrderProfit() + OrderCommission() + OrderSwap())/GetPPP(OrderSymbol());
         }
         }
   }
   Alert("today's profit in pips is ",profit);
    

double GetPPP(string A)
{
   double B = (((MarketInfo(A,MODE_TICKSIZE)/MarketInfo(A,MODE_BID))* MarketInfo(A,MODE_LOTSIZE)) * MarketInfo(A,MODE_BID))/10; //For 5 Digit

   return(B); 
}
 

Why are you adding commission and swap to your profit?

First check your code without calculating in pip.

 

Why don't you simply calculate difference between OrderClosePrice() and OrderOpenPrice()?

Note that you have to take care of sign depending on the type of the order (buy or sell). 

If you really need it, commission and swap can be approximated with point values, but those don't have anything to do with points because they are usually calculated based on the order lot size.


 

 
  • You place the stop where it needs to be - where the reason for the trade is no longer valid. E.g. trading a support bounce the stop goes below the support.
  • Account Balance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerlot + CommissionPerLot) (Note OOP-OSL includes the SPREAD)
  • Do NOT use TickValue by itself - DeltaPerlot
  • You must normalize lots properly and check against min and max.
  • You must also check FreeMargin to avoid stop out
  1. Your GetPPP is gibberish. Replace with DeltaPerLot and thus EquivalentPips = (OP+OC+OS) / OrderLots / DeltaPerLots / pips2dbl;
  2. Don't hard code numbers (/10)
    double pips2dbl = Digits%2==0 ? Point : 10*Point;

 
WHRoeder:
  1. Your GetPPP is gibberish. Replace with DeltaPerLot and thus EquivalentPips = (OP+OC+OS) / OrderLots / DeltaPerLots / pips2dbl;
  2. Don't hard code numbers (/10)

I did it in following way, But it showing zero divide error.

//----------------------------------    
   double profit = 0;
   for(int cnt=0; cnt<OrdersHistoryTotal(); cnt++)
   {
         if(OrderSelect(cnt,SELECT_BY_POS, MODE_HISTORY))
         {
         if ( TimeToStr(TimeCurrent(),TIME_DATE) == TimeToStr(OrderCloseTime(),TIME_DATE) )
         {
            profit = profit + (OrderProfit() + OrderCommission() + OrderSwap())/OrderLots()/DeltaValuePerLot(OrderSymbol())/pips2dbl(OrderSymbol());
         }
         }
   }
   Alert("today's profit is ",profit);

//-----------------------------------------------------------    
double  DeltaValuePerLot(string pair){
       return(  MarketInfo(pair, MODE_TICKVALUE)
           / MarketInfo(pair, MODE_TICKSIZE) ); // Not Point.
}
//---------------------------------------------------------
 double pips2dbl( string A)
 { 
 return(MathMod(MarketInfo(A,MODE_DIGITS),2)==0 ? MarketInfo(A,MODE_POINT) : 10*MarketInfo(A,MODE_POINT));
 }
 
eddie:

Why are you adding commission and swap to your profit?

First check your code without calculating in pip.


I need to know about the net pips . Without calculating pips my previous code is working correctly.
 
cashcube: I did it in following way, But it showing zero divide error.
  1. OrderSelect loop, filter by opened orders (OrderType <= OP_SELL) There are other things in history, that don't have a symbol.
  2. Print out your variables, and find out why.
 
WHRoeder:
cashcube: I did it in following way, But it showing zero divide error.
  1. OrderSelect loop, filter by opened orders (OrderType <= OP_SELL) There are other things in history, that don't have a symbol.
  2. Print out your variables, and find out why.

I added OrderType() == OP_BUY || OrderType() == OP_SELL

Now variables,

OrderProfit() + OrderCommission() + OrderSwap()  = 0.93

OrderLots() = 0.01

DeltaValuePerLot(OrderSymbol())  = 947.32

pips2dbl(OrderSymbol() = 0.01

Actual Net pl is +2.7 pips. but printf results shows  -9.81 along with zero divide error.

 
Any idea why it is not working?
Reason: