Australian (ASX) Stock Market Forum

AmiBroker Tips and Tricks

I've wanted a way to do Rolling Backtests for a while, and recently got some inspiration when reading the documentation about the Amibroker Object Model:


Excerpt:

New AnalysisDoc object does not allow you to read/write settings for the purpose - you are not supposed to manipulate UI while new Analysis window is running. Correct way of using New Analysis window is to open existing project file and run. If you want to modify the settings, you should write/modify existing project file. The analysis project file (.apx extension) is human-readable self-explanatory XML-format file that can be written/edited/modified from any language / any text editor.

Tomasz has an interesting definition of human-readable and self-explanatory. But lo and behold, I worked it out after a lot of hacking ?

I've attached a Powershell script to accomplish a rolling backtest across start and end years with a give step size. Sort of analogous to walk forward but without the optimization.

I've put a lot of documentation in the script header, but ping me if you have any questions.

Hope this helps...
 

Attachments

  • RollingBacktests.ps1.txt
    10.9 KB · Views: 34
Last edited:
One back test option I really like which I never see mentioned on the youtube how to videos is ExtraColumnsLocation

Amibroker creates addition columns for the variables you are optimizing and by default they are appended to the output after all the standard columns. Adding SetOption( "ExtraColumnsLocation", 1 ) ; to my AFL moves them to being the first columns with output like the following.


1620790097673.png

It's a small change but I find it really helpful having the optimized values and most of the fields I check visible without having to scroll left and right.
 
I've written some AFL which will randomly split any output you can generate via Scan (i.e. Market, Watchlist, Sector, etc) into a randomly generated In Sample and Out of Sample segment. This is based on code I saw in another forum. In that forum, an expert advocated backtesting across the entire market range, rather than splitting it over particular dates, such as IS from 2000-2014 and OOS from 2014-today.

Full instructions are in the program header.

Hope this helps!
 

Attachments

  • ISS-OSS-Stock-Segment-Build.afl
    9.7 KB · Views: 25
I found an Amibroker tip which I thought I'd share with the group. I have found this particularly useful for navigating charts.
Apologies to those who already know this...

Go to Tools -> Customize
Click the Keyboard tab
Click the Category dropdown and cycle through each category
In each Category, click in the Commands listbox, hit the down arrow, and note both the command choices and the default out-of-the-box keybindings.
You may want to take notes or screenshots of any commands that interest you and/or default keybindings that you know you'd use a lot.

Built-in keybindings which I discovered and found really useful in charts:

Zoom|In: Cntl+Num +
Zoom|Out: Cntl+Num -
Range|Mark Begin: F12
Range|Mark End: Shift+F12

Keybindings I added which I've found very useful:

Range|Hide: Cntl+F12
Zoom|All: Cntl+Alt+0
Zoom|Normal: Cntl+Alt+1 (Normal zoom is controlled by Preferences ->Charting -> Default zoom. Default is 160 bars.)
Zoom|Range: Cntl+Shift+F12 (Cntl+Alt+F12 was reserved for a system command)
Zoom|Shorter Bars: Cntl+Alt+Num -
Zoom|Taller Bars: Cntl+Alt+Num +

Less useful than these charting keybindings, but ones I still mapped:

New Analysis...: Cntl+Alt+A
Formula Editor: Cntl+Alt+E
Report Explorer: Cntl+Alt+R

To assign a new keybinding, just click in the Press new shortcut key field, press your desired keys, then click Assign. It will warn you if you are overwriting an existing key assignment.

The range functions are "tricky":
Click a bar so that it is selected (purple vertical bar) and press F12
You will see a green vertical line on that bar
Click a bar to the right so that it is selected and press Shift F12
You will see a red vertical line on that bar
Press Cntl+Shift+F12 to zoom in to that range
Press Cntl+F12 to hide (actually delete) the range

This could be useful during explore where you might want to zoom in on a certain range of the chart, say that last month or two. (I admit I'll probably just use Cntl+Num +/-, but that's how Zoom|Range works).

I'm finding with these new keybindings I'm moving around the charts MUCH faster than I used to with the mouse.

After you change your keybindings, select Tools -> Save Preferences. I found I lost some keybindings when I closed Amibroker without doing this first.

You can even create your own menu items via Commands -> New Menu, then dragging that to your menu bar (say to the right of Help). You can add your own favourite commands to that menu, or add User defined tools (the first 3 are already taken). It looks like User defined tools only runs external commands, but if you wanted to run an Amibroker batch file or external script, you could launch it from your custom menu.

(Note: I was able to create my own menu but had no external tools to execute so I deleted it. So I haven't tried this, but see the examples in Tools -> Sharenet downloader, etc. for a way to create your own tools).

Hope this helps!
 
This is more of a warning and rant than a tip.

I'm curious to know if you get the same outcome (I'm pretty sure you will) and your thoughts on what I consider to be a pretty egregious design bug in Amibroker.

I don't have hundreds of saved APX files, but they are certainly in the 30-50+ range.

I recently created a new watchlist which I use to save/monitor the symbols in a system. I add symbols when I buy, delete symbols when I sell. This makes it easy to cycle through the open positions in the charts.

I like these particular watchlists to be at the top of my watchlists, so I used Symbol --> Categories --> Watch lists tab, then clicked Move Up a million times to get the watchlist at the top of my other watchlists (drag and drop would be nice here). (I know there are other hacks that also accomplish the same result, i.e. editing C:\Program Files\AmiBroker\Databases\NorgateData\WatchLists\index.txt directly).

When I did this, it broke every APX file I'd ever saved!

I can't believe such a "stable genius" as Tomasz would save the watchlist filter setting using the watchlist number and not make that watchlist number immutable! He could then use a 2nd table for the user interface to allow the user to reorder the watchlists while keeping the actual watchlist number constant.

Your thoughts? Do you get the same behaviour? Should watchlists never be reordered if you use saved APX files?

(If you do this, and get the same behaviour, I think you can fix this by moving the new watchlist back down to the bottom, as it was before, then deleting it if you want to. But don't hold me responsible if that doesn't fix the issue.)
 

Attachments

  • Norgate Cache Functions.docx
    44 KB · Views: 16
  • Norgate_Cache_Functions.afl
    12.2 KB · Views: 11
Top