I figure out an solution, which may not be the best but I think in principle should work.... Can any expert in the group confirm if this is right?
The idea is to calculate the breakeven price as a simple weighted average of price by volume. Concurrently, then we sum up the costs of swaps for all entries.
Once the cumulative swap is calculated, such a cost is converted to ticks, which are added to the breakeven price in the case of longs, or subtracted in the case of shorts.
Basically, given the volume of the entries, how much the price would have to move to cover the costs of swaps...such as an additional price movement is added to the Breakeven price... code below...
double BreakEvenPrice(string PairName, string PositionType) { double Capital=0; // Hold variable of the entry price by the volume purchased double Volume =0; // Volume double Swap=0; // hold the swap cost, which is in the account currency for (int i = 0; i < PositionsTotal(); i++) { if (PositionGetSymbol(i) ==PairName && (PositionType=="Longs" && PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY)) { Capital += PositionGetDouble(POSITION_PRICE_OPEN)*PositionGetDouble(POSITION_VOLUME); Volume += PositionGetDouble(POSITION_VOLUME); Swap += PositionGetDouble(POSITION_SWAP); } } //--- Prevent division by zero if(Volume==0) {return(0.0);}; //--- Breakeven price without swap costs double BE_Price= Capital/Volume; //--- accounting for swaps: amount price needs to correct to recover costs from swaps long nDigits=SymbolInfoInteger(PairName,SYMBOL_DIGITS); int PipAdjust = 0; if(nDigits==5 || nDigits==3) {PipAdjust=10;}; if(nDigits==4 || nDigits==2) {PipAdjust=1;} double TickValue = SymbolInfoDouble(PairName,SYMBOL_TRADE_TICK_VALUE) * PipAdjust; double TickSize = SymbolInfoDouble(PairName,SYMBOL_TRADE_TICK_SIZE) * PipAdjust; double CostExtension = Swap/(Volume*TickValue)*TickSize; BE_Price = PositionType=="Longs" ? BE_Price + CostExtension : BE_Price - CostExtension; return(BE_Price); }
Hi
The idea with swap divided by volume seems to be correct.
I would only include in the calculations (for both BE and those added costs) the pip value – since the profit depends on the value of pip for the symbol and account currency.
Best Regards

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Would anyone know how to incorporate into a breakeven price calculation the swaps of the given positions?
I am working on the function below, which calculate the BE price of positions of a given pair in a given direction, but I have not figure out a simple way to add the losses from swaps into that price..