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.

318

PYTHON SYSTEM BACKTESTER

for i in range((curBar - offset) - (lookBack-1),

curBar - offset +1):

if prices[i] > prices[i-1]:

diff1 = prices[i] - prices[i-1]

upSum += diff1

if prices[i] < prices[i-1]:

diff2 = prices[i-1] - prices[i]

dnSum += diff2

self.delta1 = upSum/lookBack

self.delta2 = dnSum/lookBack

else:

if prices[curBar - offset] > prices[curBar - 1

- offset]:

diff1 = prices[curBar - offset] -

prices[curBar - 1 - offset]

upSum += diff1

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

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

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

+ self.delta2)

else:

self.rsi = 0.0

return (self.rsi)

Highest Function/Module

def highest(prices,lookBack,curBar,offset):

result = 0.0

maxVal = 0.00

for index in range((curBar - offset) - (lookBack-1),

curBar - offset +1):

if prices[index] > maxVal:

maxVal = prices[index]

result = maxVal

return result

www.rasabourse.com

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

Saved successfully!

Ooh no, something went wrong!