You are on page 1of 2

78 Introduction to AmiBroker

EXAMPLE 6 - RUN A SINGLE STOCK BACKTEST

In this example, you will use the Formula Editor to write the AFL code
for a simple trading system, run the code as a Backtest on the historical
data of one stock, review the results, plot the Buy and Sell arrows, plot
the Equity Curve.

Start AmiBroker.

Using the Automatic Analysis pull-down menu, select the Formula


Editor. The Formula Editor will open, ready to accept your new AF L
program. Type it in so it matches this one:

L [C:\Program File5\AmiBroker\Formulas\Custom\Examt.. [:lEE


Eile gun Imls Lab 1};

D D‘H- 5 A_i'iiwa g :x ExarnpbfiA “soar :3;


H E:{ampleo§,&.afl m

J A Eiajinq system based an rhe


er of two mav

n Lhe ta$LeL
up through V

11 when the faster mowing ak’eraqe


35595 flown througla- the Slower

/‘ n‘oung ave; age.

Fastm : M( c, 5 ),-
SlowMA = MA( C. 20 3;

IBuy = Croaa( FBStMA, SlawMA ),'


sell : Cross( SlowMA/ FastMA ),-

Formula name Ln 11, Co! 1


Save it in the Custom directory as Example6A.afl.

In setting up Automatic Analysis, you need to load the file you want
processed. Example 5 showed one way to do that. Here is another - a
shortcut that coordinates Formula Editor with Automatic Analysis.

Formula Editor has a toolbar. The rightmost icon in the toolbar is an ex—
clamation point. If you hover your mouse over it, the tooltip says Anal-
ysis. When you Click that icon, the file that is open in Formula Editor
is loaded into Automatic Analysis and Automatic Analysis is opened.
This makes for an easy cycle of editing and analyzing. After the edit,
click the Analysis icon and go directly on with the analysis.

You might also like