# How to calculate pip value in currency account (USD, EUR etc) some bars ago or some time ago?

**Toyota:**

Hi,

Using SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_VALUE) I can get pip value only for current time but I cannot do it in past. (SYMBOL_TRADE_TICK_VALUE is a on the standard lot, in the currency of the account. For instance is 1$ in USD currency account at EURUSD, if the lot is 100000, with 5 digits, or 10$, for 4 digits. I think it is not possible to get the same information using standard mql5 function in past time for example 100 bars ago or 1 hour ago. Can you give me some piece of advice how to solve this problem in custom indicator? I need it to calculate pip value for risk in past for statistic but I do not know how to synchronize the same time because some bars are lacking in some pairs of currency so using the same amount of bars in past is the wrong.

Very welcome

If you want precision, you cannot do that with OHLC history prices, you don't know that exact time these prices occur. If you can live with some impreciseness, you can use OC.

Otherwise you need to record the prices of each involved pairs, to calculate a TICK_VALUE yourself. An other way is to record SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_VALUE) itself.

**angevoyageur:**

If you want precision, you cannot do that with OHLC history prices, you don't know that exact time these prices occur. If you can live with some impreciseness, you can use OC.

Otherwise you need to record the prices of each involved pairs, to calculate a TICK_VALUE yourself. An other way is to record SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_VALUE) itself.

Dear people,

Since this question remained with no conclusive answer, for all the “google searchers” I wanted to add something.

1. Sometimes it was asked, as an answer to this and similar questions, why one would be interested in knowing the “pip-value in the past”. Answer is quite easy: this is for instance necessary in risk management schemes based on “exposure”. And, if you want to position-size trades according to such risk management also in back-tests, then the past pip-value is requested.

2. Out of doubt that the built-in SymbolInfoDouble enums (SYMBOL_TICK_VALUE & family) are useless in this respect, because they calculate pip-value (in account currency) *just* for the **current tick**.

3. Here I show an algorithm for calculating the pip-value in any account currency in any time in history (included “now”) based just on the exchange rates of the involved currencies. This is valid just for FX. Demonstration is left to the reader for avoiding too long explanations. Eventually ask.

4. Warning: since calculations are based on ratios, don’t expect *absolute precision*. Numbers will be identical just about the third significant digit, due to rounding problems. Further, suggested calculations will involve the exchange rates at a given point in time, like, typically, the open or close of a particular bar. OHLC quotes are sufficient.

Then, here we go.

Let’s call the account currency **acc_cy** (like “EUR”);

Let’s call **bse **and **qte** the base currency and the quote currency of a pair, like bse = EUR; qte = USD for EURUSD.

Let’s call **R (bse/qte) ** the exchange rate **at a given point in time (even in the past)** of a currency whit base = bse and quote = qte. Like for instance R (EUR/USD) or R (USDJPY) . (Important that the two belong to the exact same time point).

Let’s call **s (bse/qte) ** the tick size of the bse/qte currency. We can calculate tick value as such or have pip value if we multiply for the “pip-multiplier” that expresses the number of points in one pip (typically 10 for 5/3-digit brokers).

And here the algorithm (in “pseudo-code”: I cannot post implementation which makes use of a lot of proprietary-library methods)

a. First I would check that the passed-in pair exists in its “direct form” and not in the “reverse”, and eventually “normalize” it. E.g. USDAUD will be converted in AUDUSD. Buying or selling a currency against the other does not change the pip value (i.e. pip value of AUDUSD = pip value of USDAUD, because buying one means selling the other…). And other similar input error checks are left to the reader… Let’s say that all the further calculations are made using a “normalized” bse/qte pair.

b.** if acc_cy == qte, then tick_value = s (bse/qte) **; END. Else:

c. **if acc_cy == bse, then tick_value = s (bse/qte) / R (bse/qte) **; END. Else:

d. “create” pair “**bse/acc_cy**” (e.g. for calculating USDYPJ in EUR, create USDEUR).

e. if “bse/acc_cy” exists as it is, **tick_value = s (bse/qte) * (R (bse/acc_cy) / R (bse/qte) )**. END

f. Otherwise, if bse/acc_cy exists in the REVERSE FORM acc_cy/bse (e.g. above: USDEUR does not exist, but the reverse EURUSD does indeed exist):

**tick_value = s (bse/qte) / (R (bse/qte) * R (acc_cy/bse) )**. END

It might be convenient, for readability, to express the pip value as the value obtained/lost when trading 1 lot (100.000 units), so that we can look at more significant digits.

A similar algorithm could be created if you decide to use qte/acc_cy as a conversion pair for cross-currencies, but one solution is sufficient for solving a problem, and therefore I don’t develop it here.

Beauty of these formulas is that they just depend on one or two exchange rates *at a given point in the past *(or “right now”). And therefore it is sufficient to pick all those rates at the same point in time for having the tick(/pip) value anytime in the past… much better than mql5 built-in functions.

Please correct me if anything is wrong. You can verify that they work by using some online pip-value calculators (e.g. baby-pips) in which you normally have to insert the exchange rates when requested…

Sorry for having posted it here, but since it took me quite some time for coming to this formulation, I thought it was good to save the time to the next interested, and to “carve it on stone” for myself in the future, if needed.

- www.mql5.com

Got back thinking till better to this subject, if anybody is interested.

Input was the fact that, if you use MetaTrader 5, I realized that the backtester, for calculating value in money of tested trades, needs the historical quotes of the conversion pair containing the qte of the original currency, for staying with the nomenclature suggested in the previous post. And, since we must feed the correct historical data before starting the test, it is necessary to include the qte/acc_cy data (i.e. it would be two series, if we want to include also acc_cy/bse, as in the formulas above).

And… with this a big discovery, if moderators allow to insert an external quote here. A nice paper explaining how and why, for calculating even cross-pair pip values, just **ONE** exchange rate is needed. This is the link: https://www.thebalance.com/calculating-pip-value-in-forex-pairs-1031022.

Now, then, the above algorithm becomes much easier and efficient. I keep the same nomenclature above:

a. if acc_cy == qte, then tick_value = s (bse/qte) (* Lots) ; END. Else:

b. if acc_cy == bse, then tick_value = s (bse/qte) / R (bse/qte) (* Lots); END. Else:

c. if (acc_cy != qte && acc_cy != bse):

c1. if acc_cy/qte does exist: pip_val = s (acc_cy/qte) * 1 / (R acc_cy_qte ) (* Lots)

c2. if qte/acc_cy exixst (reverse ratio): pip_val = s (qte/acc_cy) * R qte/acc_cy (* Lots).

This is wonderful and much simpler. And you can try to make some experiments for instance with the babypips calculator. E.g. if you want to calculate pip value of EURGBP in USD, the form asks two exchange rates: EURGBP itself and GBPUSD. Look at what happens, once you have filled the bottom one (GBPUSD), if you start changing the EURGBP rate (the upper one): absolutely **NOTHING**. The pip value remain the same even if you insert an absurd EURGBP rate (try with 5780!).

And, call me dumb, but this is how I realized that a pip in USDJPY and in GBPJPY in EUR have the very same value (which is 1/R EURJPY ).

It takes a long trip to become simple…! My bad.

- www.thebalance.com

- Free trading apps
- Free Forex VPS for 24 hours
- Over 8,000 signals for copying
- Economic news for exploring financial markets

You agree to website policy and terms of use

Hi,

Using SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_VALUE) I can get pip value only for current time but I cannot do it in past. (SYMBOL_TRADE_TICK_VALUE is a on the standard lot, in the currency of the account. For instance is 1$ in USD currency account at EURUSD, if the lot is 100000, with 5 digits, or 10$, for 4 digits. I think it is not possible to get the same information using standard mql5 function in past time for example 100 bars ago or 1 hour ago. Can you give me some piece of advice how to solve this problem in custom indicator? I need it to calculate pip value for risk in past for statistic but I do not know how to synchronize the same time because some bars are lacking in some pairs of currency so using the same amount of bars in past is the wrong.

Very welcome