amibroker

HomeKnowledge Base

AmiBroker for Forex

Here is an article that tells you everything you need to know about using AmiBroker for trading FOREX markets.

I. DATA

AmiBroker is very flexible as regards the datasources that can be used to feed data to the program.

1) Realtime data

Forex traders usually require a realtime datasource and with AB you have a variety of choices.
The exact configuration process depends on the particular source – click on the appropriate link to learn how to configure the source of your choice:

– eSignal – http://www.amibroker.com/video/esignal.html 
– IQFeed – http://www.amibroker.com/iqfeed.html
– Interactive Brokers – http://www.amibroker.com/video/ib.html
– any source that supports DDE standard (this is a generic communication interface, check if your broker’s application supports DDE) – http://www.amibroker.com/dde.html
– any source that delivers the data in MetaStock format – see:
http://www.amibroker.com/guide/h_extsources.html

 

2) AmiQuote downloader

If you do not require realtime quotations, but it’s enough for you to have the historical data (e.g. for backtesting your strategies) – then you can also use AmiQuote downloader program (a companion program that is installed with AmiBroker) and it will allow you to get FREE forex data (both EOD and intraday: 1-, 3-, 5-, 15-, 30-, 60- and 120-minute intervals).

AmiQuote can download the quotations for the following currency pairs:
EURCHF,EURGBP,EURJPY,EURUSD,GBPUSD,USDCHF,USDJPY

The download process is shown in the video:
http://www.amibroker.net/video/forex.html

You need to do the following:
– set up database in AmiBroker (File -> New Database, local database, base
time interval, e.g. EOD)
– run AmiQuote (START -> Programs -> AmiBroker -> AmiQuote )
– add forex symbols in AQ: (Edit -> Add tickers )
– select FOREX as a datasource
– select time range
– check “Automatic Import” field
– choose: File -> Start download
The intraday forex quotes are available in the Registered version of AmiQuote only.
Although the entire data range is very long, you must remember that in case of intraday quotes the saefst way is to get data in small parts, few weeks at a time.
Otherwise the request may be too large for the data server to handle it and as a result it will reject the request.
The other important thing to remember is that the data is not avalable for downloads between 13:00 – 22:00 GMT time (7:00 – 16:00 EST) – in these hours the data  vendor’s  server just rejects all the requests for intraday quotes.

3) Text files.

You can also use any data that comes in the text files. The ASCII Importer available in AmiBroker is very flexible and accepts practically any standard of data.
To import quotations – the most convenient is to use File -> Import Wizard.

To learn more about importing the data from ASCII (text) files – please read the following tutorial:
http://www.amibroker.com/guide/w_impwizard.html
 

II.  SYMBOL GUIDE

Once you configure the database (to read realtime data), then all you need to do is to add the symbol via: Symbol -> New menu and AmiBroker will automatically read the data for the selected symbol. Please note that various datasources have different symbology, so please always refer to the data vendor’s Symbol guide to learn about the required symbol format.

Here you will find the links to the most popular vendors guidlines:

– eSignal:
http://www.esignalcentral.com/support/symbol/symbol_format.asp#forexGarban
http://www.esignalcentral.com/support/symbol/forex.asp

– IQFeed:
http://www.iqfeed.net/symbolguide/index…

– Interactive Brokers:
http://www.amibroker.com/ib.html
In case of Interactive Brokers – if you have any doubt what format to use –
you can easily check any symbol in IB.

Just enter the symbol in Interactive
Brokers TWS, then change the view to Symbol mode
(View -> Symbol mode). Now you can compose the actual symbol out of three
fields:

SYMBOL-EXCHANGE-TYPE
where:
SYMBOL is the same as the symbol column as displayed in TWS while under
symbol mode
EXCHANGE is the exchange d in TWS while under symbol mode
TYPE  is one the following: STK – stocks, FUT – futures, FOP – options on
futures, OPT – options, IND – indexes, CASH -cash (ideal FX)

 

III. CHARTING

Since most currency pairs requires 4 decimals to display the rates properly, it’s necessary to set-up AmiBroker accordingly. The number of decimal places can be defined  in Preferences dialog in:

Tools -> Preferences -> Miscellaneous

The changes will also affect such tools as Fibonacci Extension or Retracement drawing tools.

 

 

IV. SCANNING and DATA EXPLORATIONS

AmiBroker allows you to perform sophisticated scanning and data explorations (both in realtime and with use of historical quotes). To perform data analysis and display the values of chosen indicators in the customized table – we can use Automatic Analysis window. The detailed description on how to perform explorations is available at:
http://www.amibroker.com/guide/h_exploration.html

As a short example – we will find the crossovers of MACD and its Signal line and additionally – display values of the symbol we test. The 3rd parameter of AddColumn() function allows to customize the number of places after decimal point, so it’s possible to specify if we need 2 or 4 decimal places. If we use:

AddColumn( Close, “Close”, 1.4);
then – 4 decimal places will be displayed. On the other hand – if we use:

AddColumn( Close, “Close”, 1.2);
then AB will display only 2 decimals.

To perform the test – it’s necessary to do the following:
– open the Formula Editor (Analysis -> Formula Editor)
– enter the formula:
Buy CrossMACD(), Signal() );
Sell CrossSignal(), MACD() );
Filter Buy OR Sell;
AddColumnClose"Close"1.4)
– Tools -> Send to Auto-analysis
– select the time-range of the exploration
– press EXPLORE

As a result – we will get a list of MACD/Signal crossover points and the value of the chosen symbol on that bar.

V. BACKTESTING

NOTE: Unless otherwise noted, all examples below assume you trade full size contracts.

First of all, it’s necessary to enter the symbol-specific information into Symbol -> Information page (individually for each ticker). In case of currencies denominated in USD (like EURUSD) the following settings should be used:

Round lot size should be equal to 1 

– Tick size should be set to pip value equal 0.0001 for currencies with four decimal digits and to 0.01 for currencies with two decimal digits (so in case of EURUSD it’s 0.0001).

Point value represents value of profit/loss by 1 full point price movement. It can be calculated by dividing value of profit by price movement. So if you trade full size EURUSD contract +0.0001 price movement (one pip) represents $10 profit:

             PointValue = profit/movement = 10$ / 0.0001  =  100000

– Margin Deposit in most cases should be set to 1000 (1% margin from $100’000)

 

1) Currencies denominated in USD

Let’s analyse the results generated by a simple formula (a crossover of 12- and 24-day Moving Averages of Closing price, trading 3 contracts at a time). To perform a backtest – it’s necessary to do the following:

– open the Formula Editor (Analysis -> Formula Editor)
– enter the formula:
Buy CrossMA(Close12) , MAClose24) );
Sell CrossMA(Close24) , MAClose12) );
SetPositionSize(3spsShares )

 – choose: Tools -> Send to Auto-analysis

As a result – the Automatic Analysis window will open. In the settings dialog (SETTNGS button) it’s necessary to turn on the FUTURES MODE (in order to use the information entered into the Information dialog) and define the Initial Equity.

 

then – press OK. In the AA window main screen it’s necessary to define the time range of the backtest and the symbols included in the test. For our example that will be: Current Symbol, All quotations

Then – once everything is configured – press BACKTEST button. Now let’s have a look at the results list.
The profit is calculated as follows:

NumContracts * (SellPrice – BuyPrice) * PointValue
 

 

In the first transaction:
– the Entry Price is equal to 1.2154
– the Exit Price is equal to 1.2304
NumContracts3 (since we trade 3 contracts).
– we trade on 1% margin so deposit is $1,000 x 3 = $3,000 (that’s expressed in Position Value)

Profit = 3 * (1.2304 – 1.2154) * 100’000 = 4’500

So – the profit matches the results we’re getting by manual calculation.

2) Currencies denominated in a different currency from USD (assuming that your account is in USD)

AmiBroker allows you to define a base currency and exchange rates (fixed or dynamic) for different currencies, and as a result – to get correct backtest results when testing securities denominated in different currency than your base portfolio currency.

These settings can be defined in: Tools -> Preferences -> Currencies dialog.

AmiBroker allows to use both fixed and dynamic (historical) quotes for backtesting purposes (using dynamic quotes will allow you to check the real influence of the currency rates changes for your trades denominated in different currencies). 

There are following requirements to use currency adjustements:
a) Symbol->Information, “Currency” field shows currency different than BASE currency
b) Appropriate currency (defined in Symbol-> Information) has matching entry in Preferences->Currencies page
c) the dynamic rate “FX SYMBOL” defined in the preferences EXISTS in your database and HAS QUOTES for each day under analysis range.

“INVERSE” check box for in the preferences should be checked, when testing the FX rates like USDJPY or USDCHF – not denominated in the base currency of the portfolio.

For the same reason – if we look at the example of EURUSD – when “USD” is your BASE currency then EUR exchange rate would be “straight” EURUSD fx (e.g. ~1.25). But when “EUR” is your BASE currency then USD exchange rate would be INVERSE of EURUSD (i.e. ~1/1.25).

3 Responses to “AmiBroker for Forex”

  1. Grant Noble
    August 9th, 2006 | 8:31 pm

    How is Position Value calculated for non-base currency ? For example, base currency AUD and trading EURJPY. This assumes: a)Symbol information/Currency for EURJPY is JPY, b) JPY/AUDJPY/inverse in Prefs/Currencies and c) AUDJPY exists in database

    Further, what additional caculations perform rate-to-base conversions once profit is calculated ? For example, profit in Yen (for EURJPY) back to AUD base ?

    Can you confirm that Point value will (in effect) be the same for any currency, ie.
    EURUSD 10$ / 0.0001 = 100000
    EURJPY 1000Y / 0.01 = 100000

    What exactly does multipler do in Prefs/Currencies?

  2. January 26th, 2007 | 2:54 pm

    AmiBroker first converts appropriate amount of funds from base currency (in your example AUD) to required currency (JPY) at the time of ENTRY using ENTRY day FX RATE.
    Appropriate amount in AUD is subtracted from cash.

    Then at the end of trade it converts back JPY to AUD using EXIT day FX RATE. And profit is returned in base currency (back to cash).

    So TWO different FX rates are used (one for entry and one for exit).

    Point value is in the symbols’ currency. Multiplier practically is for JPY only because Yens are quoted in hundreds against USD and other currencies.

  3. June 15th, 2007 | 11:11 pm

    […] market. They show a basic application with a set-up, as an example of trading currency pairs. AmiBroker Knowledge Base � AmiBroker for FOREX Take a look if you want or have time, like I said very basic but it will give you and idea of how […]