Issue 3/2001 (No. 11)
AmiBroker Tips weekly newsletter.
Issue 3/2001. No 11.
22 January 2001.
Copyright (C)2001 Tomasz Janeczko.
All back issues available from:
1 Welcome
2 AFL Library: Ichimoku charts
3 Tip of the week: Database maintenance hints
1 Welcome

Welcome to the 3rd issue of AmiBroker Tips newsletter in the 2001. This week I will present the formula for Ichimoku chart and some database maintenance hints.

Just a reminder: if you have any comments/suggestions or article ideas, please don't hesitate to drop a line to

2 AFL Library: Ichimoku charts

Ichimoku charts - yet another Japanese charting technique is enjoying new wave of popularity. Just a few months ago, in the October 2000 issue of Technical Analysis of Stocks and Commodities (TASC) magazine an article covering this charting method was presented. I will not dig into details - they are described fairly enough in the TASC magazine - instead I am going to focus on AFL implementation, but a bit of introduction is needed:

"Literally, ichimoku means 'one look'; a chart of this style is referred to as [...] the table of equilibrium prices at a glance. [..] All the computations involved no more than taking midpoints of historical highs and lows in various ways. Nevertheless, the completed chart presents a panoramic view of price movement"

OK. This sounds a little bit complicated, but in fact the whole algorithm is not difficult at all. An ichimoku chart consists of:

  1. the standard line calculated as one half of the sum of highest high and lowest low price over past 26 days
  2. the turning line calculated as one half of the sum of highest high and lowest low price over past 9 days
  3. the delayed line which is close price shifted 25 days prior to today
  4. the first preceding span line which is calculated as the average of standard line and turning line and then shifted 25 days ahead of today
  5. the second preceding span line which is calculated as the average of highest high and lowest low prices over past 52 days and then shifted 26 days ahead of today

Implementing above rules in AFL gives the following formula:

SL = ( HHV( H, 26 ) + LLV( L, 26) )/2;
TL = ( HHV( H, 9 ) + LLV( L, 9 ) )/2;
DL = Ref( C, 25 );
Span1 = Ref( ( SL + TL )/2, -25 );
Span2 = Ref( (HHV( H, 52) + LLV(L, 52))/2, -25);

where SL is the standard line, TL - turning line, DL - delayed line, Span1 and Span2 - the first and the second preceding span lines.

To plot the chart we will need additional setup for graph colors and styles:

maxgraph = 6;

graph0 = SL;
graph1 = TL;
graph2 = DL;
graph3 = Span1;
graph4 = Span2;
graph5 = close;

graph0style = graph1style = graph2style = graph3style = graph4style = 1;
graph5style = 5;

graph0color = 7;
graph1color = 5;
graph2color = 13;
graph3color = 6;
graph4color = 6;
graph5color = 2;

The code above uses the same color scheme as presented in TASC except that close price is drawn with black color and thick line. You can change it however by modifying graph5color=2 statement. Note that you should choose Automatic scaling in the Indicator window to chart this one properly. A complete AFL code can be found here.

An ichimoku chart is a trend-following system with an indicator similar to moving averages. As in the moving averages, a buy signal is initiated when the turning line rises above the standard line, and the sell signal is the opposite. For more details please consult the article in the October 2000 issue of TASC magazine.

3 Tip of the week: Database maintenance hints

This week I will cover database maintenance issues. These things are often forgotten but they are very important.

1. Protecting your work by making database backups

Yes, I know you trust AmiBroker performing its tasks well (otherwise you would not register it!), but since there is no perfect software you should protect your data, especially your manually entered information and/or studies, from accidental deletion. It is advised to make a backup of your working database at least once a week. I do not provide any special tool for this task just because it is very simple. All you need to do is to make a copy of your data directory (by default this is Data subfolder of AmiBroker's main directory). You can do this using Windows Explorer by selecting data folder, then choosing Edit->Copy and then browsing to your Backup storage disk and choosing Edit->Paste. You can also use Edit->Copy to folder option available in some versions of the Explorer. Yes, it's that simple. You can also automate this task using your favorite tool (for example Windows Task Scheduler).

If you ever experience data lost (hopefully never) all you need to do is to copy back the folder with all subdirectories to the original location. Please remember to make backups and restores when AmiBroker is NOT running.

2. Managing large databases

If your database consists of 500 stocks this is not an issue at all, but if you have ten times more (5000 stocks or so and 10 years history) it may be worthwhile to perform some maintenance tasks to make your work faster and smoother. The most important issue that slows down database access is the file fragmentation. When your operating system writes a file to the hard drive, it finds the first available sector and begins writing. If the file is larger than that sector then your operating system tries to write in the next contiguous sector. If that sector is already being used by another file, then a "forwarding address" is attached to the file in the current sector and the remaining part(s) of the file is copied into the next available sector. This results in disk fragmentation. Fragments of the file are stored in noncontiguous locations on the hard drive. The read and write of this file would take considerably longer than reading from contiguous sectors, thus slowing performance.

In order to prevent the degradation of the performance you should run a defragmenter program once a week or so. Supplied with Windows is Defrag program that aligns file in a contiguous order. There are however better third-party defragmenters (for example Diskeeper). My tests show however, that defragmentation is performed well by these tools and often one simple method gives better results when it comes to the database loading/saving times. The method is very simple: just copy your database to another location (as you are making a backup copy), then delete the original and rename the copy back to original name. This simple process often gives 20% (or more) speed increase.

Instead of having one large database you can also consider splitting it to a couple of smaller ones.

Another thing that may greatly reduce database loading times are AmiBroker settings that can be found in Tools->Preferences menu, Miscellaneous tab:

If you tick Enable partial database loading box AmiBroker will not load all quotes stored in its files but only defined number of latest quotes (this number is defined in Load upto box). If you have 10 year database enabling this option and specifying 250 (roughly one year) can increase startup time 4 or 5 times. The remaining quotes could be loaded any time later by choosing File->Load remaining quotes option from the menu. To save you from choosing this option for every stock that you want to check in detail another option is available: Load all quotes when stock is selected. If you check this box, AmiBroker will automatically load all remaining quotes of every stock that you select for viewing from Stock tree or ticker list. This way you will not even notice that you have only partially loaded database.

.... and that's all for this week - hope you enjoyed reading


AmiBroker Tips weekly newsletter. Issue 3/2001. Copyright (C)2001 Tomasz Janeczko. All back issues available from: