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.

if prices[curBar - offset] < prices[curBar - 1 - offset]:

diff2 = prices[curBar - 1 - offset] - prices[curBar - offset]

dnSum += diff2

self.delta1 = (self.delta1 * (lookBack -1) + upSum) / lookBack

self.delta2 = (self.delta2 * (lookBack -1) + dnSum) / lookBack

will be executed every time. Self.delta1 and self.delta2 are used and reassigned

each time the function is called. You might be able to see that the Wilder’s averaging

method is being used to calculate the current RSI components:

upSumAvg today = (upSumAvg yesterday ∗ 13 + upSum today )

14

The final snippet of code is executed every time and returns the RSI calculation.

178

if self.delta1 + self.delta2 != 0:

self.rsi = (100.0 * self.delta1) / (self.delta1 + self.delta2)

else:

self.rsi = 0.0

return (self.rsi)

USING PYTHON TO BACKTEST YOUR ALGORITHM

Since the design of this class-based indicator is a little more involved than a regular

run-of-the-mill function, you would expect the call routine to be more involved as

well. This is the case, but it only requires one additional line of code. In the case

of this RSI indicator, all you need to do is add the line of code to your program:

rsiStudy = rsiClass(). You can instantiate the rsiClass by calling it like a function.

Instantiation is the creation of a shell that follows the class template/plan. In this

case, the class object is assigned to the rsiStudy variable. Once the class is assigned

to a variable, you can access the data and methods of that class by using the name

of the variable (object) and dot notation. Here is how you call the calcRsi method

through the rsiStudy variable name: rsiVal = rsiStudy.calcRsi (myClose, 10,

curBar, i). That’s all there is to using the RSI indicator.

Scroll through the rest of the indicators in indicator.py and familiarize yourself

with them. You can add you own indicators by using one of the existing functions

or indicator classes as a template. Just include the code in this file and import the

name of the indicator in the main trading program.

SystemTester.py The main module that calls all the other modules is System-

Tester.py. As I explained prior, you use this as a template to develop other trading

www.rasabourse.com

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

Saved successfully!

Ooh no, something went wrong!