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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

to Short and Cover as well. If you are using a pure stop and reverse algorithm,

you can set up your Sell and Cover arrays like this:

Sell = Short;

Cover = Buy;

These two lines tell the computer to cover long positions at the same price a short

position is established and to cover short positions at the same price a long position

is put on. Or you can do it like this:

Sell = 0;

Cover = 0;

If you don’t take into consideration the arrays that get you out of a position,

AmiBroker will give you a warning message, and will not execute the backtest.

AmiBroker requires the BUY order and its corresponding SELL order to be defined

prior to processing. The same goes for SHORT and COVER. In some platforms,

you do not need to define SELL and COVER if the algorithm is always in the market

long or short.

This little bit of code seems quite simple on the surface, but there is a lot going on

behind the scenes. AFL has a plethora of built-in functions such as the MA function

used in this simple program. So calculating the 100-day moving average is very

simple; just call the function. The four arrays (BUY, SHORT, SELL, COVER) that

instruct AmiBroker to establish and liquidate trades are instantly populated with 1s

and 0s; it’s a one-pass process. This process is extremely fast and efficient. Once

this single pass is completed, the back tester is fed the necessary information to

simulate the backtesting of the algorithm. As you can see, entry and exit prices are

not defined, so they are defaulted to the close of the bar. This default can be changed

using the settings dialog box.

Let’s give this simple algorithm a run. The next instructions assume you have

worked with AmiBroker and know how to plot charts, apply indicators, and work

with price databases.

Go ahead and launch AmiBroker and load your database of choice. I imported an

ASCII database of futures prices that I got from CSI data. The software is compatible

with CSI and there are instructions in the online manual on how to create a database,

and have it updated automatically. This may require an additional monthly data fee.

Figure 4.1 shows how to get to the AFL editor from the main AmiBroker File menu.

Once the editor launches you will see a window like the one in Figure 4.2.

This is your tabula rasa—blank slate. Anything you can dream up can be

accomplished by typing in the right code. Go ahead and type in the code from the

121

INTRODUCTION TO AMIBROKER’S AFL

www.rasabourse.com

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

Saved successfully!

Ooh no, something went wrong!