Bill Barnard – Clearwater ‘05
A VISUAL APPROACH TO SIGNAL STUDY IN AMIBROKER
Bill Barnard – 2/6/06
CONTENTS
Introduction
The Plots
The Parameter Window
The Files
First Use of the Code
Using Indicators to Generate Signals
INTRODUCTION
Many traders, particularly those who use FastTrack and associated third-party programs, make extensive use of signals to time trades. There has been very prolific signal development on the forum at FT-Talk.com, which I have followed for many years. Observation has shown that all signals vary in their effectiveness as time passes, and there has been much discussion of the reasons for this. The main thing is that signals which are highly optimized for past market conditions inevitably fail to perform as well when the markets change. Computers permit highly efficient optimization and data mining, and there is a strong temptation to produce signals which have very good past performance, often based upon a large number of parameters, and/or parameter values carefully selected to fit past market data.
I have long been interested in dissecting signals in an attempt to understand how they work, and AmiBroker has proved to be a magnificent tool for this purpose. While my association with the FastTrack community has provided the impetus for this work, the AmiBroker tools I have developed make signal study and production available to all AmiBroker users, regardless of data source or the vehicle used for trading.
THE PLOTS
AmiBroker can be employed in many ways to generate tabular information, and the work in this realm of Fred Tonetti and Bruce Robinson has contributed mightily to our understanding of signals and their robustness. My work is aimed at making a visual presentation of signal generation and trading results. Hopefully this will provide another avenue for better understanding of how finely tuned the signals are, and lead to the development of more robust signals.
I have written code which plots, in a single large window pane, the result of trading a selected fund long or short to a money market fund, or long and short with another selected fund. (I will be using the term ‘fund’, but this all applies to any tradable entity.) Also plotted is a chart of the losses associated with the trading (the familiar drawdown) or the gains/losses associated with individual trades (MFE and MAE). Additionally, a section of the window is devoted to a plot of selected indicators which generate the signals.
With so many things being calculated and plotted, there are many opportunities for errors, such as the misspelling of a signal name or the selection of a fund with too short a history, so I have incorporated a number of messages which are displayed when necessary in the chart window to guide in making the needed correction. Also, messages are displayed to describe what is happening when signal files are exported, and in other situations. My intent was to make the package self-explanatory, so that it is not necessary to refer to a separate help file.
I have always liked the visual effect of FastTrack’s black background, and have carried this through to my AmiBroker setup, but I recognize that others have different opinions, so I have incorporated parameter-selectable color schemes which make the plotted information easily visible with white and light grey backgrounds as well.
It is also possible to adjust the placement of the various plotted elements to account for different screen sizes and resolutions. This is necessary for the proper placement of title information throughout the chart.
THE PARAMETER WINDOW
One of the wonderful features of AmiBroker is the Parameter window, with its variable parameters. This allows indicators to be adjusted while the results are observed in the plot. This leads to a vastly improved understanding of how the parameter values influence the shape of indicators and the trading results.
My code makes liberal use of parameters, not only to modify the indicators, but also to adjust the placement of various things in the window, to select the things which will be calculated and plotted, and to select amongst many alternatives for the appearance of the window. In fact, I think of the Parameter window as a ‘control panel’ or ‘dashboard’, and it is intended to be left open at all times. To make it usable in the situation where screen area is limited to a single screen, I have included many labels in the right side of the parameter window so only the right half needs to be visible on the screen. Because the code uses ‘nested’ parameters, it is necessary to frequently use the button at the bottom of the Parameter window to ‘Reset all’. Ordinarily this would result in all the settings being returned to their defaults, losing your customizations, so I have incorporated configuration files which are automatically produced and read by the code. These store all the values which have been selected for the parameters, so they are not lost when the reset is done.
There are many, many parameters. For convenience, they are arranged in the order of most common use, with the ones frequently changed near the top of the list.
THE FILES
The entire work is incorporated in one large file, SIGNAL STUDY.afl, which can be placed anywhere in a subdirectory under AmiBroker\Formulas\, and a number of helper files which must be placed in AmiBroker’s ‘Standard include’ directory. In this configuration, one can select from amongst about ten indicators and a couple of other signal generators, by changing a parameter.
While it is handy to have it all available in one module like this, the total amount of code is quite large, and operations like changing parameters, moving the vertical pole on the chart, etc. may be slow when a large amount of data (like the entire FastTrack database of 17+ years) is viewed, and a slow computer is used. I have made extensive use of AmiBroker’s new chart timing display to determine just what is taking the time, and have found that it is possible to make the code execution about twice as fast by limiting the helper files to one, i. e., using several different sheets, each with the main file and a single indicator helper file. In this case, all but the one ‘include’ file would be commented out or deleted (use ‘Insert’, not ‘Insert Linked’). These ‘includes’ are located in a well-marked section about ¼ of the way down in SIGNAL STUDY.afl.
Some of the helper files, like the ones for combining multiple signals, are more computationally intensive, and they run considerably slower than the simple indicator helper files. These work much better when used singly in separate sheets, as discussed above.
If one is not comfortable with getting into the code, it is completely possible to use it with no editing. The speed issues may not be a factor if a shorter amount of history is viewed, or if a fast computer is used.
FIRST USE OF THE CODE
Start by reading the discussion which appears on the screen when the top parameter button is clicked. When first using the Parameter window, it will be helpful to view it in its entirety to get the big picture; then you will be able to use it with only the right side visible. Note that the parameters are arranged in groups. Just under the DISCUSSION area, a section called SIGNAL STUDY will provide a choice of ways to generate the signals. The next section will be specific to the source of signals selected, and it will change with different signal source selections, after the ‘Reset all’ button at the bottom of the Parameter window is clicked. The next section, PERIOD OF TEST, and all the rest, will remain the same, no matter what source of signals is selected. The parameters in these sections are used to set the various conditions for the trading, such as the test period, the trading delay, minimum holding periods, and the funds to be traded. Further down in the Parameter window are buttons to choose the things to be plotted and buttons to export signal files. Still further down (and rarely used) are parameters to select color schemes and individual colors, and the size and placement of the various plotted elements and titles.
The simplest way to start studying signals is to click on the first parameter bar below the ‘Discussion’ buttons. After a click, a list of possible selections will drop down. Click on the one called ‘Named Signals’, and then click the ‘Reset all’ button at the bottom of the Parameter window. (The reset is necessary after any change of source of signals, to bring the proper parameters into view.)
The ‘Named Signals’ module will permit the input of a signal name or a comma-separated list of signals, one of which can be selected with a parameter. The result of trading (an equity plot) and the loss characteristics will be plotted. The signal names can refer to signals in the FastTrack\SIG\ directory, or to signals which are part of the AmiBroker database. These could have been imported with the ASCII importer or generated by the AddToComposite function from suitable code which was run in the AA window. An example formula for this purpose, RUTTRFT1.afl, is included in the file package.
For those with many signals, it is possible to quickly go through a list, using the parameter slider. This comparison can be very informative, particularly when the first parameter in the CHART APPEARANCE section is adjusted to a value higher than the result of the best signal. This will cause the plots of all the trading results to be made to the same scale, as distinguished from FastTrack, which plots everything to fill the window.
While looking at the trading results of the various signals, adjust the second parameter in the CHART APPEARANCE section to show the different types of loss displays. As is the case for the trading result plot, there is a parameter to adjust the scaling of the drawdowns so that the results of various signals are plotted to the same scale.
USING INDICATORS TO GENERATE SIGNALS
Now you can move on to exploring the other signal generation possibilities, the various indicators and the composite signal modules. The latter are a bit more complex, and have their own individual discussions available by parameter buttons when the module is selected and the ‘Reset all’ button is clicked.
Remember to always click the ‘Reset all’ button after changing the Signal Source. Don’t be afraid to do this anytime; the configuration files will be saving all your parameter settings.
After you have studied and customized your special signal, it can be exported (parameter buttons) as a FastTrack signal file or as an FNU type file to either FastTrack or Amibroker\ABFNUs\.
Have Fun, and Good Trading to You! Bill Barnard