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.

code. This is a very difficult thing to do if you are used to working in a bar-by-bar

paradigm. Instead, use something like this:

myValue = (H + L)/2;

Buy = C > myValue;

Tomasz Janeczko has provided this type of array processing functionality in his

software. This accomplishes the same thing as the previous if statement. How do

you think you compare today’s close with the prior day’s close? You can’t use an if

statement, so could you do it like this?

cond1 = C > C[1];

cond2 = C < C[1];

Buy= cond1;

Short = cond2;

If you type this in and check the syntax, it will pass. You will also be able to send it

to an Analysis window, and backtest it. However, it will not work. The computer

doesn’t come out and say, ‘‘I’m sorry, Dave, I’m afraid I can’t do that.’’ It just

won’t generate the correct trades. These statements are syntactically correct, but

they are logically incorrect. You are comparing the first element of the close array

with the close array. In other words, you are comparing an element in the list with

the list. This is how you do it in AFL:

cond1 = C > Ref(C,-1);

cond2 = C < Ref(C,-1);

Buy= cond1;

Short = cond2;

The Ref(C,-1) function returns the prior close price in the close array. The function

processes the array and allows you to compare today’s closing price with yesterday’s

closing price. You can use any negative number to reference previous values of any

array. You can do this as well:

131

INTRODUCTION TO AMIBROKER’S AFL

myValue = (H + L)/2;

cond1 = myValue > Ref(myValue,-1);

And you have probably noticed that all lines end with a semicolon (;). This tells the

parser that the line of code has terminated and to go onto the next line. What do

you think the next bit of code does?

www.rasabourse.com

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

Saved successfully!

Ooh no, something went wrong!