Skip to content
Level 5 · Real-Time AmiBroker UserLabPart 21 · page 3 of 450 min Professional edition Live feed
50Minutes
9AFL functions
9Sources
Professional + live feedRequires

This page needs the Professional edition and a real-time data feed. Every gated part of this course ships a Level A path that uses Bar Replay and historical data instead — look for it below.

AFL functions taught here9

Lab: Build a Real-Time Trading Layout

Most “real-time trading layouts” you will see are a screenshot competition: nine panes, four monitors, and no way to tell from any of it whether the data behind the pixels arrived thirty seconds ago or ninety minutes ago. This lab builds a smaller layout that answers a fixed set of questions and admits when it cannot.

You will finish with a saved, reloadable arrangement of three chart windows, linked so that one symbol change moves the ones that should move and leaves alone the one that should not, with a status strip in each window that names the window, the interval, and whether what you are looking at is live or replayed. There is a complete Level A version driven by Bar Replay over historical intraday bars, and it produces the same layout, the same panes and the same verification results.

A database whose base interval is below end-of-day, holding intraday bars for at least three symbols: an instrument you would trade, a second instrument, and a broad index or sector proxy. Part 19 builds this database either from a live plugin or, at Level A, from historical intraday text files through the ASCII importer.

For the live version you also need a connected real-time plugin. For the Level A version you need nothing else at all — everything below works on stored bars.

Allow fifty minutes. The building takes about twenty; the verification is the part worth lingering over.

Step 0. Decide what the layout is for before you arrange anything

Section titled “Step 0. Decide what the layout is for before you arrange anything”

A layout is a set of answers to questions you have decided are worth constant attention. Write the questions down first, because every pane you add later costs a thread and a full formula execution per refresh, and “it looked useful” is not a budget.

A defensible starting set for intraday work:

  1. What is this instrument doing right now, at the resolution I act on?
  2. What is it doing at a resolution slow enough to have context?
  3. What is the wider market doing, independently of my instrument?
  4. Is the data I am looking at actually current?

Question 4 is the one almost every published layout omits, and it is the one this lab treats as a first-class pane rather than an afterthought.

Four words get used interchangeably and mean four different things. Getting them straight is what makes the saving step work later.

Term What it is Where it lives
Pane One formula drawn in one frame Inside a sheet. Added by double-clicking an indicator in Window → Charts
Chart sheet “A set of chart panes displayed within a single frame” Tabs at the bottom of the window. Up to 60, set by Tools → Preferences → Charting → Maximum number of chart sheets — which takes effect only after a restart
Chart window An MDI document with its own symbol, interval and set of sheets Tabs at the top. Created from File → New → Default Chart, Blank Chart or Linked Chart
Template “The complete set of chart sheets” Right-click the chart → Template → Save / Save as default / Load
Window layout A complete set of windows, each with its own symbol, interval, size and sheets Window → Layouts

Create each with File → New → Default Chart, then set its symbol and interval.

Window Symbol Interval Panes
EXECUTION Your instrument 5-minute (or your base interval) Status strip, price, volume
CONTEXT The same instrument Daily Status strip, price
MARKET Index or sector proxy 5-minute Status strip, price

Three windows with three panes each is nine panes. Under AmiBroker’s documented threading rule — one operation on one symbol is one thread, and displaying a single chart pane is one operation — that is nine threads’ worth of chart work, re-executed on every refresh of each pane. Nine is comfortable. Twenty-five, at a one-second refresh, is how people discover the load factor in the status bar.

To add a pane, open Window → Charts and double-click the indicator’s name, or use Insert from its context menu. To remove one, click it and use View → Pane → Close, or right-click the pane and choose Close. View → Pane also offers Arrange All, Move Up, Move Down, Maximize and Restore, which is how you get the status strip to sit thin at the top instead of claiming a third of the window.

The link buttons are the “S” and “I” buttons on the left of the scroll bar at the bottom of each chart window. Clicking one pops up a colour menu. Grey means unlinked; every other colour defines a link group, and all windows sharing a colour change symbol — or interval — together.

The crucial detail is that S and I are independent, which is the entire mechanism behind a multi-timeframe layout.

Link plan for this layout

  1. EXECUTION: S = red, I = greyFollows the symbol; keeps its own 5-minute interval
  2. CONTEXT: S = red, I = greyFollows the same symbol; stays daily
  3. MARKET: S = grey, padlock ONNever follows. Symbol-locked to the index
  4. One click on the symbol treeMoves EXECUTION and CONTEXT together; MARKET does not move
Symbol linking and interval linking are separate switches, which is what makes this work.

The padlock on the right of the scroll bar is Symbol Lock: a locked chart refuses symbol changes until the lock is released. Use it on the MARKET window, because the most common way to ruin a working layout is to click a ticker while the market window has focus and lose the reference you were watching.

For a second monitor, Window → Floating detaches a chart window from the main frame. Floating state is stored in the layout, so a two-monitor arrangement comes back when the layout is loaded.

Each window needs to state, without being clicked on, which window it is, which symbol and interval it is showing, whether it is live or replaying, how long the forming bar has to run, and whether the pane itself is still executing. That is an orientation panel, not an alarm; the alarm is built in the challenge that follows.

Complete runnable AFL

layout-status-panel.afl
_SECTION_BEGIN( "Layout status panel" );
/* Layout status panel - Part 21, Real-Time Charts.
WHAT IT DOES
One thin pane that answers "what am I actually looking at?" for a
multi-window intraday layout: which symbol, which interval, whether
this is live data or a Bar Replay session, how far the newest bar has
to go before it completes, and whether this pane is still repainting.
It is an orientation panel, not a staleness alarm. The alarm is a
separate formula (stale-data-monitor.afl) so that you can run the
alarm on one pane and the orientation panel on every window.
HOW TO USE IT
Insert it as the top pane of each chart window in the layout and drag
it down to two or three text lines. Give each window a different
"Window label" parameter so a screenshot or a glance tells you which
window you are reading.
ASSUMPTIONS AND LIMITS
- GetPlaybackDateTime() returns zero when Bar Replay is not active.
Zero is a legal-looking number, so it is tested before it is
formatted.
- Status( "lastbartimeleft" ) works for time-based bars only and
needs the database time shift set correctly. On a tick, N-tick or
N-volume chart it is not meaningful.
- Status( "timeshift" ) reports the database time shift in seconds.
If it is not what you expect, the countdown above it is wrong too.
- No AFL function reports the plugin connection status. This panel
cannot tell you whether the feed is connected; it can only tell you
when data last arrived. The connection state lives in the status
area at the lower right of the main window.
*/
WindowLabel = ParamStr( "Window label", "EXECUTION" );
RefreshSeconds = Param( "Refresh interval (seconds)", 2, 1, 60, 1 );
RequestTimedRefresh( RefreshSeconds, False );
PaintKey = "p21_layoutpaint_" + NumToStr( GetChartID(), 1.0, False );
PaintCount = Nz( StaticVarGet( PaintKey ) ) + 1;
StaticVarSet( PaintKey, PaintCount );
Playback = GetPlaybackDateTime();
BarLeft = Status( "lastbartimeleft" );
TimeShift = Status( "timeshift" ) / 3600; // shown in hours, as the dialog states it
NewestBar = LastValue( DateTime() );
if( Playback != 0 )
{
ModeText = "REPLAY";
ModeColor = colorOrange;
ClockText = "replay position " + DateTimeToStr( Playback );
}
else
{
ModeText = "LIVE OR STATIC";
ModeColor = colorPaleBlue;
ClockText = "system clock " + Now( 2 );
}
if( Interval( 0 ) > 0 )
CountdownText = NumToStr( BarLeft, 1.0 ) + " s left in the forming bar";
else
CountdownText = "no countdown - this interval is not time based";
SetChartOptions( 2, chartWrapTitle );
SetChartBkColor( ModeColor );
Title =
EncodeColor( colorBlack ) + WindowLabel + " | " + Name()
+ " | " + Interval( 2 ) + " | " + ModeText + "\n"
+ "Newest bar: " + DateTimeToStr( NewestBar ) + " | " + CountdownText + "\n"
+ ClockText + " | time shift " + NumToStr( TimeShift, 1.2 ) + " h"
+ " | pane repaints: " + NumToStr( PaintCount, 1.0 );
_SECTION_END();

Download layout-status-panel.afl78 lines

The formula does four things in order. It starts its own paint clock with RequestTimedRefresh( RefreshSeconds, False ), so the strip keeps updating even when the main window is minimised. It increments a per-pane execution counter held in a static variable keyed by GetChartID(), so each of the three copies counts independently. It asks GetPlaybackDateTime() whether Bar Replay is active — the function returns the playback position or zero — and switches mode text, background colour and reference clock accordingly. Then it builds a single wrapped title.

The mode is signalled twice, in colour and in words, which is deliberate: the background tells you across a room, the word tells you when the colour does not.

Status("lastbartimeleft") supplies the countdown, and it is asked for only when Interval(0) is greater than zero, because the countdown is documented as working for time-based bars only. Status("timeshift") is divided by 3600 and shown in hours, because that is the unit the Intraday Settings dialog uses, and a strip that disagrees with the dialog is a strip you will misread under pressure.

  • ParamStr( name, default ) — a text parameter, so the same formula labels itself EXECUTION, CONTEXT or MARKET without three copies of the file.
  • GetPlaybackDateTime() — Bar Replay position, or zero when replay is inactive. Zero is a plausible-looking number, so it is tested before being formatted.
  • Status("lastbartimeleft") — seconds until the forming bar completes. Time-based bars only, and it needs the database time shift set correctly.
  • SetChartBkColor( color ) — sets the pane background.
  • EncodeColor( color ) — colours the text that follows it in a title.

A thin strip at the top of each window reading, on three lines: the window label, symbol, interval and mode; the newest bar’s timestamp and the countdown; and the clock, time shift and repaint count. Live or static data gives a pale blue background; an active Bar Replay session turns it orange.

Change the “Window label” parameter in one window only, via right-click → Parameters. Only that strip should change, which proves the three panes are genuinely independent instances rather than one shared thing.

  • Forgetting that a parameter is per pane. Setting the label once does not set it everywhere, and that is the intended behaviour.
  • Reading the repaint counter as freshness. It measures the paint clock only, which is exactly why it is next to the bar timestamp rather than instead of it.
  • A countdown that is confidently wrong. Check the time shift on the same line before believing it; a mis-set shift produces a plausible number that is wrong by whole hours.

Add a ParamToggle that hides the repaint counter, so the strip can be trimmed to two lines once you trust the layout.

There are two separate saves, and doing them in the wrong order loses work.

  1. Save the template first. With one window arranged, right-click the chart and choose Template → Save. The template is the complete set of sheets, and it is what makes a new window come up right. Template → Save as default makes it the arrangement used whenever a new window is created.
  2. Then save the layout. Open Window → Layouts, right-click and choose Save As. The layout stores window sizes and positions, maximised or minimised state, the panes on each sheet per window, the selected interval, the selected symbol and the selected sheet.

Two documented details decide whether your layout is still there tomorrow.

Local versus global. A layout saved locally lives in the Layouts folder inside the database directory; a global one lives in the Layouts folder inside the AmiBroker main folder and is visible from every database. Save a layout in one database and look for it in another, and this is why you cannot find it.

Save on exit. Tools → Preferences → Miscellaneous has “Save on exit: Layouts”. If it is off, your arrangement disappears silently when AmiBroker closes.

The Level A version: the same layout, driven by Bar Replay

Section titled “The Level A version: the same layout, driven by Bar Replay”

This is not a reduced version. It is the same three windows, the same links, the same status strips, with stored bars supplying the data instead of a plugin. It is arguably the better place to learn the layout, because you control the clock.

Tools → Bar Replay plays back historical data at a chosen speed. Three documented properties shape everything below:

  • It is global. Data for all symbols ends at the current playback position, and this affects every formula, in charts and in the Analysis window alike. Your three linked windows therefore replay in step automatically, with no extra work.
  • Nothing is written to disk. The truncation is internal. The guide states the database is kept untouched and that all data remain visible in the Quote Editor, so playback cannot damage what you have stored.
  • PLAY or PAUSE enters playback mode; STOP or closing the window leaves it. Merely opening the dialog does nothing. PAUSE is not “do nothing” — in PAUSE the data are already truncated, which is what lets you drag the slider by hand.
  1. Build the three windows and links exactly as in Steps 2 and 3. Nothing changes.
  2. Open Tools → Bar Replay.
  3. Set Start and End to the session you want to replay. The small ^ buttons beside each date field set that field to the date currently selected on the chart, which is faster than typing.
  4. Set Step interval. The guide’s recommendation is the base interval of your database. Higher step intervals are allowed.
  5. Leave the chart viewing interval where you want it. The chart interval is independent of the step interval — you can step a 1-minute database while watching 15-minute bars, and the last bar builds up as data arrives rather than appearing complete.
  6. Set Speed in steps per second. The default is 1, the maximum 5, the minimum 0.1. Speed 3 is one step every third of a second.
  7. Tick Skip after-hours to skip time outside the trading hours defined in File → Database Settings → Intraday Settings, and Skip weekends as required.
  8. Press PLAY.

The status strips should immediately turn orange and start reporting a replay position. That is the confirmation that the panel is reading the replay clock rather than your PC clock.

What the Level A version does and does not reproduce

Section titled “What the Level A version does and does not reproduce”

It reproduces, faithfully: the layout mechanics, the linking behaviour, bars arriving one at a time, an unfinished last bar changing as data arrives, indicators updating as they will on live data, and the behaviour of every formula in this part.

It does not reproduce: bid and ask, spread, the order book, fill quality, latency, connection failures, or the psychological conditions of a live session. GetRTData() remains unavailable — it is Professional-only and requires a streaming plugin, and Bar Replay is neither. Part 26 examines these limits properly, and Part 23’s dashboard project shows how to write a formula that degrades honestly when the live fields are absent.

Do these in order. Each has an observation attached, and any that does not produce its observation is a fault to fix before moving on.

  1. Symbol linking. Click a different ticker in the symbol tree. EXECUTION and CONTEXT change; MARKET does not. If MARKET moved, its padlock is off or its S button is not grey.
  2. Interval independence. Confirm EXECUTION still shows 5-minute bars and CONTEXT still shows daily after the symbol change. If both changed interval, the I buttons are linked.
  3. Three independent strips. Each status strip names its own window. If all three read the same label, you set the parameter on a shared pane rather than in each window.
  4. Paint clock alive. Watch a repaint counter for ten seconds. It should advance. If not, the pane is on an inactive sheet, or the main window is minimised with onlyvisible left at True.
  5. Data clock alive. Live: the newest-bar timestamp advances at the chart interval and the countdown falls and resets. Level A: press PLAY and confirm the same behaviour against the replay position.
  6. Mode is unambiguous. Start and stop Bar Replay. The strips must switch between orange “REPLAY” and pale blue “LIVE OR STATIC” both times. A strip that stays orange after STOP means replay did not actually exit — press STOP again or close the dialog.
  7. Time shift is what you expect. Compare the value in the strip with File → Database Settings → Intraday Settings → Time shift. If they disagree, stop and fix it; every countdown and every session filter in the layout depends on it.
  8. Cost is acceptable. Check the rightmost status bar indicator. On a real-time database it shows a load factor and the documented recommendation is 100% or below. On an offline or intraday database it shows free virtual memory instead.
  9. It survives a restart. Close AmiBroker, reopen it, load the layout from Window → Layouts. All three windows, their symbols, intervals, sheets and panes should return. If they do not, check “Save on exit: Layouts” and whether the layout was saved locally in a different database.

You have a three-window layout in which symbol linking and interval linking are set separately, one window is symbol-locked so it cannot be knocked off its reference, and every window carries a strip that says what it is showing and whether the data behind it is live or replayed. You saved it as a template and as a layout, and you know where each is stored and which preference decides whether it survives closing the program.

The Level A path is not a compromise: the same layout, driven by Bar Replay over stored intraday bars, exercises every mechanism in the lab and gives you control of the clock while you learn.

What the layout still cannot do is tell you when the data has stopped. That is the next page.

Check your understanding

Question 1. You want two windows on the same symbol showing different intervals, so that one click on the symbol tree moves both. How do you set them?
Show the answer and why

Answer: Link S to the same colour on both; leave I grey on both

S links the symbol, I links the interval, and they are independent. Sharing an S colour makes the symbol move together; leaving I unlinked lets each window keep its own periodicity. Symbol Lock does the opposite of what is wanted — it prevents symbol changes entirely.

Question 2. Bar Replay is running. Which statements are true? Select all that apply.
Show the answer and why

Answer: It affects every symbol, not just the charted one, Explorations and backtests run while it is active see truncated data, GetPlaybackDateTime() returns zero once you press STOP

Bar Replay is documented as global: all symbols end at the playback position and both charts and Analysis are affected. Nothing is written to disk — the Quote Editor still shows every bar. GetPlaybackDateTime() returns the position while replay is active and zero when it is not.

Question 3. You saved a layout while working in your intraday database and cannot find it after switching to your end-of-day database. What is the most likely explanation?
Show the answer and why

Answer: It was saved as a local layout, which lives in the database folder; global layouts are visible from all databases

Local layouts are stored in the Layouts folder inside the database directory, global ones in the Layouts folder of the AmiBroker main folder. The distinction is documented and is the usual cause of a "missing" layout. Nothing has been lost — it is in the other database.

Question 4. A colleague adds twelve panes across four windows and reports that AmiBroker has become sluggish. Which explanation matches the documented cost model?
Show the answer and why

Answer: Each pane is an operation on one symbol, so each is a thread, and every refresh re-executes each pane’s entire formula

The documented rule is that one operation on one symbol equals one thread, and displaying a chart pane is one operation. Twelve panes refreshing every second means twelve full formula executions per second, which is exactly what the status-bar load factor measures. Sheets are unrelated, and panes do not queue behind one another.

Sources for this lesson

9 verified · checked 2026-08-31

  1. 01AmiBroker User's Guide — Chart sheets, templates and layoutsamibroker.com/guide/h_sheets.html2026-08-31
  2. 02AmiBroker User's Guide — Beginners' charting guide§ Linking and locking chartsamibroker.com/guide/h_charting.html2026-08-31
  3. 03AmiBroker User's Guide — Bar Replayamibroker.com/guide/w_barreplay.html2026-08-31
  4. 04AmiBroker User's Guide — Preferences§ Charting and Miscellaneous tabsamibroker.com/guide/w_preferences.html2026-08-31
  5. 05AmiBroker User's Guide — Efficient use of multithreadingamibroker.com/guide/h_multithreading.html2026-08-31
  6. 06AmiBroker User's Guide — Files and directories used by AmiBrokeramibroker.com/guide/x_files.html2026-08-31
  7. 07AFL Function Reference — GetPlaybackDateTimeamibroker.com/guide/afl/getplaybackdatetime.html2026-08-31
  8. 08AFL Function Reference — Statusamibroker.com/guide/afl/status.html2026-08-31
  9. 09AFL Function Reference — SetChartBkColoramibroker.com/guide/afl/setchartbkcolor.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.