Profit and Loss formula

Greetings… I’ve been here coding a trading strategy and I’m having a total brain lapse. Can someone help me determine my P&L? Here is the information I have.

Initial Price
Units
Spread
Close Price

I know I can “guestimate” my P&L from these variables but what is the formula? Also I’m aware that units is either positive or negative depending on if I’m long or short.
Your thoughts? thanks in advance
Scott

(Intial Price-Close Price-Spread)*Units will do it won’t it?

1 Like

He didn’t ask about it

Thanks I knew it had to be simple but after thousands of programming lines I just sit and drool sometime, lol. Now I have it in the core code and now have to chase down my own calculation issues of when it is Bid and when it is Ask. That debugging will be tomorrow!

Thanks my friend.
Scott

Hi Scott,

• You can ignore the spread.

The difference between your entry price and your exit price is pure profit (or loss) expressed as a fraction of the quote currency. The spread is in there already, and does not have to be accounted for separately, in the formula you are developing.

Example: if you enter LONG at 1.5100 and exit at 1.5150, you have captured 0.0050 (50/10,000) of one unit of the quote currency, regardless of the spread, which you overcame in order to move into profit.

Similarly, if you enter SHORT at 1.5100 and exit at 1.5150, you have taken a loss of -0.0050 (negative 50/10,000) of one unit of the quote currency, and that loss includes the spread.

• If your account is denominated in USD, and if USD is the quote currency in the pair you are trading, then this simple formula will work –

P/L = [Exit price - Entry price] x Units

Note that Units are positive (for LONG) or negative (for SHORT), and this yields the P/L as positive (for profit) or negative (for loss).

Example: Suppose you traded LONG one standard lot (100,000 units) of the pair XXX/USD, with entry at 1.5100 and exit at 1.5150

P/L = [1.5150 USD - 1.5100 USD] x 100,000
= [0.0050 USD] x 100,000
= 500 USD. This positive figure is your profit, stated in your account currency.

Similarly, if you were SHORT, with the same entry and exit prices, and the same position size, then the formula would look like this –

P/L = [1.5150 USD - 1.5100 USD] x [-100,000]
= [0.0050 USD] x [-100,000]
= - 500 USD. This negative figure is your loss, stated in your account currency.

• If the quote currency (call it YYY) in the pair you are trading is not USD, then you have to convert the calculated P/L to USD using the current exchange rate of USD versus YYY.

It’s simple enough to get the current USD/YYY or YYY/USD price (whichever is the correct form for this pair). But, it can be tricky to remember whether to multiply or divide by this price.

Here are the rules for converting P/L in YYY to P/L in USD –

  1. If the correct form is USD/YYY = price, then divide by that price.

  2. If the correct form is YYY/USD = price, then multiply by that price.


Let’s use real pairs and realistic prices to illustrate how these conversions are done.

Let’s say you enter LONG one standard lot of EUR/AUD at 1.6074, and you exit at 1.6134. The simple formula given above obviously will yield P/L in terms of AUD (the quote currency of the pair traded). You want to convert this P/L to USD. The conversion factor must equate the USD to the AUD, and the correct form for the pair is AUD/USD (not the other way around).

In other words, rule 2, above, applies in this case, and you will multiply the P/L (in the simple formula) by the current price of AUD/USD. Let’s say the price of AUD/USD was 0.7609 at the time your EUR/AUD trade was closed.

The P/L for this trade can now be found, as follows –

P/L = [Exit price - Entry price] x Units x [price of AUD/USD]
= [1.6134 AUD - 1.6074 AUD] x 100,000 x 0.7609
= 456.54 USD

Another example –

Let’s say you enter SHORT one standard lot of EUR/JPY at 126.57, and you exit (at a loss) at 126.83. At the time you were stopped out, the price of USD/JPY was 103.25.

The P/L for this trade involves dividing by the USD/JPY price, according to rule 1, above –

P/L = [Exit price - Entry price] x [-Units] / [price of USD/JPY]
= [126.83 JPY - 126.57 JPY] x [-100,000] / 103.25
= - 251.82 USD (negative figure denotes loss)

1 Like

Hi! I’m certain you will find some valuable information and advice on your trade here. This is a good community, good luck.