GeneralMy 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 some strange Time Series indicator values 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?
DatabaseHow 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/Norgate database?
How can I create a fresh NorgateData database in AmiBroker?
With "Configure NorgateData plug-in" and the options for "Price & Volume Adjustment", what events count as "Capital reconstructions" and "Special Distributions"?
Watch ListsHow 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 TestingHow 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?
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?
HelpWhere can I get help on using AmiBroker?
There is a setting in AmiBroker for "Number of bars". Click File > Database settings to increase the number of bars.
There is a setting in Amibroker to "Pad non-trading days". Select the View menu and make sure that this setting is
There is also a setting in the Norgate Data plugin to control Date Padding. To check the current setting, click File > Database settings > Configure.
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.
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:
- set "Time stamp of compressed intraday bars shows:" to "START time of interval (recommended)", and
- check "Override: Weekly/monthly bars use day of last trade."
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,"%","_");
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).
Check to see that the database still has the Norgate Data plug-in assigned as its data source (File > Database settings).
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.
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.
AmiBroker allows you to import data into a database (for instructions, refer to the AmiBroker Knowledge Base). However, imported symbols will be removed from the NorgateData database each time you run "Database Maintenance" unless at least one of the following conditions is met:
- Market ID > 200
- Group ID > 200
- Symbol starts with a tilde "~"
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 1The "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.
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.
Step 1: Ensure that the AmiBroker NorgateData database is not the default AmiBroker database.
If required, change the default database path and then close AmiBroker.
Step 2: Confirm the location of the AmiBroker NorgateData database folder.
This information is shown in NDU under Integration > AmiBroker.
Step 3: Use Windows Explorer to rename the existing folder.
For instance, rename "c:\Program Files\AmiBroker\NorgateData" to "c:\Program Files\AmiBroker\NorgateData (old)".
It is advisable to rename the existing folder rather than just delete it, in case there are Watch Lists and/or other information that you wish to preserve and transfer to the new database folder.
Step 4: Create a new NorgateData database in AmiBroker.
Follow the database creation instructions on this page.
Capital reconstructions include splits & consolidations (reverse splits), capital returns, bonus issues (stock
dividends) and right issues.
Special distributions include special dividends and distributions associated with spin-offs.
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\NorgateData\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).
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)
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.
The list created by AmiBroker will not reflect a symbol change should it occur.
Run database maintenance in AmiBroker
- Put your data onto a secondary SSD drive (or purchase an SSD drive to replace your main system drive). Solid State Drives increase performance significantly.
- Upgrade to the Professional Edition of AmiBroker, which can utilize all of the processing cores on your CPU (backtesting with the Standard edition of AmiBroker is limited to two simultaneous threads).
- Install a 64-bit version of Windows so that you can use the 64-bit version of AmiBroker Professional Edition. 64-bit CPU operations are significantly quicker than 32-bit. The 64-bit Professional Edition of AmiBroker can also better utilize all available RAM.
- Prevent your antivirus scanner from doing real-time scanning on your data folders (i.e. exclude both the NDU database and your AmiBroker database from real-time scanning). Since the data folders do not contain any executable files that need constant monitoring, this significantly decreases the CPU load by bypassing the virus checking on these large folders. You can determine your NDU database location by starting NDU and clicking the Database tab. You can determine your AmiBroker database location(s) by starting NDU and clicking Integration->AmiBroker
- Change the AmiBroker settings for "In-memory cache size". These settings are established under Tools > Preferences > Data. If you have at least 2GB of RAM, you could increase "Max. MegaBytes" to 1000. The 64-bit version of AmiBroker allows even higher settings. For instance, you could use a setting like 6000 MB given something like 16 GBs of RAM. As long as all of the data can fit into RAM, the second run (and all subsequent runs) will go very fast. You can monitor AmiBroker's cache usage by clicking Tools > Performance Monitor. The setting for "Max. Symbols" may also be increased to the limit of 20,000. However, a run should never be performed on more symbols than is necessary (see below).
- Where applicable, use "Filter" to restrict your runs to a pre-defined universe of symbols. For instance, when using the NorgateIndexConstituentTimeSeries function to run a back-test against the constituents of a particular index, use "Filter" to select the relevant Watch List for that index. This will provide a faster result than running the test against all symbols.
- Where applicable, when creating a database, set the "numbers of bars" to the lowest possible value. For instance, if a scan or exploration only requires 12 months of data, change the "number of bars" accordingly (File > Database settings). 12 months is approximately 250 bars. For backtesting you will probably want a higher number of bars to test against. Note: Once initially set, AmiBroker will not reduce the number of bars in its cache, so lowering the number will not subsequently help. It may be easier to have one database for scans, and one for backtesting.
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;
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.
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:
- Do you have enough equity to cover the margin required for a round lot?
- What is your base currency set to (Tools > Preferences > Currencies)? If your base currency is different to the currency of the Futures contract then your available equity may have been reduced due to the currency conversion.
You may be testing on a particular class of stocks where membership of the class is not fixed and no information exists
as to historical membership. For instance, you may be testing on "Nasdaq" stocks. If a stock that was previously listed on
Nasdaq changes to NYSE, then any trades previously recorded for the stock will disappear from the backtest. Similarly, if
you are backtesting on stocks in a particular sector or industry.
Further information can be found in the AmiBroker Knowledge Base article Why do backtest results change?
Before comparing results -
- 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.
- 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".
- 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.
- 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.
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).
For help with using AmiBroker see the AmiBroker website.
The AmiBroker staff are also quick to respond to support emails.
Some good books have been written on AmiBroker by Howard Bandy: Introduction to AmiBroker, Quantitative Trading Systems and Advanced AmiBroker.
There are also some AmiBroker user forums available on the Internet -
AmiBroker Yahoo Group,
and the Unofficial AmiBroker Users Forum.
Should you require it, paid assistance is also available from AmiBrokerCoding.Com, TheChartist and Alvarez Quant Trading.