Issue 11/2001 (No. 18)
| AmiBroker Tips newsletter.
Issue 11/2001. No 19.
20 May 2001.
Copyright (C)2001 Tomasz Janeczko.
All back issues available from:
Welcome to the 11th issue of AmiBroker Tips newsletter in the 2001. This time I will show you how to use the latest additions to AmiBroker (available in version 3.59 beta - http://www.amibroker.com/bin/ab359beta.zip) - watch lists and new features added to AmiBroker Formula Language (AFL)
Just a reminder: if you have any comments/suggestions or article ideas, please don't hesitate to drop a line to firstname.lastname@example.org
2 Tutorial: Working with watch lists
AmiBroker 3.59 introduces yet another way to organize your database - watch lists. Watch lists differ from other kinds of categories (as groups, markets, industries, sectors) in that, that you can assign single stock to more than one watch list.
You can use upto 32 watch lists with their names definable in Stock->Categories window. The members of each watch list is shown in the stock tree under "Watch lists" leaf. Note that only not empty lists are shown in the tree.
2.1 Adding tickers to watch lists
You can easily add a ticker to the watch list by simply clicking with a right mouse button over the item in the stock tree and choosing Add to watch list(s) option:
After choosing this option a watch list selector window will appear:
Here you should select the list you want to add the stock to. Note that you can add one stock to multiple lists at once, by holding CTRL key while clicking on the list items. After clicking OK selected stock (MSFT) appears in the watch list of your choice:
2.2 Removing tickers from watch lists
Removing stocks from the watch list is as easy as adding them. Just click on the list member with a right mouse button and select Remove from watch list(s). Then similar list selector window will appear showing only those lists that currently selected stock belongs to. You can now select one or more lists and the stock will be removed from the list(s).
2.3 Erasing watch lists
Sometimes you may want to clear (or erase) the whole watch list. Then just select Edit->Erase watch list(s) option. In the watch list selector window mark the list(s) you want to clear and click OK. This way selected watch list(s) become empty.
2.4 Using watch lists in Automatic analysis window
AmiBroker gives you a very easy way to store the results of scanning, backtesting and exploration into a watch list with a single mouse click - just run your favourite AFL formula over the whole database and click on the results list with a right mouse button to see the following menu:
When you choose Add results to watch list a watch list selector will appear where you select to which list stocks should be added, then after clicking OK all stocks filtered by your trading rules will automatically appear in the watch list of your choice.
AmiBroker 3.59 provides four important improvements to AFL:
a) experimental AFL scripting host for advanced formula writers
b) enhanced support for short trades
c) the way to control order execution price from the script
d) profit target stops in back tester
AFL scripting host is an advanced topic that is covered in a separate document available here and I won't discuss it in this newsletter. Remaining features are much more easy to understand.
3.1 Short trade support
In the previous versions of AmiBroker, if you wanted to back-test system using both long and short trades, you could only simulate stop-and-reverse strategy. When long position was closed a new short position was opened immediatelly. It was because buy and sell reserved variables were used for both types of trades.
Now (with version 3.59 or higher) there are separate reserved variables for opening and closing long and short trades:
buy - "true" or 1 value opens long trade
sell - "true" or 1 value closes long trade
short - "true" or 1 value opens short trade
cover - "true" or 1 value closes short trade
Som in order to back-test short trades you need to assign short and cover variables.
If you use stop-and-reverse system (always on the market) simply assign sell to short and buy to cover
short = sell;
cover = buy;
This simulates the way pre-3.59 versions worked.
But now AmiBroker enables you to have separate trading rules for going long and for going short as shown in this simple example:
// long trades entry and exit rules:
buy = cross( cci(), 100 );
sell = cross( 100, cci() );
// short trades entry and exit rules:
short = cross( -100, cci() );
cover = cross( cci(), -100 );
Note that in this example if CCI is between -100 and 100 you are out of the
3.2 Controlling trade price
AmiBroker now provides 4 new reserved variables for specifying the price at which buy, sell, short and cover orders are executed. These arrays have the following names: buyprice, sellprice, shortprice and coverprice.
So you can write the following to simulate real stop-orders:
// if anytime during the day prices rise above buyprice level (high>buyprice)
// the buy order takes place (at buyprice)
// if anytime during the day prices fall below sellprice level ( low < sellprice )
// the sell order takes place (at sellprice)
You can also control trade price:
buyprice = IIF( dayofweek() == 1, HIGH, CLOSE ); // on monday buy at high, otherwise buy on close
Please note that AmiBroker presets buyprice, sellprice, shortprice and coverprice array variables with the values defined in system test settings window (shown below), so you can but don't need to define them in your formula. If you don't define them AmiBroker works as in the old versions. There is also one caveat with using *price arrays - you can get very strange results in back-testing when you specify strange prices, for example assigning constant prices as follows:
buyprice = 1; sellprice = 2;
will give you 100% profit on each long trade regardless of actual stock prices. So take care.
3.3 Profit target stops and "Exit at stop" feature
As you can see in the picture above, new settings for profit target stops are available in the system test settings window. Profit target stops are executed when the high price for a given day exceedes the stop level that can be given as a percentage or point increase from the buying price. By default stops are executed at price that you define as sell price array (for long trades) or cover price array (for short trades).
But if you mark "Exit at stop" box in the settings the stops will be executed at exact stop level, i.e. if you define profit target stop at +10% your stop and the buy price was 50 stop order will be executed at 55 even if your sell price array contains different value (for example closing price of 56).
Maximum loss stops work in a similar manner - they are executed when the low
price for a given day drops below the stop level that can be given as a percentage
or point increase from the buying price
.... and that's all for this week - hope you enjoyed reading
AmiBroker Tips newsletter. Issue 11/2001. Copyright (C)2001 Tomasz Janeczko. All back issues available from: http://www.amibroker.com/newsletter/