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.

that you are reassigning a variable that is already used elsewhere in the source

code. A list of keywords is provided in the appendix to help prevent this from

happening.

Let’s get to the heart of the ESB by scrolling down to the main trading loop. You

can find it by looking for the comment block that says, ‘‘Main Trading Loop.’’ The

entire Main Trading Loop is shown below. This includes some of the code we have

already discussed and some code that you can simply ignore.

’****************************************************************

’**** Main Trading Loop ****

’****************************************************************

Do While i <= numRecords

tradeDays = tradeDays + 1

IncrementalProgress.Show

i = i + 1

’Dont touch

sPercentage = (i / numRecords) * 100

sStatus = "Checking " & i & " of " & numRecords &

" paragraphs"

IncrementalProgress.Increment sPercentage, sStatus

intraDayTrdCnt = 0

’Leave in.

If barsLong <> 0 Then barsLong = barsLong + 1 ’Leave in.

If barsShort <> 0 Then barsShort = barsShort + 1 ’Leave in.

’****************************************************************

’**** This is a good place to put all of your function calls ****

’**** and system calculations. ****

’****************************************************************

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

simpleAvg = Average(myClose, 10, i, 1)

rsiVal = RSI(myClose, 14, i, 1)

Call Stochastic(3, 4, 7, stoK, stoD, slowD, i, 1)

’****************************************************************

’**** Put All Of Your Orders Here ****

’****************************************************************

prevMarketPosition = marketPosition

If marketPosition <> 1 Then

Call Trade(Buy, "BB-Buy", upBand, stp, i)

End If

If marketPosition <> -1 Then

Call Trade(Sell, "BB-Short", dnBand, stp, i)

159

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!