How do we calculate our overall pip total like cTrader does when we have multiple entries on a position?

Created at 17 Jun 2022, 09:05
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 do we calculate our overall pip total like cTrader does when we have multiple entries on a position?
17 Jun 2022, 09:05


How do we calculate our overall pip total like cTrader does when we have multiple entries on a position?

For instance, if I have:
position #1) 10,000 units and am up 20 pips
position #2) 3,000 units up 13 pips
position #3) 4,000 units up 8 pips

how would I calculate the overall amount to get what cTrader would display in the "Pips" column programmatically?

I have a Dictionary object defined as follows which keeps track of the volume I have for each entry. My Dictionary keys start at 1 instead of 0:

private Dictionary<int, double> _positionEntryVolumes;

So:

_positionEntryVolumes[1] == 10000.00

_positionEntryVolumes[2] == 3000.00

_positionEntryVolumes[3] == 4000.00;

I can calculate the difference in pips between the current price and my price entry points (I keep track of those too).

So really just would like to know how to tie it all together to calculate the overall pips like cTrader does.

Thank you.


@firemyst
Replies

amusleh
17 Jun 2022, 10:25

Hi,

Can you tell what do you mean by overall Pips? cTrader Pips column shows the amount of Pips for your Position which you can get via Pips property of a Position.

To calculate it programmatically you can subtract the current price from Position entry price:

        private double GetPositionPips(Position position)
        {
            var symbol = Symbols.GetSymbol(position.SymbolName);

            return Math.Round((position.TradeType == TradeType.Buy ? symbol.Bid - position.EntryPrice : position.EntryPrice - symbol.Ask) / symbol.PipSize, 1);
        }

 


@amusleh

firemyst
17 Jun 2022, 11:25

RE:

amusleh said:

Hi,

Can you tell what do you mean by overall Pips? cTrader Pips column shows the amount of Pips for your Position which you can get via Pips property of a Position.

To calculate it programmatically you can subtract the current price from Position entry price:

        private double GetPositionPips(Position position)
        {
            var symbol = Symbols.GetSymbol(position.SymbolName);

            return Math.Round((position.TradeType == TradeType.Buy ? symbol.Bid - position.EntryPrice : position.EntryPrice - symbol.Ask) / symbol.PipSize, 1);
        }

 

What I mean by overall pips is if my positions are:

1) 10000 units of EURCAD @ 1.3547

2) 1000 units of EURCAD @ 1.3562

3) 1000 units of EURCAD @ 1.36701

and price is currently at 1.35835

I would like to know how to calculate the overall pips value that cTrader displays in the "Pips" column. cTrader shows roughly 24.9 pips profit despite being up 35.6 pips from position 1, 20.5 pips in position #2, -86 pips for position #3.

So how does it calculate 24.9 overall pips between the 3 positions?

Hope that better helps you understand what I'm looking for?

Thank you.


@firemyst

amusleh
20 Jun 2022, 08:48

Hi,

Can you tell me which column you are talking about? I can't find any overall Pips column in cTrader.


@amusleh

firemyst
20 Jun 2022, 10:31

RE:

amusleh said:

Hi,

Can you tell me which column you are talking about? I can't find any overall Pips column in cTrader.

The "Pips" column as per the "Positions" and "History" tabs:

Thank you.


@firemyst

amusleh
20 Jun 2022, 11:02 ( Updated at: 21 Dec 2023, 09:22 )

RE: RE:

firemyst said:

amusleh said:

Hi,

Can you tell me which column you are talking about? I can't find any overall Pips column in cTrader.

The "Pips" column as per the "Positions" and "History" tabs:

Thank you.

Hi,

The method I posted will give you the same value that you see on Pips columns with some fraction error due to rounding or delay.

There is no overall Pips, each position Pips is separate and it's not related to other positions.


@amusleh

firemyst
20 Jun 2022, 11:37 ( Updated at: 21 Dec 2023, 09:22 )

RE: RE: RE:

amusleh said:

firemyst said:

amusleh said:

Hi,

Can you tell me which column you are talking about? I can't find any overall Pips column in cTrader.

The "Pips" column as per the "Positions" and "History" tabs:

Thank you.

Hi,

The method I posted will give you the same value that you see on Pips columns with some fraction error due to rounding or delay.

There is no overall Pips, each position Pips is separate and it's not related to other positions.

 

I don't want the Position's pip value. That's the point I think you're missing or I'm not explaining well.

I want to know how that calculation is done because I want to have an indicator draw other lines at various on the chart with the correct amount of pips written on the line.

The only way I can currently do that is to drag the stop loss line and it will show me the number of pips depending on the price at the location.

Using p.pips only tells me the pips at the current closing price, not at other price levels on the chart, when I have a position with multiple scaled in positions.

Example:

 

 


@firemyst

amusleh
20 Jun 2022, 11:49

Hi,

So you are trying to calculate the Pips for positions that are partially closed or added?

If that's what you are looking to do then you can't, because the API doesn't give you the data for partially closed / added positions.

When you close part of a position or add more volume to it the history is not updated until you close the whole position, nor the positions closed / opened events are triggered.

 

 

 


@amusleh

firemyst
20 Jun 2022, 12:09

RE:

amusleh said:

Hi,

So you are trying to calculate the Pips for positions that are partially closed or added?

If that's what you are looking to do then you can't, because the API doesn't give you the data for partially closed / added positions.

When you close part of a position or add more volume to it the history is not updated until you close the whole position, nor the positions closed / opened events are triggered.

 

 

 

But there's obviously some mathematical formula that's used because cTrader does it.

As I mentioned in my original post, I keep track of each position's volume and entry price that are added (eg, I have my own history), so I should be able to do it before the position is closed just like cTrader.

So, can't you look at cTrader's source code and tell me what formula it's using to do its live calculation? :-)

Thank you.

 


@firemyst

amusleh
20 Jun 2022, 14:29 ( Updated at: 20 Jun 2022, 14:34 )

RE: RE:

firemyst said:

amusleh said:

Hi,

So you are trying to calculate the Pips for positions that are partially closed or added?

If that's what you are looking to do then you can't, because the API doesn't give you the data for partially closed / added positions.

When you close part of a position or add more volume to it the history is not updated until you close the whole position, nor the positions closed / opened events are triggered.

 

 

 

But there's obviously some mathematical formula that's used because cTrader does it.

As I mentioned in my original post, I keep track of each position's volume and entry price that are added (eg, I have my own history), so I should be able to do it before the position is closed just like cTrader.

So, can't you look at cTrader's source code and tell me what formula it's using to do its live calculation? :-)

Thank you.

 

Hi,

The cTrader Pips column shows the different in Pips between position entry price and current price.

If you add new volume to the position then the entry price of position will change, and for Pips it will use the new entry price.

That's how it's calculated on cTrader, so for:

What I mean by overall pips is if my positions are:

1) 10000 units of EURCAD @ 1.3547

2) 1000 units of EURCAD @ 1.3562

3) 1000 units of EURCAD @ 1.36701

and price is currently at 1.35835

cTrader will use 1.36701 as entry price and 1.35835 as current price, the difference will be position Pips, it doesn't take into account the previous entry prices.


@amusleh

firemyst
21 Jun 2022, 11:48 ( Updated at: 21 Dec 2023, 09:22 )

RE: RE: RE:

amusleh said:

Hi,

The cTrader Pips column shows the different in Pips between position entry price and current price.

If you add new volume to the position then the entry price of position will change, and for Pips it will use the new entry price.

That's how it's calculated on cTrader, so for:

What I mean by overall pips is if my positions are:

1) 10000 units of EURCAD @ 1.3547

2) 1000 units of EURCAD @ 1.3562

3) 1000 units of EURCAD @ 1.36701

and price is currently at 1.35835

cTrader will use 1.36701 as entry price and 1.35835 as current price, the difference will be position Pips, it doesn't take into account the previous entry prices.

That can't be totally accurate, because if you look at this capture:

by your last reply, the last entry price is 1.01315, but the position closed closed negative from the last entry, yet it says the overall trade was up 13.5 pips.

So I'm confused because it obviously does take into account the previous price points.

????


@firemyst