Handling limit orders in the backtester
In order to simulate limit orders in backtesting it is necessary to check in the code if Low price of the entry bar is below the limit price we want to use. The following example shows an entry signal...
View ArticleHow to restrict trading to certain hours of the day
In order to include time-based conditions in the back-testing code – we can use TimeNum() function to check the time-stamp of given bar and use it as input for any time-based conditions....
View ArticleHow to display correlation between symbols
For the purpose of calculating the correlation between two data-arrays, there is a Correlation() function in AFL which can be used. In order to display a correlation chart, please select...
View ArticleHow to add full name to the Price chart title
The full name of the security can be retrieved in AFL using FullName() function. In order to add such information to the built-in Price chart, we need to do the following: Click on the chart with right...
View ArticleText output in Explorations
Explorations allow to display not only numerical data but also text, there are however certain restrictions what can and can’t be displayed in the exploration result list as a text. AddTextColumn()...
View ArticleUsing multiple watchlists as a filter in the Analysis
The Filter window in the Analysis screen allows us to define a filter for symbols according to category assignments, for example watchlist members (or a result of mutliple criteria search). The filter...
View ArticleDrawing indicators on a subset of visible bars
By default, the Plot function draws the graph for all visible bars. In some situations however, we may want to draw some selected bars, leaving remaining chart space unaffected. To achieve that – we...
View ArticleUsing optimum parameter values in backtesting
After Optimization process has found optimum values for parameters of our trading system, typically we want to use optimum values in subsequent backtesting or explorations. In order to achieve that, we...
View ArticleHow to display interest gains in the backtest report
The default backtest report shows total Net Profit figure, which includes both trading profits and interest earnings. With Custom Backtest procedure we can easily isolate these components by summing up...
View ArticleDrawing line extensions on future bars using AFL
AmiBroker allows to display the AFL-based chart output on the future blank bars area with use of XSHIFT argument of the Plot function. This functionality allows to move the particular chart by certain...
View ArticleHow to populate Matrix from a text file
AmiBroker 6.00 has introduced support for matrices. After we create a matrics with Matrix function call: my_var_name = Matrix( rows, cols, initvalue); then in order to access matrix elements, we need...
View ArticleSymbol selection when PositionScore is not defined
AmiBroker’s portfolio backtester allows to define stock ranking and selection criteria by means of PositionScore variable. This is explained in details in the following tutorial chapter:...
View ArticlePositioning area plots behind the grid lines
When we want to paint the background with custom colors to indicate certain states or conditions – we can use area plots style for this purpose. The code example presented below shows green background...
View ArticleHow to browse charts in selected date range
In order to select certain range of dates in the historical chart, then scroll through the history of tickers, we can mark the range of dates we interested in using Range Markers (double-click on the...
View ArticleHow to run certain piece of code only once
There are situations where we may need to run certain code components just once, e.g. to initialize some static variables before auto-trading execution or perform some tasks (such as ranking) at the...
View ArticleHow to increase maximum periods of built-in indicators
Built-in indicators and averages which are shipped with AmiBroker use Param() function calls to provide the ability to adjust parameter values through Parameters window. Param function in the code...
View ArticleHow to fix Error 61 in printf/StrFormat calls
AmiBroker version 6.07 has introduced a strict check for correct string formatting in printf and StrFormat functions. These functions allow to specify the string followed by the list of arguments that...
View ArticleNumber of stopped-out trades as a custom metric
For the purpose of counting trades closed by particular stop we can refer to ExitReason property of the trade object in the custom backtester. The custom backtest formula presented below iterates...
View ArticleHow to fill background between hand-drawn trend lines
Among built-in drawing tools, the Triangle, Rectangle and Ellipse allow to fill the background with custom color. However, if we wanted to fill the space between manually drawn trend lines, then we...
View ArticleHow to count symbols in given category
When we want to find out how many symbols belong to given category (such as watchlist) then for manual inspection, it is enough to hover the mouse cursor over the particular category name in the...
View Article