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.

learning curve. You don’t need to know VBA to invoke the indicator or trading

functions. You will just need to follow the included templates.

If you are interested in learning some VBA and want to see under the hood, a

discussion of the source code is included in the ESB appendix. First off, let’s learn

how to use the software and its indicator and trading functions. The VBA tester is

based on one large loop. The software loops through each and every bar of data and

allows the user to create indicators and analyze patterns and make trading decisions

on each and every bar. Conceptually, it works like AmiBroker and TradeStation,

but doesn’t have all the bells and whistles. It can only test one market at a time, and

has limited performance metrics. However, it is sufficient to get your feet wet,

and since the source code is open, you can take it and do as you want.

■ VBA Functions and Subroutines

The heart of this algorithm is a 60-day Bollinger Band, and just like AmiBroker,

you get access to this indicator by calling a function:

Call BollingerBand(myClose, 60, 2, avg, upBand, dnBand, i, 1)

Some indicators return a single value and some return several. This function call

is actually a subroutine that returns three parts of the Bollinger Band indicator:

the moving average, the top band, and the lower band. The subroutine needs five

inputs or arguments to calculate the bands: price (myClose), length (60), number of

deviations (2), the current bar we are on (i), and the offset (1). Don’t worry about

the difference between a subroutine and function because in this application they do

the same thing, return indicator values. The only difference is in the way you call the

indicator and how the indicator values are assigned. Notice the difference between

a pure function call and our BollingerBand subroutine call:

myHH = Highest(myHigh, 20, i, 1)

Call BollingerBand(myClose, 60, 2, avg, upBand, dnBand, i, 1)

The function Highest returns a single value and that value is assigned to the

variable myHH. The subroutine BollingerBand is invoked by preceding the name

of the subroutine with the keyword Call. The values that are used for trading decisions

are included in the list of arguments that are passed into and out of the subroutine.

The information that is passed to a function is only used by the function internally and

is not passed back. The variable in our function call, myHH, holds the output off

the function. In this case, it will be the highest high of the past 20 days starting from

yesterday. A neat feature of VBA is that once you define functions or subroutines, the

editor will help you fill out the argument list just like AmiBroker. (see figure 5.1.)

147

USING MICROSOFT EXCEL TO BACKTEST YOUR ALGORITHM

www.rasabourse.com

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

Saved successfully!

Ooh no, something went wrong!