michaelhly / cryptobacktester Goto Github PK
View Code? Open in Web Editor NEWThis is a backtesting platform to test trading strategies
This is a backtesting platform to test trading strategies
If someone reads my code, can someone tell me why when I replace the code from line 94 to line 143
with this portion,
#INITIALIZE SRATEGY OBJECTS TO KEEP TRACK OF
timeframe = 50
upper, middle, lower = talib.BBANDS(np.array(close_prices),timeframe,nbdevup=2,nbdevdn=2,matype=0)
if(timeframe > len(dates)):
raise ValueError("Timeframe cannot be greater than the total amount of candles")
# MAIN LOOP
def main():
# INDEX: Index of current candle from the historical data, start from 0 to len(dates)
# DATE: Date of the current candle
for index,date in enumerate(dates[timeframe:]):
#--------------------------------IMPLEMENT STRATEGY HERE--------------------------------------------#
#Bollinger Band strategy from http://pythontrader.blogspot.com/2015/05/ta-lib-usage-bollinger-bands.html
#Localize Data
close = close_prices[index]
up = upper[index]
mid = middle[index]
low = lower[index]
# If price is below the recent lower band and we have
# no long positions then invest the entire
#portfolio value into ASSET
if close < low:
if portfolio['currency'] > 0:
test_buy(time = date, price=close)
storage['trades']+=1
# If price is above the recent upper band and we have
# no short positions then invest the entire
# portfolio value to short ASSET
elif close > up:
if portfolio['assets'] > 0:
test_sell(time = date, price=close)
storage['trades']+=1
and def chart() with this
def chart():
# PLOT OBJECTS
ax1.plot(dates[timeframe:],close_prices[timeframe:],linestyle="",marker='.',
color='white',label='PRICE')
ax1.plot(dates[timeframe:],upper[timeframe:],color='b',label='UPPERBAND')
ax1.plot(dates[timeframe:],middle[timeframe:],color='g',label='MIDDLEBAND')
ax1.plot(dates[timeframe:],lower[timeframe:],color='r',label='LOWERBAND')
# PLOT VOLUME
#*************Width of volume bar should be widened accordingly
#*************Will find a way to fix small bars
ax2.bar(dates[timeframe:],volume[timeframe:], width=200)
#FORMATTING
plt.suptitle("BACKTEST RESULT: %s, %s - %s" % (PAIR, datetime.datetime.utcfromtimestamp(info['begin']), datetime.datetime.utcfromtimestamp(info['end'])))
plt.setp(ax1.get_xticklabels(), visible = False)
ax1.autoscale(enable=True, axis='y')
ax1.autoscale(enable=True, axis='x')
ax1.get_xaxis().get_major_formatter().set_useOffset(False)
ax1.get_xaxis().get_major_formatter().set_scientific(False)
ax1.grid(True)
for label in ax2.xaxis.get_ticklabels():
label.set_rotation(90)
The bollinger bands become off script? And the test buys and test sells are executed at inaccurate places?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.