How to calculate entry price + 1 pip + commission costs

Created at 27 Jun 2019, 08:04
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
FI

firemyst

Joined 26.03.2019

How to calculate entry price + 1 pip + commission costs
27 Jun 2019, 08:04


Hi everyone:

I have a formula where when a position is in profit by x-amount of pips, I want to move the SL to a "break even" point (including commissions) plus 1 pip.

Example: if Entry price is $5, commission each way is $1, and 1 pip is $0.50, then the "break even" point would be:

5 + ABS($1 * 2) + (1 * $0.50) == $7.50.

I have the following, but it doesn't seem to be working quite as expected as sometimes (depending on the symbol) when it's moved and I check in cTrader, the line on the chart says, "0.4" pips (above the entry point) for the SL, whereas it should always show at least "1.0".

Here's what I have for "buy long" trades. My gut feeling is it's not 100% correct, but I can't seem to find what's wrong with it either:

//calculate the value of 1 pip + the commission cost (both ways)
double adjustment = (Symbol.PipSize * 1) + (Math.Abs(p.Commissions) * 2 * Symbol.PipValue);
//I also had the following:
//double adjustment = (Symbol.PipSize * 1 * Symbol.PipValue) + (Math.Abs(p.Commissions) * 2 * Symbol.PipValue);

//add it onto the entry price
double newSL = entryPrice + adjustment;

//modify the position to the new price
TradeResult r = p.ModifyStopLossPrice(newSL);

 

Any help would be appreciated.

Thanks!

 


@firemyst
Replies

firemyst
27 Jun 2019, 10:20

I believe I have figured it out.

I believe the calculation should be the following:

double adjustment = (Symbol.PipValue * 1) + (((Math.Abs(p.Commissions) * 2) / Symbol.PipSize) * Symbol.PipValue);

But if anyone else thinks otherwise, I'm definitely open.

Thanks!


@firemyst

firemyst
28 Jun 2019, 11:56

This is correct:

//For Buy orders
double pipsToBreakEven = ((Math.Abs(p.Commissions) * 2) * Symbol.PipSize);
double priceAdjustment = (Symbol.PipValue * additionalPips) + pipsToBreakEven;
double newSL = p.EntryPrice + priceAdjustment

 


@firemyst