31.07.2021 Views

Ultimate Algorithmic Trading System

Using automated systems for trading in stock markets

Using automated systems for trading in stock markets

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

shortMav = MA(C,avgLen1);

longMav = MA(C,avgLen2);

Buy = Cross(shortMav,longMav);

Short = Cross(longMav,shortMav);

Sell = Short;

Cover = Buy;

■ Syntax

To save some typing, I copied the code from MyFirstAlgo and made the necessary

changes. This is the code for a double moving average system where you buy when

the short (fast) moving average crosses above long (slow) moving average and you

short when the fast moving average crosses below the slow moving average. The

beauty of AmiBroker’s AFL is it reads almost like English. After you check the AFL

andsendittoanAnalysis window, go back to AmiBroker. Instead of clicking on

the Backtest button, click the Optimize button. AmiBroker will now optimize

the fast length from 9 to 49 and the slow length from 19 to 99 and report the

results from each iteration. This might take a few seconds. When the optimization

has completed, click on the down arrow beside the Optimize button and select

3D Optimization chart. A chart like the one in Figure 4.13 will appear on

your screen.

This is the result of the optimization where the x-axis and y-axis are the varying

lengths of the moving averages and the z-axis is the net profit. You can also see the

water level; this represents where the profit is equal to zero. Hopefully, most of

your mountains are above this level. This 3D chart only works on a two-parameter

optimization.

You may want to play around with some of the other icons and familiarize yourself

with their functions. AmiBroker is very sophisticated, and it took me several hours

to become somewhat comfortable with the charting, reports, and applying trading

and indicator algorithms. Again, I refer you to the excellent online manual, the

AmiBroker forums, and of course, Bandy’s book.

129

INTRODUCTION TO AMIBROKER’S AFL

The AmiBroker Function Language is very powerful, and, once you grasp the

array-processing paradigm, quite easy to use. In some programming languages you

have to declare variables and sometimes their types before you can use them. This

is not so for the AFL. However, when you create a variable know that it is an array

or list and not just a single memory location. Because of this, you can’t do this:

www.rasabourse.com

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!