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.

FIGURE 5.10 Comment text in VBA code is written in gray. It is also indicated by the single

quote at the beginning of each line.

data (row 3 in our case) holds the date, open, high, low, close, volume, and open

interest for one day of data. Think of the data as just in one big table consisting of

rows and columns. If you want the data of the very first bar, you would access it

using the following notation: Cells (3, 1). In Excel, cells refer to the entire table and

the first index value inside the parentheses refers to the row number and the second

index value is the column number. Cells (3, 2) refer to the open price of the very

first bar. A newcomer to VBA might not know this nomenclature so it is included

in this comment block. Since all of the data is being read into individual arrays you

do not need to concern yourself with notion of cells, unless you want to.

Scroll down in the code until you find a comment block that looks like the one in

Figure 5.11.

All the code that you scrolled through until you got to this point can be ignored.

This area of the source code is used to set up any system-specific variables. The

two lines of code following the comment block set rampUp to 100 and commsn

to 100. Notice there are lines of comments to the right of each variable assignment.

These are inline comments to let you know what that exact line of code is doing.

You will again see the single quote (‘) preceding the comment. Whatever follows

the single quote is ignored by the computer, be it at the beginning of a line of code

or right in the middle. The rampUp variable informs the computer that the trading

algorithm needs 100 days of data for calculation purposes before it can initiate

trading. If you want to test a 100-day simple moving average algorithm, you would

need to tell the ESB to skip the first 100 days of data so that the moving average

157

USING MICROSOFT EXCEL TO BACKTEST YOUR ALGORITHM

FIGURE 5.11

This is where the VBA comments end and the actual source code begins.

www.rasabourse.com

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

Saved successfully!

Ooh no, something went wrong!