Forex Trading ABC

MetaQuotes | 11 July, 2007

Introduction


Working on financial markets represents, first of all, trade operations. We all, starting from the very childhood, have an intuitive idea of what is to buy and to sell. But Forex trading is still something special. This article deals with the ideas necessary to explain some terms. We will also consider the MQL4 functions that correspond with those terms.

A Bit of History


We know from our history textbooks that money was not used in ancient times – there were natural economies and direct barter of products. Genesis (invention) of money itself became a great step forward for the human history. It allowed people to exchange practically everything using one universal article of merchandise - the money. While the form of that universal exchange article varied from country to country and from epoch to epoch, money was always a rather rare article that could be broken into parts and also could be stored and transported easily, for example, gold or silver. And, of course, every country now has both its own history and customs and its own currency - a form of monetary resources. But already in remote antiquity, there were trading relations between countries, and merchants carried their goods from one country to sell them in another country. The goods were exchanged for either local goods or a universal equivalent, for instance, coined gold.

Our Times


Nowadays, precious metals are not practically used as a payment vehicle, so countries use exchange rates in their payments. The exchange rate sets the price of a currency unit of one country in currency units of another country. For example, the rate of EUR/USD being equal to 1.25 means that for one euro you can get 1.25 US dollars. Thus, for any two freely convertible currencies it is possible to calculate their exchange rate. Large foreign exchange is usually performed by banks in import/export operations, so it became necessary to introduce standard currency pairs and standard amounts to be exchanged. The name of a currency pair (a financial instrument, symbol) in the MetaTrader 4 Client Terminal is written as a combination of currency name abbreviations. For example, EURUSD is the rate of euro in US dollars, GBPJPY - British pounds in Japanese yens, i.e., the first currency is always defined in terms of the second one.

Deposit Currency


Though it is possible to make trades using various currency pairs, the trading result is always written in only one currency - the deposit currency. If the deposit currency is US dollar, profits and losses will be shown in US dollars, if it is euro, they will be, of course, in euros. You can get information about your deposit currency using the AccountCurrency() function. It can be used to convert the trade results into deposit currency.

Standard Contract Size - Standard Lot


When exchanging one currency for another one, they use the notion of "lot". Lot is the amount of goods bought or sold. A lot can have different values for different currency pairs. At present, the most currency pairs have the lot value equal to 100 000 (One hundred). But 100 000 of what? When we buy, we give money for goods. When we sell, we get money for goods. But with currencies, we buy and sell simultaneously since we get one currency for another one. This is why it is common practice to consider that we get the first currency of the pair when we buy and give, respectively, the second currency. A standard lot for EURUSD is 100 000 euros. If we buy one standard lot of EURUSD, it means that we get 100 000 euros and give a number of US dollars. Since receipts and payments must always be equal, 100 000 euros = X US dollars. How can we calculate the amount of US dollars then? Let's replace euros with US dollars in the expression:

EURO= k*USD
where k is the exchange rate of EURUSD;
100 000 (k*USD) = X USD => X= k*100 000;
if the current exchange rate of EURUSD is 1.25, then X=125 000.


Thus, having bought one lot of EURUSD, we get 100 000 euros and give 125 000 US dollars. They sometimes say - euros were bought and US dollars were sold which means EURUSD was bought. You can get information about the price of a standard lot for a currency pair from the contract specification, as well as using the MarketInfo() function, for example:



MarketInfo(Symbol(), MODE_LOTSIZE);

You can also give the text name of a currency pair, and function


MarketInfo("EURUSD",  MODE_LOTSIZE);

will return 100 000. It is written in the Help files: MODE_LOTSIZE is the contract size in the symbol base currency. The base currency for EURUSD is EUR (*). The base currency for CHFJPY is Swiss franc, and the price of one lot will be expressed in Swiss francs, respectively.


Trade Result



Let's consider another example. We bought 1 lot of EURUSD at 1.2500. The current price is 1.2600, so we decided to close the trade, i.e., sell 1 lot of EURUSD.

Write down the Balance:

Buying 1 lot of EURUSD at 1.2500 (opened a trade): + 100 000 euros - 125 000 US dollars.
Selling 1 lot of EURUSD at 1.2600 (close the trade): - 100 000 euros + 126 000 US dollars.
Resulting profit of the operation: 0 EURO + $ 1000.

Conclusion: Profit resulting from the operation on EURUSD is expressed in US dollars, i.e., in the second currency of the currency pair. Try to calculate the results of another trade by yourself: 1 lot of GBPCHF was bought at 2.30 and closed at 2.40. What profit will be obtained as a result and n what currency?


Leverage and Margin


Trading on financial markets is attractive for it allows traders to profit from leverage. In our example with buying one lot of EURUSD, we would have to have over 100 000 US dollars (125 000 at the rate of 1.25). Most brokers allow traders to use so-called 'leverage'. The value of leverage shows how many times less capital should be available to open a position. The amount of money necessary to open a position is named margin. Without leverage, one lot of EURUSD costs 100 000 euros, or 125 000 US dollars at the rate of 1.2500. If your broker provides you with the leverage of 100, the amount of money necessary to open a position will be decreased 100 times and make 1250 US dollars. The profit we have already calculated remains the same. You can see the leverage value on a given trade account using function AccountLeverage(). Thus, the margin for opening one lot is defined as:

Margin (in the symbol base currency) = Lot price (in the symbol base currency) / Leverage_size.

Price of the symbol base currency in terms of the deposit currency is the ratio between the symbol base currency and the deposit currency.


Margin Determination


Example:

MarketInfo("GBPJPY", MODE_LOTSIZE) gives the value of 70 000 (LS).
AccountCurrency() returns "EUR" (AC).
AccountLeverage() returns 50 (AL).
How can we calculate the price of the GBPJPY contract at the present moment (M)?

Base currency is GBP, so
M = 70000 GBP / AL = 70 000*GBPEUR / AL = 70000 / EURGBP / AL.

If the rate of EURGBP is 0.6786 at the moment, then
M = 70000 / 0.6786 / 50 = 2063.07 EURO.

If the leverage is equal to 100, the margin will be two times smaller - 1031.54 euros. For a leverage of ten, the margin will be:

M = 70000 / 0.6786 / 10 = 10315.36.


Thus, the leverage size influences only the margin size necessary to open a position, but does not impact the profit size obtained when trading by one contract. It should also be reminded that the margin size in euros (deposit currency) will fluctuate together with the EURGBP rate since the symbol base currency is British pound. In our example, we replaced GBPEUR with 1/EURGBP since there is only symbol EURGBP available.



Point - The Minimal Price Change


Currency pairs on Forex differ from each other not only by their special movements, but also by the number of decimal places in their rates. For example, the rate of GBPJPY, as of the 29th of December 2006, made 233.18, while the close price of GBPUSD was 1.9587 on the same day. The amount of decimal places (accuracy) can be set using function

MarketInfo(Symbol(), MODE_DIGITS);

For instance, function

MarketInfo("GBPJPY", MODE_DIGITS);

will return 2.

Correspondingly, the minimal price change for different currency pair will differ, too. This value is usually equal to 0.01 for pairs including yens, for EURUSD it makes 0.0001. The value of the minimal price change in the quote currency is named Point, and it can be obtained using function:

MarketInfo(Symbol(), MODE_POINT);

For currency pairs, values of functions

are the same.


Point Price in Deposit Currency


To evaluate risks, the trader must know the size of loss for an open position when price is moving to a certain amount of points. Or vice versa, calculate the acceptable loss size in points on the loss size in money terms. For this purpose, he or she can use function

MarketInfo(Symbol(), MODE_TICKVALUE);
that returns one-point value in the deposit currency.
It must be reminded that one-point price will change for currency pairs, the second value of which is not deposit currency.

Margin per Lot


The last function considered,

MarketInfo(Symbol(), MODE_MARGINREQUIRED);

returns the amount of free assets necessary to open a one-lot buying position, i. e., one standard lot price at the Ask price.

Exemplary Use of Functions Considered Above


Below you can see the script that shows data for functions considered above on twelve currency pairs. It must be noted that custom function MarginCalculate() of this script returns the price of one standard lot at the Bid price (selling price). The script below allows one to learn how to apply MQL4 functions to use in Expert Advisors algorithms of Money Management and Risk Management.


//+------------------------------------------------------------------+
//|                                          SimplySpecification.mq4 |
//|                      Copyright © 2007, MetaQuotes Software Corp. |
//|                                       https://www.metaquotes.net/ |
//+------------------------------------------------------------------+
string SymbolsArray[13] = {"","USDCHF","GBPUSD","EURUSD","USDJPY",
"AUDUSD","USDCAD","EURGBP","EURAUD","EURCHF","EURJPY","GBPJPY","GBPCHF"};
//+------------------------------------------------------------------+
//| string SymbolByNumber                                            |
//+------------------------------------------------------------------+
string GetSymbolString(int Number)
  {
//----
   string res = "";
   res = SymbolsArray[Number];   
//----
   return(res);
  }
//+------------------------------------------------------------------+
//| A very simple function to calculate margin for Forex symbols.    |
//| It automatically calculates in the account's base currency and   |
//| does not work for complicated rates that do not have direct      |
//| recalculation into the trade account's base currency.            |
//+------------------------------------------------------------------+
double MarginCalculate(string symbol, double volume)
  {
   string first    = StringSubstr(symbol,0,3); // the first symbol, for example,  EUR
   string second   = StringSubstr(symbol,3,3); // the second symbol, for example, USD
   string currency = AccountCurrency();        // deposit currency, for example,  USD
   double leverage = AccountLeverage();        // leverage, for example,          100
// contract size, for example, 100000
   double contract = MarketInfo(symbol, MODE_LOTSIZE);
   double bid      = MarketInfo(symbol, MODE_BID);      // Bid price
//---- allow only standard forex symbols like XXXYYY
   if(StringLen(symbol) != 6)
     {
      Print("MarginCalculate: '",symbol,"' must be standard forex symbol XXXYYY");
      return(0.0);
     }
//---- check for data availability
   if(bid <= 0 || contract <= 0) 
     {
      Print("MarginCalculate: no market information for '",symbol,"'");
      return(0.0);
     }
//---- check the simplest variations - without cross currencies
   if(first == currency)   
       return(contract*volume / leverage);           // USDxxx
   if(second == currency)  
       return(contract*bid*volume / leverage);       // xxxUSD
//---- check normal cross currencies, search for direct conversion through deposit currency
   string base = currency + first;                   // USDxxx
   if(MarketInfo(base, MODE_BID) > 0) 
       return(contract / MarketInfo(base, MODE_BID)*volume / leverage);
//---- try vice versa
   base = first + currency;                          // xxxUSD
   if(MarketInfo(base, MODE_BID) > 0) 
       return(contract*MarketInfo(base, MODE_BID)*volume / leverage);
//---- direct conversion is impossible
   Print("MarginCalculate: can not convert '",symbol,"'");
   return(0.0);
  }
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----
   for(int i = 1; i < 13; i++)
     {
      Print("Symbol=",GetSymbolString(i),"  spread=",MarketInfo(GetSymbolString(i),
      MODE_SPREAD),"  margin at 1 lot=",MarginCalculate(GetSymbolString(i),1),
      "  MODE_TICKVALUE=",MarketInfo(GetSymbolString(i),MODE_TICKVALUE),
      ", MODE_TICKSIZE=",MarketInfo(GetSymbolString(i),MODE_TICKSIZE),
      " MODE_MARGINREQUIRED=",MarketInfo(GetSymbolString(i),MODE_MARGINREQUIRED));
     } 
//----
   return(0);
  }
//+------------------------------------------------------------------+

* In most cases, the symbol's base currency is the first currency in the currency pair, but there can be different server settings, of course.


Translated from Russian by MetaQuotes Software Corp.
Original article: /ru/articles/1453