Average the entry price of the open trades - page 2

 
mark692: i want to get the average of my entry price on buy, is that possible?
  1. Keith Watford: Add all the entry prices together. Divide by 10.

    Only if the lot sizes are all the same will sum/n work. Otherwise:

  2. Lots Weighted Average Price (∑  opi × loti ÷ ∑ loti) This is the break even price of all orders combined.
              OrderOpenPrice question . - MQL4 programming forum
              looking for sample code on how to calculate the price BE for a few Buy and Sell orders simultaneously - Pips - MQL4 programming forum

 

William Roeder:

mark692: i want to get the average of my entry price on buy, is that possible?

Keith Watford: Add all the entry prices together. Divide by 10.
  1. Only if the lot sizes are all the same will sum/n work. Otherwise:

  2. Lots Weighted Average Price (∑  opi × loti ÷ ∑ loti) This is the break even price of all orders combined.
              OrderOpenPrice question . - MQL4 programming forum
              looking for sample code on how to calculate the price BE for a few Buy and Sell orders simultaneously - Pips - MQL4 programming forum

mark692 didn't ask for the Lots weighted average.

He asked for the average entry price and that's the question that I answered!

 
William Roeder hi Sir William is  "Lots Weighted Average" the same as Sir  Fernando Carreiro  "Net Mean Opening Price"? can you translate this formula  " (∑   opi ×  loti ÷ ∑  loti)", im just an ordinary person. haha Thank you so much

Hi Sir  Keith Watford I think of this two "Lots weighted average" or  "Net Mean Opening Price" is what I need, if they are the same. I'm sorry I didn't explain clearly what I want. I thought that average entry price of all my position will give me the breakeven price, but I think I also need to consider the lotsize of my open trades not just the entry price to get the average. Thank you anyway :)
 
mark692 is  "Lots Weighted Average" the same as Sir  Fernando Carreiro  "Net Mean Opening Price"? can you translate this formula  " (∑   opi ×  loti ÷ ∑  loti)",
  1. Yes
  2. Sum (open price * lotsize) / sum (lotsize)
 
William Roeder:
  1. Yes
  2. Sum (open price * lotsize) / sum (lotsize)
Thank you so much sir  William Roeder :)
William Roeder
William Roeder
  • www.mql5.com
Trader's profile
 
Also in Sum (open price * lotsize) / sum (lotsize)

You need the lotsize to be positive in long positions and negative in short possitions in case the positions are hedged
 
Amir Yacoby:
Also in Sum (open price * lotsize) / sum (lotsize)

You need the lotsize to be positive in long positions and negative in short possitions in case the positions are hedged

oh yeah i also need to get the lot size i need to use right? is there a formula for that?

 
mark692:

oh yeah i also need to get the lot size i need to use right? is there a formula for that?

first you should get :order open price...with the OrderSelect() functions..as wiliam said at first

if you use differernt lot size for each order 

you should get each positions LOT size separately with: OrderLots function

 

There are two potential break even prices. Using this code gives me one:

double   openPrice   = 0;
double   totalLots   = 0;

double   thisLots,thisOpen,weightedAvg;

for(int i=0; i<OrdersTotal(); i++)
  {
   if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
     {
      if(OrderSymbol() == Symbol())
        {
         if(OrderType()==OP_BUY)
           {
            thisOpen = OrderOpenPrice();
            thisLots = OrderLots();

            openPrice   += thisOpen * thisLots;
            totalLots   += thisLots;
           }

         if(OrderType()==OP_SELL)
           {
            thisOpen = OrderOpenPrice();
            thisLots = -OrderLots();

            openPrice   += thisOpen * thisLots;
            totalLots   += thisLots;
           }
        }
     }
  }

weightedAvg  = NormalizeDouble(openPrice / totalLots,Digits);

Anyone know how to calculate the second potential price?

In order to test it I used these positions:
GBPAUD SELL 0.02 @ 1.89544
GBPAUD SELL 0.04 @ 1.89547
GBPAUD SELL 0.08 @ 1.89464
GBPAUD BUY  0.16 @ 1.89478

With the code I provided I get a price of 1.89330, which would be breakeven if all trades exited there. However when the price reaches 1.89511 the account profit is also $0.00.

I would like to be able to calculate both breakeven points in this case, and any help would be greatly appreciated.

 
Frederick Langemark #:

There are two potential break even prices. Using this code gives me one:

Anyone know how to calculate the second potential price?

In order to test it I used these positions:
GBPAUD SELL 0.02 @ 1.89544
GBPAUD SELL 0.04 @ 1.89547
GBPAUD SELL 0.08 @ 1.89464
GBPAUD BUY  0.16 @ 1.89478

With the code I provided I get a price of 1.89330, which would be breakeven if all trades exited there. However when the price reaches 1.89511 the account profit is also $0.00.

I would like to be able to calculate both breakeven points in this case, and any help would be greatly appreciated.

Can you apply the calculation to indicators so that it shows the average opening price on the chart?

Reason: