basket pips

 

I'm trying to tackle an area re: basketpips

I'm not sure if i ought concern myself with pipvalue at all.
i.e.
http://www.earnforex.com/pip-value-calculator

Currency pair AUDJPY
Position size, units 100000
Current AUD/JPY 87.672
Price of pip 11.406150196185786

Account Currency USD
Currency pair AUDJPY
Position size, units 100000
Current USD/JPY Ask price 89.431
Price of pip 10.159401001716938

So ignoring that for now - I have a script where I want to find
a) basketpips profit
b) basketpips breakeven point

It varies in results. Can anyone see it clearly.

//+------------------------------------------------------------------+
//|                                        bskt_avrge_per_symbol.mq4 |
//|                                          Copyright © 2013, TMM. |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2013, TMM."

   double  dg,  pt, mt;

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
   {
//----
   double LotsB   = 0.0;
   double LotsS   = 0.0; 
   double LotsTotal = 0.0; 
        
   double ProfitB = 0.0;
   double ProfitS = 0.0;   
   double ProfitTotal = 0.0;      
   
   double OCPB_bid    = 0.0;
   double OCPS_ask    = 0.0;   
   
   double averageB = 0.0;
   double averageS = 0.0;   
   double averageTotal = 0.0;   

   double pipsTotalB = 0.0;
   double pipsTotalS = 0.0;      
   double pipsTotal = 0.0;
   
   int    OTBCnt  = 0;
   int    OTSCnt  = 0;      
   int    OTCntTotal  = 0;  

  
   double openpipsLongB = 0.0;
   double openpipsShortB = 0.0;   
   double openpipsTotalB = 0.0;     

   double openpipsLongC = 0.0;
   double openpipsShortC = 0.0;   
   double openpipsTotalC = 0.0;   
   
   double openpipsLongD = 0.0;
   double openpipsShortD = 0.0;   
   double openpipsTotalD = 0.0;  
 
   double openpipsLongE = 0.0;
   double openpipsShortE = 0.0;   
   double openpipsTotalE = 0.0;  
                  
   point();
   
   for (int i = OrdersTotal() - 1; i >= 0; i--)
      {
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);

            if (OrderSymbol() != Symbol()) 
            continue ;
            if( OrderType() != OP_BUY && OrderType() != OP_SELL) 
            continue ;
        //    if(OrderMagicNumber()!=Magic )  
        //    continue;

            if(OrderType() == OP_BUY)
            {
               LotsB   += OrderLots();
               ProfitB += OrderProfit() + OrderCommission() + OrderSwap();
               OCPB_bid    = OrderClosePrice(); 
               OTBCnt++;
            
               // alternativeB               
               openpipsLongB += ( ((OrderClosePrice()-OrderOpenPrice())/pt) *OrderLots() ); 
               // alternativeC               
               openpipsLongC += ( ((OrderClosePrice()-OrderOpenPrice())/PointValuePerLot()) *OrderLots() );                
               // alternativeD               
               openpipsLongD += MarketInfo(OrderSymbol(),MODE_TICKVALUE)*OrderLots()*((OrderClosePrice()-OrderOpenPrice())/pt);                
               // alternativeE               
               openpipsLongE += MarketInfo(OrderSymbol(),MODE_TICKVALUE)*OrderLots()*((OrderClosePrice()-OrderOpenPrice())/PointValuePerLot());                
               
               Alert("Close price for the B order ",OrderTicket()," = ",DoubleToStr(OCPB_bid,5));
            }
            if(OrderType() == OP_SELL)
            {
               LotsS   += OrderLots();
               ProfitS += OrderProfit() + OrderCommission() + OrderSwap();         
               OCPS_ask    = OrderClosePrice(); 
               OTSCnt++;
               
               // alternativeB
               openpipsShortB +=  ( ((OrderOpenPrice()-OrderClosePrice())/pt) *OrderLots() ); 
               // alternativeC
               openpipsShortC +=  ( ((OrderOpenPrice()-OrderClosePrice())/PointValuePerLot()) *OrderLots() );                
               // alternativeD
               openpipsShortD += MarketInfo(OrderSymbol(),MODE_TICKVALUE)*OrderLots()*((OrderOpenPrice()-OrderClosePrice())/pt);
               // alternativeE
               openpipsShortE += MarketInfo(OrderSymbol(),MODE_TICKVALUE)*OrderLots()*((OrderOpenPrice()-OrderClosePrice())/PointValuePerLot());    
                                         
               Alert("Close price for the S order ",OrderTicket()," = ",DoubleToStr(OCPS_ask,5));
            }  
                  
      }

      LotsTotal = LotsB+LotsS;
      ProfitTotal = ProfitB+ProfitS;
      pipsTotal = (ProfitB+ProfitS)/(LotsB+LotsS)/MarketInfo(Symbol(),MODE_TICKVALUE);

      pipsTotalB = (ProfitB)/(LotsB)/MarketInfo(Symbol(),MODE_TICKVALUE);
      pipsTotalS = (ProfitS)/(LotsS)/MarketInfo(Symbol(),MODE_TICKVALUE);
      

                  
      if (OTBCnt > 0)
         {
         averageB = OCPB_bid - (pipsTotalB*pt);
         }
      if (OTSCnt > 0)
         {
         averageS = OCPS_ask + (pipsTotalS*pt);
         }
      averageTotal =  (averageB+averageS)/2;
         
      Alert ("Part 1");
      Alert ("LotsTotal = ", DoubleToStr(LotsTotal,5));
      Alert ("ProfitTotal = ", DoubleToStr(ProfitTotal,5));
      Alert ("pipsTotal = ", DoubleToStr(pipsTotal,5));
      Alert ("averageTotal BE = ", DoubleToStr(averageTotal,5));
      
      //alternativeB           
      openpipsTotalB = openpipsLongB + openpipsShortB ;
      Alert ("Part 2");      
      Alert ("openpipsTotalB = ", DoubleToStr(openpipsTotalB,5));

      //alternativeC           
      openpipsTotalC = openpipsLongC + openpipsShortC ;
      Alert ("Part 3");      
      Alert ("openpipsTotalC = ", DoubleToStr(openpipsTotalC,5));            
      
      //alternativeD           
      openpipsTotalD = openpipsLongD + openpipsShortD ;
      Alert ("Part 4");      
      Alert ("openpipsTotalD = ", DoubleToStr(openpipsTotalD,5));    
      
      //alternativeE           
      openpipsTotalE = openpipsLongE + openpipsShortE ;
      Alert ("Part 5");      
      Alert ("openpipsTotalE = ", DoubleToStr(openpipsTotalE,5));          
      
//----

   return(0);
   }
//+------------------------------------------------------------------+

void point(){
   dg=Digits;
   if(dg==3 || dg==5){pt=Point*10;mt=10;}
   else{pt=Point;mt=1;}
} 

double  PointValuePerLot() { // Value in account currency of a Point of Symbol.
    /* In tester I had a sale: open=1.35883 close=1.35736 (0.00147)
     * gain$=97.32/6.62 lots/147 points=$0.10/point or $1.00/pip.
     * IBFX demo/mini       EURUSD TICKVALUE=0.1 MAXLOT=50 LOTSIZE=10,000
     * IBFX demo/standard   EURUSD TICKVALUE=1.0 MAXLOT=50 LOTSIZE=100,000
     *                                  $1.00/point or $10.00/pip.
     *
     * https://forum.mql4.com/33975 CB: MODE_TICKSIZE will usually return the
     * same value as MODE_POINT (or Point for the current symbol), however, an
     * example of where to use MODE_TICKSIZE would be as part of a ratio with
     * MODE_TICKVALUE when performing money management calculations which need
     * to take account of the pair and the account currency. The reason I use
     * this ratio is that although TV and TS may constantly be returned as
     * something like 7.00 and 0.00001 respectively, I've seen this
     * (intermittently) change to 14.00 and 0.00002 respectively (just example
     * tick values to illustrate). */
    return(  MarketInfo(Symbol(), MODE_TICKVALUE)
           / MarketInfo(Symbol(), MODE_TICKSIZE) ); // Not Point.
     }      

I think PointValuePerLot() is actually probably useful in lot size calcs - so it is probably being used incorrectly

Maybe part1 is accounting for commission so might be doing what i need.


 

If you're looking for the total pips the basket have gain/lost then you're probably going about it the hard way. Here I'll give you a few of my function, hopefully you know how to use functions. If you're looking for something else like total_profit [with/without commissions], or total_points, or total x-currency value then please clarify.

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int PipCntBuyOpn(){
    int Res=0, Sign=0;
    for(int i=OrdersTotal()-1; i>=0; i--){
        if(!OrderSelect(i,SELECT_BY_POS)){continue;}
        if(OrderMagicNumber()!=SystemMagic1){continue;}
        if(OrderSymbol()!=CurSetSymbol){continue;}
        if(OrderType()!=OP_BUY){continue;}
        double Oop=OrderOpenPrice();
        double Ocp=OrderClosePrice();
        int DifIntPip=p2i(MathAbs(Oop-Ocp));
        double P=OrderProfit()+OrderCommission()+OrderSwap();
        if(P>0){Sign=1;}else{Sign=-1;}
        Res+=(DifIntPip*Sign);
    }   return(Res);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int PipCntSelOpn(){
    int Res=0, Sign=0;
    for(int i=OrdersTotal()-1; i>=0; i--){
        if(!OrderSelect(i,SELECT_BY_POS)){continue;}
        if(OrderMagicNumber()!=SystemMagic1){continue;}
        if(OrderSymbol()!=CurSetSymbol){continue;}
        if(OrderType()!=OP_SELL){continue;}
        double Oop=OrderOpenPrice();
        double Ocp=OrderClosePrice();
        int DifIntPip=p2i(MathAbs(Oop-Ocp));
        double P=OrderProfit()+OrderCommission()+OrderSwap();
        if(P>0){Sign=1;}else{Sign=-1;}
        Res+=(DifIntPip*Sign);
    }   return(Res);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int p2i(double X){ /*Pip2Int or Price2Int*/
    if(StringFind(CurSetSymbol,"JPY")>-1
    || StringFind(CurSetSymbol,"XAG")>-1
    || StringFind(CurSetSymbol,"XAU")>-1
    ){
        double Pips=0.01;}else{Pips=0.0001;
    }   return(X/Pips);
}

PipCntBuyOpn: Sums-up the total Pips [again its Pips not Point]. Pip_Count_Buy_Open.Orders.

 

mrmedia:

a) basketpips profit

b) basketpips breakeven point

I think PointValuePerLot() is actually probably useful in lot size calcs - so it is probably being used incorrectly

  1. profit you already have.
    ProfitB += OrderProfit() + OrderCommission() + OrderSwap();
  2. breakeven point is just lots weighted open price. Sum( OrderOpenPrice() * OrderLots() ) / Sum( OrderLots() )
  3. I renamed/modified PointValuePerLot:
    double PipValuePerLot(string  pair=""){return(DeltaValuePerLot(pair)*pips2dbl);}
    double DeltaValuePerLot(string pair=""){
       if(pair == "") pair = Symbol();
       //{Value in account currency of a Point of Symbol.
       // In tester I had a sale: open=1.35883 close=1.35736 (0.0147)
       // gain$=97.32/6.62 lots/147 points=$0.10/point    or $1.00/pip.
       // IBFX demo/mini       EURUSD TICKVALUE=0.1 MAXLOT=50 LOTSIZE=10,000
       // IBFX demo/standard   EURUSD TICKVALUE=1.0 MAXLOT=50 LOTSIZE=100,000
       //                      $1.00/point    or $10.0/pip.
       //
       // https://www.mql5.com/en/forum/127584 CB: MODE_TICKSIZE will usually return the same
       // value as MODE_POINT (or Point for the current symbol), however, an example
       // of where to use MODE_TICKSIZE would be as part of a ratio with
       // MODE_TICKVALUE when performing money management calculations which need to
       // take account of the pair and the account currency. The reason I use this
       // ratio is that although TV and TS may constantly be returned as something
       // like 7.00 and 0.0001 respectively, I've seen this (intermittently) change
       // to 14.00 and 0.0002 respectively (just example tick values to illustrate).
       // https://www.mql5.com/en/forum/135345 zzuegg reports for non-currency DE30:
       // MarketInfo(pair,MODE_TICKSIZE) returns 0.5
       // MarketInfo(pair,MODE_DIGITS)   return 1
       // Point    = 0.1
       // Prices to open must be a multiple of ticksize
       //}
       return( MarketInfo(pair, MODE_TICKVALUE)
             / MarketInfo(pair, MODE_TICKSIZE) ); // Not Point.
    }
    As the comment says, do NOT use TICKVALUE by itself.
    // openpipsLongE += MarketInfo(OrderSymbol(),MODE_TICKVALUE)*OrderLots()*
    // ((OrderClosePrice()-OrderOpenPrice())/PointValuePerLot());                
    
    openpipsLongE += ( OrderClosePrice()-OrderOpenPrice() ) * OrderLots() * DeltaPerLot();

  4. for (int i = OrdersTotal() - 1; i >= 0; i--)
          {
          OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
    If the OrderSelect fails, so does everything below. What are Function return values ? How do I use them ? - MQL4 forum

 


Trying to put some meaning to it...
The brokers may have set a fixed value to each point movement but the calculator suggests its all
dynamic.

If 2xbuy and 4xsell that is net 2xsell.
I saw in i-Breakeven that it uses 'net'.
codebase.mql4.com/1097

If in the 'pipcalc' the result "Price of pip" = 20.00, that is what the exposure is up and down.
input 200000 net position size, choice base, input current.. etc. etc.

And i know that OrderProfit() + OrderCommission() + OrderSwap() = 880.00

So it must be 44pips.
which is approx (lots()*OOP-OCP - lots()*OCP-OOP)

(Maybe

....since in backtester you need a value for
usdjpy whilst trading audjpy - so you can calc MODE_TICKVALUE
you might use this
string   pipFactor[]                = {"SILVER","GOLD","AUDJPY","AUDUSD","GBPJPY","GBPCHF","EURAUD","EURJPY","EURCHF","EURGBP","USDCAD","USDJPY","USDCHF","GBPUSD","EURUSD","NAS100","CAC400"};
double   pipFactors[]               = { 5.000,  1.00,  1.020,    1.00000,    1.020,  1.07470,   0.90603,  1.020,   1.07470,  1.52538,    0.97154,   1.020,    1.07470,  1.00000,  1.00000,  1,       1};

No code yet but I want to ask the question

Exiting at $800 profit or 40pips .... why use pips?
Basketdollar vs basketpip. They ought to equal if you did the code right.

Though I guess if you target 20pips exit - the dollar amount will vary from instrument to instrument.

So maybe useful if reporting results in $ or pnt or pip depending on your liking.

assuming

void point2(){
  if (Digits == 5 || Digits == 3){    // Adjust for five (5) digit brokers.
                pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
    } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }  
} 

ok here's the problem ...
if tp at 20points and trail 50points 
it can be calculated as 
87.124+10points-50points = 87.084 trailing stop
but
in dollars 
87.124+$20-$50 = ?????

Reason: