Norgate Data Norgate Data
 

AmiBroker FAQ

General

I receive an "Error 30. Syntax error" in my AFL - how do I fix this?
My charts only show a limited amount of data - how do I fix this?
My charts show non-trading days such as weekends and holidays - how do I remove them?
I see gaps in Markets/Groups - how do I remove them?
I see the last date as a future date on my weekly/monthly charts or in my analyses - how do I fix this?
What names should I use for dynamic/static variables in the VarSet and StaticVarSet functions?
When I use printf(FullName()) or printf(Name()) in my code I receive an "Invalid Parameter Exception". How can I avoid this?

Plugin

I have clicked "Install Plugin" under Integration > AmiBroker but continue to see that the plugin hasn't been installed. What could be wrong?
The entire status bar including the MAINT button is missing. How can I restore it?

Database

How do I find the location of my AmiBroker/NorgateData database folder?
My AmiBroker/NorgateData database is no longer updating. What's the first thing I should check?
Why does AmiBroker frequently show that "MAINT" is required?
Why won't Database Maintenance start when I right-click on "MAINT"?
How do I incorporate data from elsewhere into the AmiBroker/NorgateData database?
How do I create a fresh Symbols list in the AmiBroker/NorgateData database?
How do I create a fresh instance of the NorgateData database in AmiBroker?

Watch Lists

How do I re-order the Watch Lists? (I would like to move my favourite Watch Lists to the top).
What is the best way to reference Watch Lists in AFL?
How do I bring in my personal Watch Lists from another AmiBroker database?
What's the difference between a "static" Watch List created by AmiBroker and one created by NDU for use in AmiBroker?
I've created a Watchlist using NDU and it doesn't appear in AmiBroker. What do I need to do?

System Testing

How can I increase the speed of AmiBroker Scans/Explorations/Backtests?
How do I exit a position in a backtest prior to a stock being delisted?
Why does my trading system backtest only give signals from a particular date onwards rather than from the start of the backtest?
When I loop through all stocks as part of a ranking or static variable creation (StaticVarAdd), my code does not seem to include all securities. How do I fix this?
Why do I get "Error 47" on a backtest? (I am using SetForeign/RestorePriceArrays)
When backtesting Futures, I receive the error message "not entered because requested size is less than minshares/minposvalue" or "not entered because of insufficient funds or wrong position size/value". How do I fix this?
My trading system backtest shows a different sequence of trades than previously recorded. How could that be possible?
My trading system backtest results are different from one PC to another. What are possible reasons for this?
My trading system shows trades with anomalous position values and profit levels. How do I fix this?
My trading system gives anomalous results when using AmiBroker's Pad & Align setting. How do I fix this?
Why does the current bar show in a chart, but an exploration can only see the previous day?
When using GetOption("FilterIncludeWatchlist") only one watchlist is that I have included is provided. Is there an alternative method I can use?

Help

Where can I get help on using AmiBroker?



I receive an "Error 30. Syntax error" in my AFL - how do I fix this?

When running your AFL if you receive an "Error 30. Syntax error, identifier '<function_name>' is undefined" this is usually because you are missing the #include_once line as outlined here.

My charts only show a limited amount of data - how do I fix this?

There is a setting in AmiBroker for "Number of bars". Click File > Database settings to increase the number of bars.

My charts show non-trading days such as weekends and holidays - how do I remove them?

There is a setting in Amibroker to "Pad non-trading days". Select the View menu and make sure that this setting is unticked.
There is also a setting in the Norgate Data plugin to control Date Padding. To check the current setting, click File > Database settings > Configure.

I see gaps in Markets/Groups - how do I remove them?

Click on the icon to the right of the Symbols Search arrow in AmiBroker and a drop-down box will appear. Make sure that "Hide empty markets" and "Hide empty groups" are ticked.

I see the last date as a future date on my weekly/monthly charts or in my analyses - how do I fix this?

This problem can occur when certain settings for weekly or monthly bar dates generated by AmiBroker are used.
To fix this, in AmiBroker go Tools > Preferences > Intraday and:

What names should I use for dynamic/static variables in the VarSet and StaticVarSet functions?

AmiBroker has a strict requirement that variable names only contain the following characters: A-Z, 0-9 and _. If you try to include portions of the current symbol in the variable name you will receive errors on some symbols such as BRK.B, ARNC-, $SPX etc.

You can use a simple string substitution to ensure that your variable names follow the AmiBroker requirements, eg:

        varname = "myvar_" + Name();
        varname = StrReplace(varname,".","_");
        varname = StrReplace(varname,"-","_");
        varname = StrReplace(varname,"#","_");
        varname = StrReplace(varname,"$","_");
        varname = StrReplace(varname,"@","_");
        varname = StrReplace(varname,"%","_");
        

When I use printf(FullName()) or printf(Name()) in my code I receive an "Invalid Parameter Exception". How can I avoid this?

The printf function is designed to print a formatted string with arguments defining the format and the output. The AmiBroker website has detailed information on the printf function.

A problem arises if the output contains the % character, as this character can be misinterpreted as the beginning of a formatting sequence. A number of symbols in NDU's Economic database use the % character to indicate "interest rate" - for instance, %TYX (US 30-Year T. Bond Yield). To avoid problems with symbols or names containing the % character, you should specify the format on the printf call by stating that a string is expected. Usage examples:

        printf("%s",Name());
        printf("Symbol: %s",Name());
        printf("Security name: %s",FullName());
        

I have clicked "Install Plugin" under Integration > AmiBroker but continue to see that the plugin hasn't been installed. What could be wrong?

You may have copied the AmiBroker folder over from another machine without actually installing AmiBroker. If so, you will need to run AmiBroker setup. See How to migrate AmiBroker to a new computer for more information.

The entire status bar including the MAINT button is missing. How can I restore it?

You may have inadvertently turned off the Status Bar. Within AmiBroker, click View -> Toolbars -> Status Bar to restore it.

How do I find the location of my AmiBroker/NorgateData database folder?

The location is recorded by NDU. Open NDU and click on Integration > AmiBroker. (You should exclude this folder from real-time Anti-virus/malware checking for best performance).

My AmiBroker/NorgateData database is no longer updating. What's the first thing I should check?

Check to see that the database still has the Norgate Data plug-in assigned as its data source (File > Database settings).

Why does AmiBroker frequently show that "MAINT" is required?

Maintenance is flagged as being required even if just a single bit of "background" information changes. NDU supplies fundamentals, metadata and dynamic Watch Lists for stocks (in addition to price and volume data), so there are many bits of information that can change.

Why won't Database Maintenance start when I right-click on "MAINT"?

The currently-selected (active) symbol may be an imported symbol where "Use only local database" is set to "Yes". Navigate to a non-imported symbol (one supplied by Norgate Data) and try again.

How do I incorporate data from elsewhere into the AmiBroker/NorgateData database?

AmiBroker allows you to import data into a database (for instructions, refer to the AmiBroker Knowledge Base), download external data using AmiQuote or create composite securities. However, any securities created using this method will be removed from the NorgateData database each time you run "Database Maintenance" unless one of the following conditions is met:

If you are creating your own Composite securities within AmiBroker, you must use the CategoryAddSymbol() function to put your new composite security into one or more of the above categories. e.g.:

        CategoryAddSymbol(Name(),CategoryMarket,201);
        CategoryAddSymbol(Name(),CategoryGroup,201);
If you are using the ASCII Import Wizard, you can use the following lines to assign a stock to a particular market/group:
        $MARKET 201
        $GROUP 201
        $USEONLYLOCALDB 1
The "Use only local database" setting is required, otherwise the data will not be saved into the database correctly.

If you have manually created a new symbol in AmiBroker, you will need to view the Information for that symbol (Window > Symbol Information) and set "Use only local database" to "Yes". The Market and Group should also be set to 201 or higher.

An alternative to storing data in a security is to store them within Static Variables. A worked example of this can be found on the AmiBroker forum: Using eTables with AmiBroker. If you decide to use Static Variables, ensure your naming convention conforms to AmiBroker's requirements: What names should I use for dynamic/static variables in the VarSet and StaticVarSet functions?

How do I create a fresh Symbols list in the AmiBroker/NorgateData database?

You may want to create a fresh Symbols list if some empty symbols have found their way into the database and can't be removed. Firstly, close AmiBroker. Then navigate to the database folder using Windows (File) Explorer and delete the file "broker.master". This file will be re-built when AmiBroker is next opened.

How do I create a fresh instance of the NorgateData database in AmiBroker?

You may want to do this if the existing database appears to have become corrupted in some way.

Step 1: Confirm the location of the AmiBroker NorgateData database folder.
This information is shown in NDU under Integration > AmiBroker.

Step 2: Ensure that the AmiBroker NorgateData database is not the default AmiBroker database.
If required, change the default database path and then close AmiBroker.

Click here for more information

Step 3: Use Windows Explorer to rename the existing database folder.
For instance, rename "c:\Program Files\AmiBroker\Databases\ABNorgateData" to "c:\Program Files\AmiBroker\Databases\ABNorgateData (old)".
Do this to preserve information in the old database folder that you may wish to copy across to the new one - for instance, "WatchLists" and "Layouts".

Step 4: Create a new NorgateData database in AmiBroker.
Follow the database creation instructions on this page.

How do I re-order the Watch Lists? (I would like to move my favourite Watch Lists to the top).

There is a file called "index.txt" associated with every AmiBroker database. This file is found in the "WatchLists" sub-folder (e.g. "c:\Program Files\AmiBroker\Databases\ABNorgateData\WatchLists"). To re-order your Watch Lists, first of all make sure that AmiBroker is closed. Then open the index.txt file and change the order of the entries (make sure to move the entries rather than copy them, as the system cannot tolerate duplicates). Alternatively, if you just want to reorder the watchlists alphabetically, just delete the index.txt file.

What is the best way to reference Watch Lists in AFL?

We recommend the use of the InWatchListName function to reference Watchlists in AFL code as opposed to using Watchlist numbers. This is because Watchlist numbers are problematic in the face of changes to the Watchlist order or removal of Watchlists.

InWatchListName("watchlist name here")
An alternative to using the InWatchListName function is to use the Watchlist Name to look up the Watchlist number as follows:
wlnumber = CategoryFind("watchlist name",categoryWatchList)

How do I bring in my personal Watch Lists from another AmiBroker database?

Each AmiBroker database folder has its own "WatchLists" sub-folder. This sub-folder contains *.tls files. Copy the relevant *.tls files from one "WatchLists" sub-folder to the other.

What's the difference between a "static" Watch List created by AmiBroker and one created by NDU for use in AmiBroker?

The list created by AmiBroker will not reflect a symbol change should it occur.

I've created a Watchlist using NDU and it doesn't appear in AmiBroker. What do I need to do?

Run database maintenance in AmiBroker

How can I increase the speed of AmiBroker Scans/Explorations/Backtests?

Click here for detailed solutions

How do I exit a position in a backtest prior to a stock being delisted?

Assuming a trade delay of 1 bar, you need to have an "exit" signal on the second last bar to simulate exiting a delisted stock. This will cause AmiBroker to exit the position on the final day of trading. You also want to avoid entering any new positions during the final 2 days.

OnSecondLastBarOfDelistedSecurity = !IsNull(GetFnData("DelistingDate")) AND (BarIndex() == (LastValue(BarIndex()) -1) OR DateTime() >= GetFnData("DelistingDate") ) ;
OnLastTwoBarsOfDelistedSecurity = !IsNull(GetFnData("DelistingDate")) AND (BarIndex() >= (LastValue(BarIndex()) -1) OR DateTime() >= GetFnData("DelistingDate") );

Buy = Buy AND NOT OnLastTwoBarsOfDelistedSecurity;
Sell = Sell OR OnSecondLastBarOfDelistedSecurity;

// If you have a short selling system you will also need to include the following:

Short = Short AND NOT OnLastTwoBarsOfDelistedSecurity;
Cover = Cover OR OnSecondLastBarOfDelistedSecurity;
        

Note on "future leaks"

Why does my trading system backtest only give signals from a particular date onwards rather than from the start of the backtest?

If you are using any sort of rotational backtest or ranking backtest (where you iterate through each stock and generate rankings at the start of the test), AmiBroker will use the start date of the first security in the exploration or backtest. When you are testing against listed and delisted stocks that have different IPO dates and delisting dates, it may be very difficult to find a security that traded for every day of the backtest period. There are at least two ways of solving this issue.

Click here for detailed solutions

When I loop through all stocks as part of a ranking or static variable creation (StaticVarAdd), my code does not seem to include all securities. How do I fix this?

The reason and fixes are the same issue as the previous question/answer.

Why do I get "Error 47" on a backtest? (I am using SetForeign/RestorePriceArrays)

In AmiBroker versions prior to v6.13, when SetForeign is used, AmiBroker needs to keep the contents of the foreign symbols in its in-memory cache. If the number of foreign symbols accessed exceeds the cache size then error 47 will be given. You should increase the In-memory cache size in Tools > Preferences > Data. Ensure that "max. symbols" and "max. MegaBytes" have enough size to cache all symbols. Alternatively, upgrade to AmiBroker v6.20.1 or above.

When backtesting Futures, I receive the error message "not entered because requested size is less than minshares/minposvalue" or "not entered because of insufficient funds or wrong position size/value". How do I fix this?

Futures can only be traded in whole contracts (i.e. "round lots"), so the RoundLotSize in AmiBroker is set to 1 (unlike stocks where RoundLotSize=0). Backtests on Futures can be quite sensitive to this setting.

Here are some things that you can check:

My trading system backtest shows a different sequence of trades than previously recorded. How could that be possible?

It may be that price and/or volume corrections have been published for one or more stocks. Corrections for many stocks may need to be published if there has been a significant disruption to trade processing at the exchange level. However, these events are rare. Or it may be that a price and/or volume correction has been published for a particular stock. We receive corrections automatically from upstream and publish them automatically. These corrections are not rare but neither are they frequent. Almost invariably, when we receive a query about whether a stock price has changed, it hasn't.

It may also be that a stock that previously qualified for inclusion in an exploration or backtest no longer does. This could be because the stock has been delisted and your subscription only provides access to currently-listed securities. But there are other circumstances that can produce disqualification.

Say, for example, that your universe is limited to Nasdaq stocks. You run the test on day 1 and stock XYZ produces a buy. Then the stock switches its listing to NYSE. You run the test again on day 2 and the buy for XYZ disappears from the list. The same could apply if stocks were qualified by sector/industry membership. There is no "point-in-time" historical record for such changes in the NDU database.

This could also apply to index membership. Say, for example, that your universe is limited to Russell 1000 stocks. Stock XYZ qualifies for the test on day 1 but then falls out of the index and no longer qualifies when you run the test again on day 2. This particular circumstance can be avoided if your subscription is at the Platinum level (or above) which allows reference to the NorgateIndexConstituentTimeSeries function. In other words, the NDU database does contain a "point-in-time" historical record of changes to index membership (for a number of important indices).

A similar thing could apply if stocks were qualified by absolute price value. Say, for example, that your trade entry is limited to stocks trading above $5. Stock XYZ qualifies on day 1 by trading at $8 but then undergoes a 2:1 stock split. The historical split-adjusted price becomes $4 and the stock no longer qualifies. Hint: Use NorgateOriginalCloseTimeSeries().

Furthermore, there may be other subtle (and hard to track) events that occur in a database that might result in a different trade sequence and therefore provide different subsequent compounding/capital availability. For example, if your trading system doesn't employ any sort of mechanism to rank which trades to take (aka position score), and it has more trade signals than available capital to fill all positions (or has a position limit) then AmiBroker will use the alphabetical symbol as a rank. In this scenario, if a symbol change is received and causes the stock ABCD to become WXYZ, and the signal for WXYZ happens to fall on a day when there are too many trades signalled, then that trade will not occur in the backtest. This will have knock-on effects to available capital and trade sequences.

AmiBroker has its own information about changing results here: Why do backtest results change?

AmiBroker gives the option to track backtesting trades/results with a "Detailed Log" which may help to ascertain the reason for any change.

My trading system backtest results are different from one PC to another. What are possible reasons for this?

Before comparing results -

  1. Make sure that the two machines have been brought up-to-date to the exact same point, with respect to both NDU data updates and AmiBroker database maintenance.
  2. Check that the Norgate Data plugin settings are the same. To check the settings, open the NorgateData database in AmiBroker and click File > Database settings. Take a note of the "Number of Bars". Then click "Configure" and note the settings for "Data Padding" and "Price & Volume Adjustment".
  3. Check that the AmiBroker Preferences settings are identical (Tools > Preferences). In particular, check the settings for -
    Currencies > Base currency
    Intraday > START time of interval (recommended)
    Intraday > Override:Weekly/monthly bars use day of last trade.
  4. Check that the AmiBroker Analysis/Backtester settings are identical. You can save these settings to a .APX file and then compare the APX files from both machines. Further information can be found in the AmiBroker Knowledge Base article How to synchronize backtesting setup on different computers.

My trading system shows trades with anomalous position values and profit levels. How do I fix this?

AmiBroker returns the results from backtesting in the selected "base currency". It converts the currency from the security's trading currency to the base currency at each point of the trade to determine the Position Value and Profit/Loss amounts. In AmiBroker go Tools > Preferences > Currency and set the base currency as required (eg: Australian traders may want to select AUD).

My trading system gives anomalous results when using AmiBroker's Pad & Align setting. How do I fix this?

When there is no trading on a particular day, the "Pad and align data to reference symbol" setting in AmiBroker copies the entire OHLC from the previous bar to the current day. The AmiBroker backtester also allows trades to be taken on padded dates.

The Norgate Data plugin takes a different approach to date padding. When used, if there are no trades on a given date the previous Close (only) is copied to the OHLC fields of the padded day and the Volume is set to zero.

To determine whether a given date is padded in the data set, you can use the NorgatePaddingStatusTimeSeries() indicator. This can be used in your Buy, Sell, Short and Cover rules to prevent a trade signal from being generated on a padded date. To make of use it, simply add the following to your trade condition:

AND NorgatePaddingStatusTimeSeries()==0
        

Why does the current bar show in a chart, but an exploration can only see the previous day?

This can occur when you use Pad & Align with multiple markets - referencing a symbol from one market that has a different set of dates than the current chart. For example, you are looking at an Australian stock, but your Pad & Align field is set to use a US stock index like $DJI which hasn't yet traded for that date. For any exploration, you should set the Pad & Align field appropriately and save your analysis settings into its own .apx file.

When using GetOption("FilterIncludeWatchlist") only the watchlist is that I have included is provided. Is there an alternative method I can use?

The AmiBroker function will not show more than one watchlist. As an alternative, create a "Combined" watchlist inside NDU's Watchlist Library, which combines multiple watchlists into a single item, and refer to that single combined watchlist in Amibroker instead.

Where can I get help on using AmiBroker?

For help with using AmiBroker see the AmiBroker website and the official AmiBroker forum. The AmiBroker staff are quick to respond to support emails.

There are also some AmiBroker user forums on the Internet including the Unofficial AmiBroker Users Forum.

For books that refer to using AmiBroker, see the list provided by AmiBroker.

Should you require it, paid assistance is also available from: