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.

However, this is not the case. The code inside the average function consists of a

loop and is called on each and every bar.

If you have a lot of experience with scalar programming (Java, C++, or

EasyLanguage), then picking up AFL might require a little patience, but it will

definitely be worth it. As you know, learning a new programming script/language is

best performed by working through examples. If you own AmiBroker, make sure you

go to this link and download Howard Bandy’s book: http://introductiontoamibroker

.com/book.html. This book will get you up and going very quickly. Bandy helps

explain the sophisticated database management that you get with AmiBroker. Data

is to a trading algorithm like gas is to an automobile.

■ AFL Array Programming

Here is a simple moving average crossover system in AFL:

PositionSize = MarginDeposit = 1;

avgLen = Optimize("Len",20,10,100,1);

avgLen = Param("Length",81,10,100,1);

120

INTRODUCTION TO AMIBROKER’S AFL

Buy = C > MA(C,avgLen);

Short = C < MA(C,avgLen);

Sell = Short;

Cover = Buy;

For right now, ignore lines 2 and 3—the ones starting with the word avgLen. If

you are testing futures data, then don’t forget the first line must be in every trading

algorithm. This tells AmiBroker’s backtester to only trade one contract and sets

the margin deposit to one as well. The variable avgLen is the length of the moving

average indicator the algorithm will utilize. Let’s set it to 100.

Buy = C > MA(C,avgLen);

This line of code tells AmiBroker to set the BUY array to true or 1 if the close is

greater than the 100-day moving average of closes. If the test fails and the close is

not greater than the moving average, then it is set to false or 0. Since we are array

processing, this done all at one time. The BUY array is filled completely up with

either 1s or 0s. The SHORT array does just the opposite—true if the close is less than

the 100-day moving average and false if it’s not. This system simply flips back and

forth between long and short positions—it’s always in the market. If you use Buy

and Short arrays to initiate positions, then you must have values for the Sell and

Cover arrays. If you only use Buy, then you only need a value for Sell. This applies

www.rasabourse.com

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

Saved successfully!

Ooh no, something went wrong!