| / | Articles |
Articles
Features
Forex Trading ABC
To post a new article, please log in or register
|
Forex Trading ABC [ ru | cn ]IntroductionWorking 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
Our TimesNowadays, 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
Standard Contract Size - Standard Lot
EURO= k*USD
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
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 DeterminationExample: 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
MarketInfo(Symbol(), MODE_DIGITS); For instance, function MarketInfo("GBPJPY", MODE_DIGITS); will return 2. MarketInfo(Symbol(), MODE_POINT); For currency pairs, values of functions MarketInfo(Symbol(), MODE_POINT); and MarketInfo(Symbol(), MODE_TICKSIZE); 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. Margin per Lot
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
//+------------------------------------------------------------------+ //| SimplySpecification.mq4 | //| Copyright © 2007, MetaQuotes Software Corp. | //| http://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: http://articles.mql4.com/ru/304
Warning:
All rights to these materials are reserved by MetaQuotes Software Corp.
Copying or reprinting of these materials in whole or in part is prohibited.
|