Formula to know the average price on several positions
-
Hello, I am trying to understand how to calculate the average price on several positions and the unrealised pips of profit.
Example:
Trade 1 = 1 lot 1.0000
Trade 2 = 2 lots 1.0002
Trade 3 = 4 lots 1.0004
Current market price 1.0010
They are all buy trades, obviously the total lot size is 7 lots but how can I make the robot understand what's the average price and what are the unrealised pips?
Unrealised pips = x
I would like to know the x value so I can use it in other conditions.
Thank you in advance to anyone who can do this, it would help me a lot to increase the profitability and lower drawdown.
-
https://fxdreema.com/shared/ekL83l7ke
I came up with this, there is something wrong for sure but I don't get what. Can someone help me?
Thank you
-
For those who don't know how to calculate it but maybe know much better how to translate it into formulas of Fxdreema.
You should calculate like this
a. 1 lot buy 1.0001
b. 2 lots buy 1.0003
c. 3 lots buy 1.0005
Average price = (1 x 1.0001 + 2 x 1.0003 + 3 x 1.0005) / (1+2+3)
Help please
-

You can do it by block bucket of trades , reach it by condition or fomula and put it in a variable,what you want to do it. -
Does this give an average value also considering that they have different volume lot size?
-
@MMF
I tried it, it works very well but it doesn't consider that trades have different sizes
This would have been ideal if the trades were all of the same size.
-
Please FxDreema help I am sure you are able to make the software do that, it would help a lot of others I believe.
-
I am not sure what exactly you need, but maybe this?

-
This is similar to the other solution. It doesn't consider the fact that not all trades have the same size. You made me reflect though, what I need exactly is to know the breakeven point of all buy trades, so I can set the robot to close 10 pips further.
-
ok, for different lot size and knowing BE price point, you need manually calculation ... something like this:
https://fxdreema.com/shared/467ZcImHb
(swaps, commisions, etc. are not calculated here, but you can do it)
I have not tested if it is working ...note, in this case block order numbering is important, if you mix them, it stop working ...
and I dont know how easier it can be done ....
-
Wonderful miro1360
If you remember I requested the same request from time past.
. -
@miro1360 i tried it, it is Perfect

Break even is zero, how adjust break even + 4 pips ?
i Put resultSellPrice in modify stops as Take Profit(custom price level) .
i tried adjust in Block modify stops but it Ignores the value -
@MMF said in Formula to know the average price on several positions:
i Put resultSellPrice in modify stops as Take Profit(custom price level) .
i tried adjust in Block modify stops but it Ignores the valuetry type into adjust this:
+4pipsand note one thing ... for Buy, TP can be placed above current price, and SL can be placed below current price .... for buy you can not place TP below current price ...
-
@miro1360
there is no change in the value of the variable and also question mark unable when I mouse over it. -
than modify it manually in calculation:

for buy add these pips in digits and for sell subtract it (because logically sell is in profit below open prices) ...
-
@miro1360
thank you now it`s Ok

-
dont forget, that for JPY pairs is another quotation, so instead of 0.0004 you need give 0.04
... or you can instead of this number have this function:
toDigits(4) (where 4 are 4 pips) ... and it can working with all pairs automaticallyso result formula will be:
resultBuyPrice=sumPrice/sumLot+toDigits(4);
resultSellPrice=sumPrice/sumLot-toDigits(4); -
This is a great system, I found this that seems easier tell me if it makes sense to you
https://fxdreema.com/shared/GOHeJlHAc
TPB is a constant so it can be modified for each currency pair. It just checks when the trades get over breakeven and if the flag is true, which is only after a trade was opened it draws a horizontal line at the preferred distance.
Trades are closed when price passes the line.
This is done but sadly I had another problem...
If the server is restarted all of my martingale risk management screws up because I use this system:
https://fxdreema.com/shared/iQQPen5Zc
When the server restarts it's a mess and the lots multiply like crazy and make an insane profit or otherwise blow up because the trade size is too big.
Do you have any ideas to multiply volume size from the last opened trade only, or otherwise draw on chart the last trades size so if the server restarts the robot can find it on the chart?
-
Lot size from last opened trade you can get with this way:

Lot size from last closed trade this way:

-
@miro1360
I have already done by adjust not formula.
thank you very much miro