Git Product home page Git Product logo

cryptobacktester's Introduction

cryptobacktester's People

Contributors

michaelhly avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

cryptobacktester's Issues

Talib moving average off script

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.