• Home
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • User/Email: Password:
  • 8:26pm
Menu
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • 8:26pm
Sister Sites
  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Options

Bookmark Thread

First Page First Unread Last Page Last Post

Print Thread

Similar Threads

I Have 10 Buy Open Positions - I need to calculate 4 Buys open 2 replies

function to calculate stoploss for all open orders based X% DrawDown 0 replies

script to "close open orders" and "open opposite orders" 3 replies

How do I calculate total profit of all open orders? 9 replies

Calculate Average exit point for various Orders with diferent lots 3 replies

  • Trading Discussion
  • /
  • Reply to Thread
  • Subscribe
  • 7
Attachments: How to calculate average price for open orders
Exit Attachments

How to calculate average price for open orders

  • Last Post
  •  
  • Page 1 2
  • Page 1 2
  •  
  • Post #1
  • Quote
  • First Post: Sep 1, 2014 4:28am Sep 1, 2014 4:28am
  •  PlanAndTrade
  • | Membership Revoked | Joined Oct 2012 | 64 Posts
Hello,
if i open a sellorder at 1.3500 with 0.1 lot and a buyorder at 1.3520 with 0.25 lot, how can i calculate the break even average price for both orders? I know when the price will go more up the win from the buy can be more then the loose from the sell, but how can i calculate the exact price where both orders toghter create 0 win/loos?
  • Post #2
  • Quote
  • Sep 1, 2014 4:36am Sep 1, 2014 4:36am
  •  FerruFx
  • Joined May 2007 | Status: MT4/MT5 EAs/Indicators/Alerts coder | 6,842 Posts
The lot size gives a specific "weight" to your position pip value. Define the pip value for each position and you will easily find the BE point
MT4/MT5 EAs/Indicators/Alerts coder
 
 
  • Post #3
  • Quote
  • Edited at 5:32am Sep 1, 2014 5:19am | Edited at 5:32am
  •  PipMeUp
  • Joined Aug 2011 | Status: Member | 1,305 Posts
The breakeven price B is given by the following formula where Pi is the entry price for the i-th position and Wi is the lot size of the i-th position. Wi is negative for short and positive for long.
In the example: (-0.1 x 1.3500 + 0.25 x 1.3520) / (-0.1 + 0.25) = 1.35333
Attached Image
No greed. No fear. Just maths.
 
2
  • Post #4
  • Quote
  • Sep 1, 2014 10:57am Sep 1, 2014 10:57am
  •  Proximus
  • Joined Oct 2013 | Status: Forex Shaman | 1,468 Posts
Quoting PlanAndTrade
Disliked
Hello, if i open a sellorder at 1.3500 with 0.1 lot and a buyorder at 1.3520 with 0.25 lot, how can i calculate the break even average price for both orders? I know when the price will go more up the win from the buy can be more then the loose from the sell, but how can i calculate the exact price where both orders toghter create 0 win/loos?
Ignored
If you open a SELL order at 1.35 at BID, then you have to add the spread to the open order, so for example 1.35000 is your BID, your ask is 1.35010, then your order will be breakeven once the BID reaches the previous ASK of 1.35010

So the breakeven is actually the open price + or - the spread, depending on the type of the order.

But if the LOT size is different, then you have to multiply each difference with the lot size.

So you got a 1.35000 SELL, and lets assume there is 1 pip spread in both cases, so first you got a 10 pipette difference multiply that with 10000 lot size *0.00001 the ticksize that is 1$ / pip and the buy is also 2.5$/pip, so in total you got -3.5$ initially because of the spread.

Once that hits 0 $ then it will be breakeven.
"There's a sucker born every minute" - P.T. Barnum
 
 
  • Post #5
  • Quote
  • Sep 1, 2014 1:19pm Sep 1, 2014 1:19pm
  •  hayseed
  • Joined Nov 2006 | Status: Member | 3,536 Posts
why not just use iexposure..... it's included in the platform......h
//----
Attached Image (click to enlarge)
Click to Enlarge

Name: av.png
Size: 63 KB
to trade and code, keep both simple... no call to impress....h
 
1
  • Post #6
  • Quote
  • Sep 1, 2014 1:43pm Sep 1, 2014 1:43pm
  •  PlanAndTrade
  • | Membership Revoked | Joined Oct 2012 | 64 Posts
Quoting PipMeUp
Disliked
The breakeven price B is given by the following formula where Pi is the entry price for the i-th position and Wi is the lot size of the i-th position. Wi is negative for short and positive for long. In the example: (-0.1 x 1.3500 + 0.25 x 1.3520) / (-0.1 + 0.25) = 1.35333 {image}
Ignored

Thank you that was what i was searching.
 
 
  • Post #7
  • Quote
  • Sep 4, 2014 7:16am Sep 4, 2014 7:16am
  •  PlanAndTrade
  • | Membership Revoked | Joined Oct 2012 | 64 Posts
Hello,

can somebody look to my following calculation and help me to correct it, i am getting a result for Break Even price which is not right, the price must to fall a few pips more to get that trade at break even, but i dont find what i am making wrong:

1. Order one Long with 0.1 lot open at 1.64557 in GBPUSD

2. Order two Short with 0.25 lot open at 1.64476 in GBPUSD

My calculation looks so:

Quote
Disliked
0.1 * 1.64557 = 0,164557
-0.25 * 1.64476 = -0,41119

0.164557 + -0.41119 = -0,246633

0.1 + -0.25 = -0.15

-0,246633 / -0.15 = 1.64422

At 1.64422 the loose from the first order is not recovered, the second order just have open 2 pips above that calculated break even price. But i dont find what i am making wrong in the calculation, does somebody from you know it?
 
 
  • Post #8
  • Quote
  • Sep 4, 2014 8:29am Sep 4, 2014 8:29am
  •  PipMeUp
  • Joined Aug 2011 | Status: Member | 1,305 Posts
At 1.64422
your long is 13.5 pips in loss. -13.5*0.1 = -1.35
your short is 5.4 pips in profit. 5.4*0.25 = 1.35
The difference is certainly due to the spread
No greed. No fear. Just maths.
 
 
  • Post #9
  • Quote
  • Sep 4, 2014 8:40am Sep 4, 2014 8:40am
  •  PlanAndTrade
  • | Membership Revoked | Joined Oct 2012 | 64 Posts
Quoting PipMeUp
Disliked
At 1.64422 your long is 13.5 pips in loss. -13.5*0.1 = -1.35 your short is 5.4 pips in profit. 5.4*0.25 = 1.35 The difference is certainly due to the spread
Ignored
I dont understand what you mean.
How must i calculate it correct?
 
 
  • Post #10
  • Quote
  • Sep 4, 2014 8:50am Sep 4, 2014 8:50am
  •  PipMeUp
  • Joined Aug 2011 | Status: Member | 1,305 Posts
To take the spread into account add the weights and multiply the result by the spread s. Add the result to B.
B + (0.1 + -0.25)s = B - 0.15*s with s in the same unit as the price.
If you have 2 pips of spread, s = 0.0002 and B - 0.15*0.0002 = 1.64419
Does it fix the difference?
No greed. No fear. Just maths.
 
 
  • Post #11
  • Quote
  • Sep 4, 2014 11:36am Sep 4, 2014 11:36am
  •  PlanAndTrade
  • | Membership Revoked | Joined Oct 2012 | 64 Posts
Quoting PipMeUp
Disliked
To take the spread into account add the weights and multiply the result by the spread s. Add the result to B. B + (0.1 + -0.25)s = B - 0.15*s with s in the same unit as the price. If you have 2 pips of spread, s = 0.0002 and B - 0.15*0.0002 = 1.64419 Does it fix the difference?
Ignored
Thanks for the exampel, but i think that can also not be right, because 1.64419 is just one pip below the price i did already calculate, but the break even for that should be anywhere at 1.6435 minimum i think.
 
 
  • Post #12
  • Quote
  • Sep 5, 2014 3:38am Sep 5, 2014 3:38am
  •  PlanAndTrade
  • | Membership Revoked | Joined Oct 2012 | 64 Posts
I have the solution now, you must take the spread, but other way then in your exampel, you need just to substract the spread to the calculated aver age price for sellorders, so the price need to fall then little bit more.
 
 
  • Post #13
  • Quote
  • Sep 5, 2014 3:47am Sep 5, 2014 3:47am
  •  PipMeUp
  • Joined Aug 2011 | Status: Member | 1,305 Posts
When you're net long you look at the bid price because to take profit you sell your position. It is of course the opposite when you're short you buy back your position at the ask price. I suppose you always look at the chart made of the bid prices.
No greed. No fear. Just maths.
 
 
  • Post #14
  • Quote
  • Apr 20, 2018 8:39am Apr 20, 2018 8:39am
  •  TradeToLive
  • | Joined May 2017 | Status: Digging... | 4 Posts
What about comissions+swaps weights? I can't find anywhere the solution. I would really appreciate any help. This is my function without spread/comminsions/swaps:

//+------------------------------------------------------------------+
//| Function: BE Price Average calculation
//+------------------------------------------------------------------+
double PriceAverage()
{
double PriceSum=0;
double LotSum=0;
double PriceSum1=0;
double LotSum1=0;
int count=0;

for (int i=0; i<OrdersTotal(); i++)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
if(OrderSymbol()==Symbol() && OrderType()==OP_BUY)
{
PriceSum+=OrderOpenPrice()*OrderLots();
LotSum+=OrderLots();
count++;
}
if(OrderSymbol()==Symbol() && OrderType()==OP_SELL)
{
PriceSum1+=OrderOpenPrice()*(OrderLots());
LotSum1+=OrderLots();
count++;
}
}
if((LotSum-LotSum1)==0) return(0);
return(NormalizeDouble( (PriceSum-PriceSum1)/(LotSum-LotSum1),Digits ));
}
 
 
  • Post #15
  • Quote
  • Apr 21, 2018 6:53am Apr 21, 2018 6:53am
  •  PipMeUp
  • Joined Aug 2011 | Status: Member | 1,305 Posts
The spread needn't be considered because if you're net long (LotSum>LotSum1) the BE price to compute is on the bid side. And of course if you're short the BE price is on the ask side.

The solution depends on your broker. With some broker you pay the commission when you open the position. With others you paid part at opening and part at closing (round trip). Some other replace the commission by a premium on top of the spread. Yet less and less of them do this so they can advertise lower spread (while they avoid communicating on their commission).

I assume you have got the sum of the commissions cost for all the positions converted in pips of the currency of the positions. I don't know MQL4 enough so I don't know what functions are to be called for this (*). If you're net long you add the result to the target (the value you currently return). If net short you substract.

Overnight rates also vary depending on your broker and time (week-end, wednesdays, bank holidays) and of course rates change. Because the swap increase over time you can't return a single value. The result is a stair-step function. In backtest you need the historical swap rates.



(*) if used during a backtest this function must use historical exchange rate. To speed-up the simulation set the currency of the simulated account to the same as the instrument so the conversion is always 1.
No greed. No fear. Just maths.
 
 
  • Post #16
  • Quote
  • Edited at 7:18am Apr 22, 2018 5:58am | Edited at 7:18am
  •  TradeToLive
  • | Joined May 2017 | Status: Digging... | 4 Posts
Thank you for your reply PipMeUp.

The current function serves me just fine; its accuracy is within 5 pips which is understandable because of stacking spread cost, especially when the number of total positions grows. So I’m not really looking for a 100% solution.

What I really want is to figure out the formula for using the sum of the commission and swap costs (already converted in pips), as a weight, for a more accurate representation of the average price for all open positions (buy and sell).

As you have mentioned earlier in this post about using spread as weight, I would like some help figuring out the formula to integrate it into my function, please.
Quoting PipMeUp
Disliked
To take the spread into account add the weights and multiply the result by the spread s. Add the result to B. B + (0.1 + -0.25)s = B - 0.15*s with s in the same unit as the price. If you have 2 pips of spread, s = 0.0002 and B - 0.15*0.0002 = 1.64419 Does it fix the difference?
Ignored
Since I already have the value converted in pips, let’s call it TotalCost, how do I integrate TotalCost into this formula as weight?

(PriceSum-PriceSum1)/(LotSum-LotSum1)

Thank you!
 
 
  • Post #17
  • Quote
  • Apr 23, 2018 5:37am Apr 23, 2018 5:37am
  •  PipMeUp
  • Joined Aug 2011 | Status: Member | 1,305 Posts
That was only to try and understand the difference PlanAndTrade was having in his calculation. This is not to put in the formula. I guess he used the mid-price instead of the bid and the ask separately. I asked him to check if this could explain the difference.
No greed. No fear. Just maths.
 
 
  • Post #18
  • Quote
  • Feb 3, 2021 1:57am Feb 3, 2021 1:57am
  •  sonnyhs
  • | Joined Sep 2010 | Status: Member | 14 Posts
Here I attach Price Average Line which calculate all open order Buy/Sell also OrderSwap() + OrderCommission()
Attached Image (click to enlarge)
Click to Enlarge

Name: 5ee31681eb96508cfc10639d827e0df5.png
Size: 97 KB
Attached File
File Type: ex4 HS Price Average_v1.ex4   35 KB | 165 downloads
Trending is the most important thing to make profit
 
1
  • Post #19
  • Quote
  • Edited at 4:31am Feb 3, 2021 4:17am | Edited at 4:31am
  •  sonnyhs
  • | Joined Sep 2010 | Status: Member | 14 Posts
Quoting sonnyhs
Disliked
Here I attach Price Average Line which calculate all open order Buy/Sell also OrderSwap() + OrderCommission() {image} {file}
Ignored
The calculate always update according to price movements, P/L in currency base will move with Close Price, while Pip calculation number will stay with price average line.
The calculation purpose only for trade on your currency chart you open.
If there is Hedge condition BuyLots()==SellLots(), it will appears information on the chart.
And if there is no Open Orders, the information will disappear.
Trending is the most important thing to make profit
 
 
  • Post #20
  • Quote
  • Feb 14, 2021 2:51am Feb 14, 2021 2:51am
  •  sonnyhs
  • | Joined Sep 2010 | Status: Member | 14 Posts
Quoting sonnyhs
Disliked
Here I attach Price Average Line which calculate all open order Buy/Sell also OrderSwap() + OrderCommission() {image} {file}
Ignored
Here is some update .... revise of the equation
Attached File
File Type: ex4 HS Price Average_v2.ex4   36 KB | 233 downloads
Trending is the most important thing to make profit
 
1
  • Trading Discussion
  • /
  • How to calculate average price for open orders
  • Reply to Thread
    • Page 1 2
    • Page 1 2
0 traders viewing now
  • More
Top of Page
Forex Factory Blog Updated: Alerting All Members
  • Facebook
  • Twitter
About FF
  • Mission
  • Products
  • User Guide
  • Media Kit
  • Blog
  • Contact
FF Products
  • Forums
  • Trades
  • Calendar
  • News
  • Market
  • Brokers
  • Trade Explorer
FF Website
  • Homepage
  • Search
  • Members
  • Report a Bug
Follow FF
  • Facebook
  • Twitter

FF Sister Sites:

  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Forex Factory® is a brand of Fair Economy, Inc.

Terms of Service / ©2022