In “Trading High-Yield Bonds Using ETFs” in this issue, author Brooke Gardner presents a basic moving average crossover system. Implementation of the moving average (MA) crossover is straightforward and the AmiBroker formula is presented here. To use it, enter the formula into the AFL Editor, then press the “Send to analysis” button to backtest, and “Insert indicator” to see the chart.
Periods = Param("Periods", 8, 2, 100 ); movavg = MA( C, Periods ); Buy = Cross( C, movavg ); Sell = Cross( movavg , C ); Plot( C, "Price", colorBlack, styleCandle ); Plot( movavg, "MA"+_PARAM_VALUES(), colorBlue );
A sample chart is shown in Figure 6.
FIGURE 6: AMIBROKER, EIGHT-BAR SIMPLE MOVING AVERAGE. Here is a monthly chart of FAGIX with an eight-month simple moving average (upper window) and the backtest results (lower window).