lt20kmph / smi

Robo trading simulation on the Binance crypto exchange following simple strategy based on the SMI ergodic oscillator.
https://smi.lt20kmph.co.uk/ethbtc/5m
The Unlicense
3 stars 1 forks source link

TSI Indicator Code #1

Open eugjr opened 4 years ago

eugjr commented 4 years ago

Hi! I was trying to implement your TSI indicator code within a bot that I'm already running. I've copyied only the EMA and TSI code, but the values calculated are different from TradingView indicator:

The bot have a variable named "c" that stores the last 1.000 closes prices.

def EMA(L, period):
        E = []
        l = len(L)
        p = period
        for i in range(l):
            if i == 0:
                E.append(L[0])
            else:
                E.append(2/(p+1)*(L[i]-E[i-1])+E[i-1])
        return E

def TSI(L, fast, slow):
        L = L[::-1]
        l = len(L) - 1
        m = [L[i+1]-L[i] for i in range(l) if L[i+1] - L[i] != 0]
        am = [abs(i) for i in m]
        e = [EMA(EMA(m, slow), fast)[i]/EMA(EMA(am, slow), fast)[i] for i in
             range(len(m))]
        s = EMA(e, 5)
        return zip(e, s)

#def sellOrbuy(symbol, interval):
k = c
T = list(TSI(k, 5, 50))[-1]
if (T[0] > T[1]):
            print('Buy:')
elif (T[0] < T[1]):
            print('Sell:')

T = list(TSI(k, 5, 50))[-1]
print(T)
print('T0', T[0], 'T1', T[1])

The code calculate the TSI values, but they aren't the same as TradingView and doesn't intersect in same times also. You can give me a hand on this?

lt20kmph commented 4 years ago

Hi,

There are a couple of things that could go wrong if you just copied my code, I take it you have been trying with the correct parameters, there are three parameters involved which you are free to choose as you will. There's the period for the EMA, and the fast and slow periods for the TSI. Also the order of the list of inputs is important. Mine seem to be ordered most recent first. You will notice, that the first thing that happens before calculating the TSI is that the order gets reversed. It's also possible Tradingview is calculating the EMA differently. I'm not sure but I there are a few different ways you could calculate it, but all should give roughly the same results. I'm using the closes to calculate with, but there's also no good reason to do this as far as I can see, maybe Tradingview is using some other data point? Do they say how they are calculating anywhere? It's also possible there's some bug in my code so beware!