looking for sample code on how to calculate the price BE for a few Buy and Sell orders simultaneously

 

hi all

I'm looking for sample code,  or an explanation, on how to calculate the price Break Even for a few Buy and Sell orders simultaneously

 

basically this is the scenario

1 Sell order of 1 lot, 1 Buy order 50 pip above the sell order of 1,5 lots at which level i will Reach the break even? 

keep in mind that i could have multiple sell order and multiple buy orders... 

any idea? 

 
didjeridoo: 1 Sell order of 1 lot, 1 Buy order 50 pip above the sell order of 1,5 lots at which level i will Reach the break even?
  1. Volume weighted average price. Sum[ OrderLots * (OrderType == OP_BUY ? +1 : -1) * OrderOpenPrice ] / Sum[ OrderLots * (OrderType == OP_BUY ? +1 : -1) ] if denominator is zero, no solution, e.g. buy 1 sell 1, hedging, any price.
  2. BEprice = [1 * (-1) * 1.2345 + 1.5 * (+1) * 1.2395] / [1 *(-1) + 1.5 * (+1)] = 0.62475 / 0.5 = 1.2495.
    profit= -1* DeltaPerlot * (1.2495-1.2345) + 1.5 * DeltaPerlot * (1.2495-1.2395) = DeltaPerlot *[ -1 * 0.0150 + 1.5 * 0.0100 ] = DeltaPerlot * [ -0.015 + 0.015 ] = 0
Reason: