Calling custom user functions in our code
AFL language allows us to define reusable functions that can be used in our formulas. The following chapter of the manual explains the procedure in details:...
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 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 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 ArticleChecking relationship between multiple moving averages
When we compare the positions of several lines against one another, we need to remember about using correct operators, so our AFL statement return correct results. Let us consider a set of moving...
View ArticleWhen and how often AFL code is executed?
All analysis in AmiBroker including charting, Analysis window or commentaries is based on underlying AFL code, which is being executed by the program to produce the required output. Therefore – any...
View ArticleWhat are constants in AFL and how they work
The AFL language contains many pre-defined words like: shapeUpArrow, stopTypeTrailing, colorRed, styleThick, inDaily and many more. These are examples of constants. As written in AFL language...
View ArticleCan I encrypt my formula so no-one can decipher it?
Currently the only way to protect your code from other peoples’ eyes is to translate part of the formula (such as few functions) or entire formula to C/C++ language and compile as AFL plugin DLL. Doing...
View ArticleDo NOT make assumptions on number of bars
From time to time some users face “Error 10. Subscript out of range” in their formulas. The error itself is described in the manual, but still a few words of explanation why it happens may be useful....
View ArticleA function with multiple return values
A typical AFL function returns one value. For example sin( x ) returns sine value of argument x. Sometimes however it is useful and/or required to return more than one value from the function....
View ArticleAbout floating point arithmetic
In general, to represent numbers with fractional parts, computers use a “floating point” binary representation. Floating point arithmetic is also used by AmiBroker for AFL calculations. For some more...
View ArticleAFL execution speed
NOTE: Benchmarks and timings given below are little outdated because article was written back in 2008. Today’s CPUs are faster and memory bandwidth is also higher. AmiBroker Formula Language (AFL)...
View ArticleQuickAFL facts
QuickAFL(tm) is a feature that allows faster AFL calculation under certain conditions. Initially (since 2003) it was available for indicators only, as of version 5.14+ it is available in Automatic...
View ArticleNew keywords in AFL and possible conflict with user-defined variables
AmiBroker 4.91.0 BETA introduced the following new keywords: switch, case, break, continue, default You have to make sure that your formulas do not use them as variable names. The above words are now...
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 synchronize backtesting setup on different computers
When comparing the output of back-tests obtained from different working machines, it is necessary to make sure that all aspects of our testing are identical, including: the database the formula used...
View ArticleHandling 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 ArticleUsing loops with TimeFrame functions
AmiBroker features a powerful set of TimeFrame functions that allow combining different time intervals in single system formula. There is one aspect of TimeFrame functions that is important to...
View ArticleHow to display indicator values in the backtest trade list
Backtesting engine in AmiBroker allows to add custom metrics to the report, both in the summary report and in the trade list. This is possible with Custom Backtester Interface, which allows to modify...
View ArticleHow to plot daily High and Low on intraday chart
The AFL offers a set of time-frame functions which allow to use multiple intervals within a single formula (the topic is explained in details in the following tutorial chapter:...
View Article