MQL5 Pip Value Calculator
Post id: 39, 2022/05/10
Why this is importance?
Normally, the profit can be calculated from this formula…
Profit = (Close_Price - Open_Price) * Lot_Size / Point
Point is ONE PIP IN DECIMALS
Digits = 5
Point = 1 / pow(10, Digits)= 1/100000 = 0.00001
NOTE: You can find Digits and Contact_Size in symbol specification
Example
BUY - EURUSD @1.05400 lot 1.00 ==> Close @1.05500 Digits = 5
Point = 1 / pow(10, Digits)= 1/100000 = 0.00001
Profit = (1.05500 - 1.05400) * 1 / 0.00001 = 100
But…. , this formula can be used with the symbol which based on USD only such as EURUSD, GPBUSD, XAUUSD, AUDUSD, NZDUSD etc.
If you trade with another symbol, you cannot use this formula
This is the full form of profit calculation formula
Profit = (C_Price - O_Price) * Lot * Pip_Value / Point
What is Pip value?
You must have base currency in your port such as USD, EUR, AUD but as you know, forex symbol is the pair of 2 currencies for example
EURUSD = EUR/USD
*(USD is base currency of this symbol)
When you trade this symbol, Profit or Loss of this symbol will be converted to your port currency.
If your port currency is USD, this case will be…
Currency_base => Port_Currency
USD => USD = 1
this convert factor called pip value
If you convert same currency, pip value will be 1.00
But of difference currency, the pip value will calculate from…
Pip_value = Point * Contact_Size / Exchange_Rate
and
Exchange_Rate = port_currency / base_currency
for example
EURUSD => base is “USD”
Port currency is BALANCE UNIT in your port, in this case is “USD”
Exchange_Rate = USD/USD = 1
so, for symbo “EURUSD” pip value is…
Contact_Size = 100000
Digits = 5
Point = 1/pow(10, Digits)= 1/100000 = 0.00001
Exchange_Rate = USD/USD = 1
Pip_value = Point * Contact_Size / Exchange_Rate
Pip_value = 0.00001*100000/1 = 1
Calculation Example
NOTE: assume our port currency is “USD”
Example 1: Calculate pip value of symbol “USDJPY”
Base currency = JPY
Digits = 3
Contact_Size = 100000
Point = 1/pow(10, Digits)= 1/1000 = 0.001
Exchange_Rate = USD/JPY = 130.015 (Current price of symbol USDJPY)
Pip_value = Point*Contact_Size/Exchange_Rate
Pip_value = 0.001*100000/130.015 = 0.7691
That mean, if you open BUY “USDJPY” @130.000 Lot 1.00 and Close @130.100 the profit is…
Lot = 1.00
O_Price = 130.000
C_Price = 130.100
Profit = (C_Price - O_Price)*Lot*Pip_Value/Point
Profit = (130.100-130.000)*1.00*0.7691/0.001 = 76.91 USD
As you see, We earn profit 100 Point same as before example (EURUSD example) but we can earn profit only 76.91 USD
Example 2: Calculate pip value of symbol “EURGBP”
Base currency = GBP
Digits = 5
Contact_Size = 100000
Point = 1/pow(10, Digits)= 1/1000 = 0.00001
Exchange_Rate = USD/GBP = ???
We don’t have symbol “USDGBP” but we have “GBPUSD” so we must convert “GBPUSD” to “USDGBP”
GBPUSD = GBP/USD
GBPUSD = 1.23200 (Current price)so...
1*GBP = 1.23200*USDor...
1*USD = 1*GBP/1.23200 = 0.8117 * GBPor...
USDGBP = 0.8117so...
Exchange_Rate = USD/GBP = 0.8117Pip_value = Point*Contact_Size/Exchange_Rate
Pip_value = 0.00001*100000/0.8117 = 1.2320
That mean, if you open BUY “EURGBP” @1.23200 Lot 1.00 and Close @1.23300 the profit is…
Lot = 1.00
O_Price = 1.23200
C_Price = 1.23300
Profit = (C_Price - O_Price)*Lot*Pip_Value/Point
Profit = (1.23300-1.23200)*1.00*1.2320/0.00001 = 123.20 USD
As you see, We earn profit 100 Point again but we get profit 123.20 USD
How to use?
Assume balance in your port is 10,000 USD. If you want to trade BUY “USDJPY” with Stop Loss 500 Point and risk 1% how to calculate lot size?
Port balance = 10,000
SL = 500 Point
Risk 1% = 1*Balance/100 = 100 USD
That means you accept maximum loss of this order is 100 USD
from profit formula…
Loss = (C_Price - O_Price)*Lot*Pip_Value/Pointor...
Lot = Point*Loss/((C_Price - O_Price)*Pip_Value)so...
SL = C_Price - O_Price = 500 Point
Loss = 100 USD
Pip_value = 0.7691 (from example 1)Lot = Point*Loss/((C_Price - O_Price)*Pip_Value)
Lot = Point*100/(500*Point)*0.7691
Lot = 100/(500*0.7691) = 0.26
- NOTE: Profit and Loss use same formula
So the answer is Lot = 0.26
MQL5 Code
This is the final mql5 code
Example
trade_sym = "USDJPY"
Open_Price = 130.035
SL_Price = 129.750
Lot = calLotSize(Open_Price, SL_Price);