Greetings to the worthy ones.

Help me find the average mql5 price. Please, there are 4 positions in different lots, at different prices, in one direction, I want to know where their price is B. U.

# How do I find the average price?

Share

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Our community is a completely independent place for communication between forex traders and software developers for trading platforms Metatrader 4 and Metatrader 5

Create A New Account
## andreifan

To find the BU price for several orders, even in different directions, I use the formula

`PriceBreakeven=(SummBuy-SummSell)/(LotsBuy+LotsSell*-1);`

The formula works only if the Buy and Sell volumes are not equal.

With equal volumes, the price of BU simply does not exist. The position is locked.

*Zumbi is the sum of the products of a lot of Buy on the open price of the order.

Then this price is automatically adjusted for commission and swaps.

## barabashkakvn

Calculation Net Price.mq5 version “1.001”

Now you do not need to set the position type – for the current symbol and FOR ANY magic, two netting prices are always calculated: for Buy positions and for Sell positions. The netting price of Buy positions is drawn with a blue line, and the netting price of Sell positions is drawn with a red line:

## lil_lil

Thank you, gentlemen. Fast, professional help.

## barabashkakvn

hlinecreate, hlinemove, hlinedelete are taken from the help – creating a horizontal line: OBJ_HLINE.

The Expert Advisor (for example) works only with one type of positions-which is set in the input parameters.

## mvs

I think so, then all swaps and commissions are taken into account.

// _get. Pos. Buy. _profit = total profit Buy

// _get. Pos. Sell. _profit = total Sell profit

// _get.Pos. Buy. _lots= total Lot Buy

// _get.Pos. Sell. _lots= total Lot Sell

double TickValue=SymbolInfoDouble(mSymbol,SYMBOL_TRADE_TICK_VALUE);

if(TickValue==0) return;

double ask=SymbolInfoDouble(mSymbol,SYMBOL_ASK);

double bid=SymbolInfoDouble(mSymbol,SYMBOL_BID);

double poi=SymbolInfoDouble(mSymbol,SYMBOL_ASK);

int dig=(int)SymbolInfoInteger(mSymbol,SYMBOL_DIGITS);

BuyAwerage=0; SellAwerage=0; AllAwerage=0;

if(_Get.Pos.Buy._Lots>0) BuyAwerage= bid-(_Get.Pos.Buy._Profit/(TickValue*_Get.Pos.Buy._Lots))*poi;

if(_Get.Pos.Sell._Lots>0) SellAwerage= ask+(_Get.Pos.Sell._Profit/(TickValue*_Get.Pos.Sell._Lots))*poi;

if(_Get.Pos.Buy._Lots-_Get.Pos.Sell._Lots!=0) AllAwerage= ((_Get.Pos.Buy._Lots>_Get.Pos.Sell._Lots)?bid:ask)-((_Get.Pos.Buy._Profit+_Get.Pos.Sell._Profit)/(TickValue*(_Get.Pos.Buy._Lots-_Get.Pos.Sell._Lots))*poi);

## dima_s

(Price1 * Volume1 + … + pricen * Volume N) / (Volume 1 +…+ Volume N)

## lil_lil

That’s right )

## barabashkakvn

This means that if you open a BUY 0.30 lot at 1.18470 and a BUY 0.15 lot at 1.18740 on a hedge account , where will the netting price of these two positions be?

## laryx

The question is unclear.

What do you mean “the price of B. U.” for multiple items ? The BU price happens for one position – it is, in fact, the price of its opening. And if there are several positions – what ONE “BU price” can we talk about ?