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
- Saved layout — "Course"Windows, symbols, intervals, sheets. Step 6
- Three chart sheets — Price, Trend, ScratchPanes and formulas. Steps 4 and 5
- Two watch lists — Course universe, Data problemsStep 3
- Imported symbols with verified dataStep 2
- Database — end-of-day base intervalStep 1chosen once
Before you start
Section titled “Before you start”- 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:
Step 2 — Import a starter universe
Section titled “Step 2 — Import a starter universe”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.
Route A: AmiQuote
Section titled “Route A: AmiQuote”Route B: the Import Wizard
Section titled “Route B: the Import Wizard”Verify before you go further
Section titled “Verify before you go further”Step 3 — Create the watch lists
Section titled “Step 3 — Create the watch lists”Write both names into your setup record. Names, not numbers — watch list numbers are ordinal positions that move if the lists are reordered.
Step 4 — The chart formula
Section titled “Step 4 — The chart formula”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.
The formula
Section titled “The formula”Complete runnable 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();How it works
Section titled “How it works”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.
Key functions
Section titled “Key functions”| 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 |
Expected result
Section titled “Expected result”Test it
Section titled “Test it”- Change
Fast average periodsfrom 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. - 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.
- Set
Show averagesto No. Both lines disappear; price and volume remain.
Common errors
Section titled “Common errors”| 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 |
Extension
Section titled “Extension”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.
Step 5 — Build the three chart sheets
Section titled “Step 5 — Build the three chart sheets”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”Step 7 — Prove it survives
Section titled “Step 7 — Prove it survives”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.
Verification checklist
Section titled “Verification checklist”Where the workspace can fail, and what proves it did not
- The databaseIt exists, at a path you recorded, with an end-of-day base interval
- The dataThe health check runs clean, and charts look like markets
- The universeTwo watch lists exist and have the right members
- The sheetsThree named tabs, each with its own arrangement
- The layoutNamed, saved, and still there after a restart
-
File -> Database Settingsshows 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.aflreturns 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 universeandData problemsexist under the Watch lists leaf, with the right members in each. -
universe-audit.aflruns againstCourse universeand 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.
Where this goes next
Section titled “Where this goes next”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.
What changed in your understanding
Section titled “What changed in your understanding”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
Sources for this lesson
8 verified · checked 2026-08-31
- 01AmiBroker User's Guide — Database Settings windowamibroker.com/guide/w_dbsettings.html2026-08-31
- 02AmiBroker User's Guide — Understanding AmiBroker database conceptsamibroker.com/guide/h_workspace.html2026-08-31
- 03AmiBroker User's Guide — Working with chart sheets and window layoutsamibroker.com/guide/h_sheets.html2026-08-31
- 04AmiBroker User's Guide — Working with watch listsamibroker.com/guide/h_watchlist.html2026-08-31
- 05AmiBroker User's Guide — Beginners' charting guideamibroker.com/guide/h_charting.html2026-08-31
- 06AmiBroker User's Guide — Drag-and-drop chartingamibroker.com/guide/h_dragdrop.html2026-08-31
- 07AmiBroker User's Guide — AFL Formula Editoramibroker.com/guide/w_afledit.html2026-08-31
- 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.