{"id":31,"date":"2006-08-09T02:56:17","date_gmt":"2006-08-09T07:56:17","guid":{"rendered":"http:\/\/www.amibroker.com\/kb\/2006\/08\/09\/amibroker-for-forex\/"},"modified":"2017-06-14T12:01:22","modified_gmt":"2017-06-14T11:01:22","slug":"amibroker-for-forex","status":"publish","type":"post","link":"https:\/\/www.amibroker.com\/wordpress\/kb\/2006\/08\/09\/amibroker-for-forex\/","title":{"rendered":"AmiBroker for Forex"},"content":{"rendered":"

Here is an article that tells you everything you need to know about using AmiBroker for trading FOREX markets. <\/p>

I.\u00a0DATA<\/strong><\/p>

AmiBroker is very flexible as regards the datasources that can be used to feed data to the program.<\/p>

1) Realtime data<\/p>

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:<\/p>

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

\u00a0<\/p>

2) AmiQuote downloader<\/p>

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).<\/p>

AmiQuote can download the quotations for the following currency pairs:
EURCHF,EURGBP,EURJPY,EURUSD,GBPUSD,USDCHF,USDJPY<\/p>

The download process is shown in the video:
http:\/\/www.amibroker.net\/video\/forex.html<\/a><\/p>

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\u00a0 vendor’s\u00a0 server just rejects all the requests for intraday quotes.<\/p>

3) Text files.<\/p>

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.<\/p>

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

II.\u00a0 SYMBOL GUIDE<\/strong><\/p>

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.<\/p>

Here you will find the links to the most popular vendors guidlines:<\/p>

– eSignal:
http:\/\/www.esignalcentral.com\/support\/symbol\/symbol_format.asp#forexGarban<\/a>
http:\/\/www.esignalcentral.com\/support\/symbol\/forex.asp<\/a><\/p>

– IQFeed:
http:\/\/www.iqfeed.net\/symbolguide\/index…<\/a><\/p>

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

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:<\/p>

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\u00a0 is one the following: STK – stocks, FUT – futures, FOP – options on
futures, OPT – options, IND – indexes, CASH -cash (ideal FX)<\/p>

\u00a0<\/p>

III. CHARTING<\/strong><\/p>

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\u00a0 in Preferences dialog in:<\/p>

Tools -> Preferences -> Miscellaneous<\/p>

<\/p>

The changes will also affect such tools as Fibonacci Extension or Retracement drawing tools.<\/p>

\u00a0<\/p>

\u00a0<\/p>

IV. SCANNING and DATA EXPLORATIONS <\/strong><\/p>

AmiBroker allows you to perform sophisticated scanning and data explorations (both in realtime and\u00a0with use\u00a0of\u00a0historical quotes). To perform\u00a0data analysis\u00a0and 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<\/a><\/p>

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\u00a0AddColumn()<\/a><\/strong> 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.\u00a0If we use:<\/p>

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

AddColumn( Close, “Close”, 1.2);<\/strong>
then AB will display only 2 decimals.<\/p>

To perform the test –\u00a0it’s necessary to do the following:
– open the Formula Editor (Analysis -> Formula Editor)
– enter the formula:
Buy <\/span>= <\/span>Cross<\/span>( <\/span>MACD<\/span>(), <\/span>Signal<\/span>() );
<\/span>Sell <\/span>= <\/span>Cross<\/span>( <\/span>Signal<\/span>(), <\/span>MACD<\/span>() );
<\/span>Filter <\/span>= <\/span>Buy <\/span>OR <\/span>Sell<\/span>;
<\/span>AddColumn<\/span>( <\/span>Close<\/span>, <\/span>"Close"<\/span>, <\/span>1.4<\/span>)<\/code>– Tools -> Send to Auto-analysis
– select the time-range of the exploration
– press EXPLORE<\/p>

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

V. BACKTESTING<\/strong><\/p>

NOTE: Unless otherwise noted, all examples below assume you trade full size contracts.<\/em><\/p>

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:
<\/p>

Round lot size<\/strong>\u00a0should be\u00a0equal to 1\u00a0<\/p>

–\u00a0Tick size<\/strong> should be set to pip value<\/strong>\u00a0equal 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).<\/p>

Point\u00a0value<\/strong> 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: <\/p>

\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 PointValue = profit\/movement = 10$ \/ 0.0001\u00a0 =\u00a0 100000<\/p>

–\u00a0Margin Deposit<\/strong> in most cases should be set to 1000 (1% margin from $100’000)<\/p>

\u00a0<\/p>

1) Currencies denominated in USD<\/p>

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

– open the Formula Editor (Analysis -> Formula Editor)
– enter the formula:
Buy <\/span>= <\/span>Cross<\/span>( <\/span>MA<\/span>(<\/span>Close<\/span>, <\/span>12<\/span>) , <\/span>MA<\/span>( <\/span>Close<\/span>, <\/span>24<\/span>) );
<\/span>Sell <\/span>= <\/span>Cross<\/span>( <\/span>MA<\/span>(<\/span>Close<\/span>, <\/span>24<\/span>) , <\/span>MA<\/span>( <\/span>Close<\/span>, <\/span>12<\/span>) );
<\/span>SetPositionSize<\/span>(<\/span>3<\/span>, <\/span>spsShares <\/span>)<\/code>

\u00a0– choose: Tools -> Send to Auto-analysis<\/p>

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.<\/p>

<\/p>

\u00a0<\/p>

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,\u00a0All quotations<\/strong><\/p>

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

NumContracts * (SellPrice – BuyPrice) * PointValue<\/strong>
\u00a0<\/p>

\u00a0<\/p>

In the first transaction:
– the Entry Price<\/strong> is equal to 1.2154<\/strong>
– the Exit Price<\/strong> is equal to 1.2304<\/strong>
NumContracts<\/strong> =\u00a03<\/strong> (since we trade\u00a03 contracts).
–\u00a0we\u00a0trade on 1% margin<\/strong> so deposit is $1,000 x\u00a03 = $3,000<\/strong> (that’s expressed in Position Value<\/strong>)<\/p>

Profit<\/strong> = 3 * (1.2304 – 1.2154) * 100’000 = 4’500<\/strong><\/p>

So – the profit matches the results we’re getting by manual calculation.<\/p>

2) Currencies denominated in a different currency from USD (assuming that your account is in USD)<\/p>

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

These settings can be defined in: Tools -> Preferences -> Currencies <\/strong>dialog.<\/p>

<\/p>

AmiBroker allows to use both fixed\u00a0and dynamic (historical) quotes for backtesting purposes\u00a0(using dynamic quotes will allow you to check the real influence of the currency rates changes\u00a0for your trades denominated in different currencies).\u00a0<\/p>

There are following requirements to use currency adjustements:
a) Symbol->Information, “Currency<\/strong>” 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.<\/p>

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

For the same reason –\u00a0if 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).<\/p>","protected":false},"excerpt":{"rendered":"

Here is an article that tells you everything you need to know about using AmiBroker for trading FOREX markets.<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[51,14,15,54,22],"_links":{"self":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/31"}],"collection":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/comments?post=31"}],"version-history":[{"count":2,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/31\/revisions"}],"predecessor-version":[{"id":1419,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/31\/revisions\/1419"}],"wp:attachment":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/media?parent=31"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/categories?post=31"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/tags?post=31"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}