Skip to content
Level 2 · AmiBroker AnalystLabPart 03 · page 8 of 850 min
50Minutes
12AFL functions
8Sources
StandardRequires
AFL functions taught here12

Lab: Build Your First AmiBroker Workspace

Everything in this part so far has been separate: an installation, a database concept, an importer, a category system, a set of chart controls. This lab joins them into one thing — an environment you open, work in, and close again, and which is still there tomorrow.

Budget fifty minutes and do it in one sitting. Roughly fifteen minutes go on the database and the import, twenty on the charts and sheets, and the rest on watch lists, the layout and verification. The result is the workspace the rest of the course assumes you have.

What you are building, and the order you build it in

  1. Saved layout — "Course"Windows, symbols, intervals, sheets. Step 6
  2. Three chart sheets — Price, Trend, ScratchPanes and formulas. Steps 4 and 5
  3. Two watch lists — Course universe, Data problemsStep 3
  4. Imported symbols with verified dataStep 2
  5. Database — end-of-day base intervalStep 1chosen once
  • AmiBroker installed and verified, and your setup record from the first lab open in a text editor.
  • Either AmiQuote working, or a folder of CSV files with daily OHLCV data for a handful of instruments. Either route is fine and the lab covers both.
  • A decision about where the database folder goes. Somewhere you back up, outside C:\Program Files.

Step 1 — Create and configure the database

Section titled “Step 1 — Create and configure the database”

Then, immediately, before you forget:

Aim for twenty to forty symbols, not two thousand. A universe small enough to inspect by eye is a universe whose defects you will actually notice, and every technique in Parts 4 through 16 works identically at either scale. Part 12 covers scaling up.

Choose instruments you can say something about: a broad index, a handful of large, liquid stocks from different sectors, and — if you have them — an instrument or two from outside equities, so that later lessons about volume, gaps and sessions have something to contrast against.

Write both names into your setup record. Names, not numbers — watch list numbers are ordinal positions that move if the lists are reordered.

You need a price pane that works on all three of the sheets you are about to build, on daily and weekly intervals, without editing it in between. That means every number in it has to be adjustable from the Parameters dialog rather than hard-coded, and the title has to say which interval you are looking at — because in a layout with several windows open, reading a weekly chart while believing it is daily is the easiest mistake in AmiBroker to make and the hardest to notice.

Complete runnable AFL

price-with-context.afl
// ===========================================================================
// Price with context
// A price pane that always tells you what you are looking at: which symbol,
// which interval, which bar, and where price sits relative to two averages.
// Written for the "Build Your First AmiBroker Workspace" lab in Part 3.
//
// HOW TO USE IT
// Analysis -> Formula Editor, paste, type a name into the Formula Name
// field, Save, then press Apply indicator to put it on the current chart.
// Right-click the pane -> Parameters to change the averages.
//
// WHY THE PARAMETERS EXIST
// The same formula has to serve a weekly sheet, a daily sheet and, later,
// an intraday sheet. Hard-coding 50 and 200 would make it a daily formula
// wearing a general name. Every number a reader might want to change is a
// Param() at the top instead of a literal buried in an expression.
//
// WHAT IT DOES NOT DO
// It plots two averages. It does not generate signals, and a moving average
// is a transformation of past prices, not a forecast of future ones. Nothing
// here should be read as a reason to trade.
// ===========================================================================
_SECTION_BEGIN( "Price with context" );
FastPeriods = Param( "Fast average periods", 50, 2, 300, 1 );
SlowPeriods = Param( "Slow average periods", 200, 5, 500, 1 );
ShowAverages = ParamToggle( "Show averages", "No|Yes", 1 );
FastAverage = MA( Close, FastPeriods );
SlowAverage = MA( Close, SlowPeriods );
// styleCandle is the default rather than the only option, so the same pane can
// be switched to bars or a line from the Parameters dialog without editing code.
Plot( Close, "Price", colorDefault, ParamStyle( "Price style", styleCandle ) );
if ( ShowAverages )
{
Plot( FastAverage, "MA " + NumToStr( FastPeriods, 1.0 ),
colorBlue, styleLine );
Plot( SlowAverage, "MA " + NumToStr( SlowPeriods, 1.0 ),
colorRed, styleLine | styleThick );
}
// The title states the interval explicitly. Reading a weekly chart while
// believing it is daily is the single easiest mistake to make in a workspace
// with several linked windows open at once.
Title = Name() + " - " + FullName() + "\n"
+ Interval( 2 ) + " - " + Date() + "\n"
+ "Open " + NumToStr( Open, 1.2 )
+ " High " + NumToStr( High, 1.2 )
+ " Low " + NumToStr( Low, 1.2 )
+ " Close " + NumToStr( Close, 1.2 )
+ " Volume " + NumToStr( Volume, 1.0 );
_SECTION_END();
_SECTION_BEGIN( "Volume" );
// Volume lives in its own scale. Without styleOwnScale it would be drawn
// against the price axis and collapse into a flat line along the bottom -
// the most common surprise when a second plot joins a price pane.
Plot( Volume, "Volume", colorLightGrey, styleHistogram | styleOwnScale );
_SECTION_END();

Download price-with-context.afl65 lines

A parameter block at the top, then everything else. Three Param calls declare the fast and slow average lengths and a toggle for whether the averages are drawn at all. Nothing below that block contains a literal number that a reader might want to change. That is a convention, not a requirement, and it is the single most useful habit in AFL chart formulas.

The price plot takes its style from a parameter too. ParamStyle("Price style", styleCandle) makes candlesticks the default while leaving bars and lines a dialog choice away. Hard-coding styleCandle would work; it would just mean editing the file to change your mind.

The averages are drawn inside a conditional. if (ShowAverages) skips both Plot calls when the toggle is off, so the pane can be reduced to bare price for a screenshot or a clean look without removing anything.

The title states the context explicitly. Symbol, full name, interval by name, the selected date, and the four prices plus volume. Interval(2) returns the interval as a string, which is what makes the interval visible rather than inferred.

Volume gets its own section and its own scale. A second _SECTION_BEGIN block plots volume as a histogram with styleOwnScale. Without that style, volume in the millions drawn against a price axis running from twenty to four hundred collapses into a flat line along the bottom — the classic surprise when a second plot with a different range joins a pane.

Function What it gives you
Param(name, default, min, max, step) A numeric value editable from the Parameters dialog
ParamToggle(name, "No|Yes", default) A Yes/No parameter, returned as 1 or 0
ParamStyle(name, defaultStyle) A style chooser in the dialog, returned as a style value
_SECTION_BEGIN(name) / _SECTION_END() Delimits a code section and namespaces its parameters
Interval(2) The current interval as a readable string
NumToStr(value, format) Formats a number for concatenation into a title
styleOwnScale Draws a plot against its own independent Y scale
  1. Change Fast average periods from 50 to 5 in the Parameters dialog. The blue line should immediately hug the price much more closely. If nothing changes, you are editing the parameters of a different pane.
  2. Switch the chart to Weekly. The title’s interval field must change to “Weekly”, and both averages must recompute over weekly bars — the slow average will cover a far longer span of calendar time for the same period count. This is the check that proves the title is reporting rather than guessing.
  3. Set Show averages to No. Both lines disappear; price and volume remain.
Symptom Cause
The formula does not appear in the Charts tree It was not saved into the Formulas folder; run View -> Refresh All after saving there
Volume is a flat line along the bottom styleOwnScale was removed from the volume plot
Parameters dialog shows entries you do not recognise You opened Parameters from the context menu, which shows every section in the pane
Changing a parameter has no visible effect A different pane is selected, or the parameter belongs to another section
The title shows the last visible bar rather than the one you clicked Quote selection is off, or Quote selection only by CTRL+LMB is enabled in Preferences

Add a third, much slower average and a ParamColor call so its colour is a dialog choice too. Then ask a harder question: with three averages on the chart, is the chart telling you anything that the two-average version did not? Being able to answer “no, and I will remove it” is a skill this course returns to repeatedly.

Sheets are the tabs along the bottom of the chart window. A default installation ships with four; you are going to use three of them and name them.

Once the three sheets are as you want them, make the set permanent: right-click the chart and choose Template -> Save as default. New windows will then start from this arrangement rather than from AmiBroker’s factory default.

Step 6 — Arrange the windows and save the layout

Section titled “Step 6 — Arrange the windows and save the layout”

This is the only test of this lab that matters, because it is the one that fails. An arrangement that vanishes on close is the most common complaint about AmiBroker’s interface, and it has two causes, both of which you have now dealt with: Save on exit: Layouts being off, and never having saved a named layout in the first place.

Where the workspace can fail, and what proves it did not

  1. The databaseIt exists, at a path you recorded, with an end-of-day base interval
  2. The dataThe health check runs clean, and charts look like markets
  3. The universeTwo watch lists exist and have the right members
  4. The sheetsThree named tabs, each with its own arrangement
  5. The layoutNamed, saved, and still there after a restart
  • File -> Database Settings shows your database with data source (local) and an end-of-day base time interval.
  • The symbol tree contains the symbols you imported, and no others you did not intend.
  • import-health-check.afl returns one row per symbol with no unexplained OHLC errors or non-positive prices.
  • At least three symbols have been opened on a chart and looked at with View -> Zoom -> All.
  • Course universe and Data problems exist under the Watch lists leaf, with the right members in each.
  • universe-audit.afl runs against Course universe and reports the membership you expect.
  • Three sheet tabs named Price, Trend and Scratch, each with its own arrangement.
  • The Price and Trend sheets use the same formula with different parameter values.
  • Two chart windows, one daily and one weekly, symbol-linked and not interval-linked.
  • A layout named Course in the Layouts pane.
  • AmiBroker has been closed and reopened, and the workspace came back.
  • Your setup record names the database path, the base interval, and the two watch lists.

Any unchecked box is worth fixing now. The workspace is a dependency of everything that follows, and the cost of fixing it here is minutes.

Part 4 starts reading price charts, and it assumes the chart window you just built. Part 12 runs scans and explorations, and it assumes the Course universe watch list, so that “Apply to = Filter” has something meaningful to point at. Part 19 creates a second database with an intraday base interval — deliberately separate from this one, for the reasons the base-interval lesson set out.

Add to the workspace as you go, but keep the discipline: watch lists for anything that changes, one sheet you can safely experiment on, and a layout saved under a name rather than trusted to the automatic save.

You have an environment rather than an installation. More importantly, you have built each layer of it knowing what the layer below constrains: the base interval limits the charts, the import determines what the analysis can see, the watch lists determine what a scan runs over, and the layout is the only thing that remembers where you put it all.

You have also seen a single formula serve two configurations through its Parameters dialog, which is the first appearance of an idea the whole of Part 10 is built on — that a formula with its variables exposed is a tool, and a formula with them hard-coded is a single-use answer.

Check your understanding

Question 1. You put the same chart formula on the Price sheet and the Trend sheet, then change the average lengths on Trend. What happens to Price?
Show the answer and why

Answer: Nothing — each pane stores its own parameter values

Parameter values are stored per chart pane, not in the formula file, which is why one formula can serve several configurations. That separation is what makes a heavily parameterised formula worth writing in the first place.

Question 2. You linked two chart windows with the S button but left both I buttons grey. What behaviour does that give you?
Show the answer and why

Answer: Both windows change symbol together, and each keeps its own interval

S links the symbol, I links the interval, and they are independent. Symbol-linked and interval-unlinked is exactly the multi-timeframe arrangement this lab builds: one instrument, two horizons, following you around the database together.

Question 3. Which of these would cause your carefully arranged workspace to be gone tomorrow? Select all that apply.
Show the answer and why

Answer: Never saving a named layout, "Save on exit: Layouts" being off in Preferences, Saving a local layout and then opening a different database

The first two lose the arrangement outright; the third does not lose it but makes it invisible, because local layouts are per-database. Renaming a sheet tab is harmless. Together the three explain almost every report of AmiBroker "not remembering" a workspace.

Question 4. Six months from now you want intraday charts. What is the documented route?
Show the answer and why

Answer: Create a new database with an intraday base interval and import into it

Changing the setting on an existing database does not create intraday history that was never stored — bars already compressed to daily cannot be un-compressed. The documented approach is a second database with the finer base interval, which is also why this lab makes you record the base interval of every database you create.

Sources for this lesson

8 verified · checked 2026-08-31

  1. 01AmiBroker User's Guide — Database Settings windowamibroker.com/guide/w_dbsettings.html2026-08-31
  2. 02AmiBroker User's Guide — Understanding AmiBroker database conceptsamibroker.com/guide/h_workspace.html2026-08-31
  3. 03AmiBroker User's Guide — Working with chart sheets and window layoutsamibroker.com/guide/h_sheets.html2026-08-31
  4. 04AmiBroker User's Guide — Working with watch listsamibroker.com/guide/h_watchlist.html2026-08-31
  5. 05AmiBroker User's Guide — Beginners' charting guideamibroker.com/guide/h_charting.html2026-08-31
  6. 06AmiBroker User's Guide — Drag-and-drop chartingamibroker.com/guide/h_dragdrop.html2026-08-31
  7. 07AmiBroker User's Guide — AFL Formula Editoramibroker.com/guide/w_afledit.html2026-08-31
  8. 08AmiBroker User's Guide — Preferencesamibroker.com/guide/w_preferences.html2026-08-31

Every technical claim on this page was checked against the official AmiBroker documentation on the date shown. Where the course disagrees with folklore, the source is how you can tell which one to trust.