Stochastic function is stuck [Python]

230
March 12, 2018, at 02:15 AM

can you point me out to what i've been doing wrong?

import time
import math
import numpy as np
import datetime
import pandas as pd
import ccxt
exchange = ccxt.kraken()
symbol = 'BTC/USD'
timeframe = '1h'

def get_candle(exchange,symbol,timeframe): # timeframe = 1m 5m 15m 30m 1h 2h... etc. 
    return exchange.fetch_ohlcv(symbol, timeframe)
ohlcv = get_candle(exchange,symbol,timeframe)
source = ohlcv

def sort_candle_highest(ohlcv,n,z):
    i = 0
    results = []
    while i < z:
        series = [x[2] for x in ohlcv]
        series = series[:len(series)-i]
        hh = highest(series,n)
        print(hh)
        results.append(hh)
        i += 1
    results.reverse()
    return results
def sort_candle_lowest(ohlcv,n,z):
    i = 0
    results = []
    while i < z:
        series = [x[3] for x in ohlcv]
        series = series[:len(series)-i]
        ll = lowest(series,n)
        print(ll)
        results.append(ll)
        i += 1
    results.reverse()
    return results
def sort_candle_lastclose(ohlcv,z): 
    i = 0
    results = []
    while i < z:
        series = [x[4] for x in ohlcv]
        series = series[:len(series)-i]
        results.append(series[-1])
    results.reverse()
    return results

def lowest(source, n):
    return np.amin(source[-n:])
def highest(source,n):
    return np.amax(source[-n:])
class indicators:
    print("noerroryet1")
    def stochastic_k(source,n,smoothK,smoothD): #for source here ohlcv (get_candle)
        print("noerroryet2")
        if smoothK > smoothD:
            ticksback = smoothK
        if smoothD > smoothK:
            ticksback = smoothD
        def stoch(source,n,ticksback):
            print("noerroryet3")
            i = 0
            close = sort_candle_lastclose(source,ticksback)
            hh = sort_candle_highest(source,n,ticksback)
            ll = sort_candle_lowest(source,n,ticksback)
            print("noerroryet3b")
            while i < ticksback:
                print("noerroryet3c")
                results.append(( 100 * (close[-ticksback+i-1]-ll[-ticksback+i-1]) ) / ( hh[-ticksback+i-1] - ll[-ticksback+i-1] ))
                i += 1
                print("noerroryet4")
            return results

        print(stoch(source,n,ticksback)+'lol')
    stochastic_k(source,15,1,5)

So im trying to calculate some cool indicators and the function is stuck simply running never ending never printing anything. I have no idea where the mistake is, although its definitely connected with stochastic calculations, i need to get the list of stoch values to than calculate SMA from, i think [-ticksback+i-1] should be giving me the correct value in list not sure tho because it wont spit out anything...

Rent Charter Buses Company
READ ALSO
TCP handshake via raw sockets reset connection

TCP handshake via raw sockets reset connection

I am trying to implement handshaking functionality (SOCK_RAW)I am sending SYN packet and server responds via SYN+ACK packet but i finish the connection with reset

307
Conditional SASS Variables using mixin&#39;s

Conditional SASS Variables using mixin's

I am currently using this mixin:

194
css transition on horizontal &amp; vertical scroll with jQuery detection

css transition on horizontal & vertical scroll with jQuery detection

I've found a nice script to add and remove the class "in-view" to an element on vertical scrolling

198
Github pages code blocks behave differently offline and online

Github pages code blocks behave differently offline and online

The offline version is the one I'd like to get and it looks like this:

196