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.

you don’t need to know exactly how one works to use it. This software allows the

users to do whatever they want, including looking into the future, so be careful.

Our first test is going to be the ol’ Bollinger Band algorithm.

194

USING PYTHON TO BACKTEST YOUR ALGORITHM

for i in range(len(myDate) - numBarsToGoBack,len(myDate)):

equItm += 1

tempDate = myDate[i]

todaysCTE = todaysOTE = todaysEquity = 0

marketPosition[i] = marketPosition[i-1]

mp = marketPosition[i]

buyLevel,shortLevel,exitLevel = bollingerBands

(myDate,myClose,60,2,i,1)

print(tempDate," avg ",exitLevel," ",buyLevel - exitLevel)

atrVal = sAverage(trueRanges,10,i,0)

rsiVal = rsiStudy.calcRsi(myClose,10,i,0)

stopAmt = 3000/myBPV

# print(myDate[i],"rsi ",rsiVal," atrVal ",

atrVal*myBPV," ",myBPV)

# fastKVal,fastDVal,slowDVal = stochStudy.

# calcStochastic(3,9,9,myHigh,

myLow,myClose,i,1)

# if (mp > 0 and maxPositionL < 3) : maxPositionL = mp

# if (mp < 0 and maxPositionS < 3) : maxPositionS = mp

#Long Entry Logic - Bolloinger

if (mp == 0 or mp == -1) and myHigh[i] >= buyLevel:

profit = 0

price = max(myOpen[i],buyLevel)

if mp <= -1:

profit,trades,curShares = exitPos(price,

myDate[i],"RevShrtLiq",curShares)

listOfTrades.append(trades)

mp = 0

todaysCTE = profit

tradeName = "Boll Buy"

mp += 1

marketPosition[i] = mp

numShares = 1

entryPrice.append(price)

entryQuant.append(numShares)

curShares = curShares + numShares

www.rasabourse.com

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

Saved successfully!

Ooh no, something went wrong!