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.

This should look very similar to the code we originally typed in for

MySecondAlgo. The AFL Wizard can get you up and running very quickly and

can also be used as a learning tool. It automatically builds the AFL code so you can

start your design with the Wizard and have it generate the framework and then

move onto the AFL Editor and complete your coding of your algorithm there.

■ AmiBroker Loop Programming

As powerful as AmiBroker’s array programming is, there are times when you want to

program on a bar-by-bar basis. Dr. Janeczko has built this capability into his software

as well. With this feature you can program with your precious If constructs. Here

is a familiar algorithm utilizing loops:

PositionSize = MarginDeposit = 1;

mav = MA(C,20);

for( i = 0; i < BarCount; i++ ){

}

if (C[i] >= mav[i]) {

}

Buy[i] = 1;

if (C[i] <= mav[i]) {

}

Sell[i] = 1;

This is the simple price crossing moving average reversal algorithm. The mav

array is set to a 20-day simple moving average of closes. This line of code is still

utilizing array programming. A for loop is then set up so that individual elements

of the different arrays can be examined. The for loop construct in AFL is very

similar to one in the C language. The loop variables are controlled by what is inside

the parentheses.

(i= 0; i < BarCount; i++ )

Here the loop will start at zero and stop at BarCount and the loop variable i will

increment by one each time i++. The i++ is the same as i = i + 1; since we are

not processing arrays, we can now use if constructs. Notice how the comparison of

the C[i] element and the mav[i] element is enclosed in parentheses. If the close is

greater than the 20-bar moving average, then the following code is executed: Buy[i]

= 1; This sets the ith element in the Buy array to one. Also, notice how the curly

brackets {}are used in the code. The curly brackets inform the computer and the

139

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!