-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Please add OTT (Optimized trend tracker) to Pandas_TA #387
Comments
Hello @mhgutier, Added it to the list. ✅ I appreciate that you shared both the source and your Python implementation. 😎 If you are feeling venturous, try the following guide: Creating a Custom Indicator: The Big 4. If not, hopefully someone can help implement this sooner. I'll keep you posted when it's ready on the development branch for testing. Kind Regards, |
@mhgutier |
Hi @twopirllc , Please see updated code below. please free to modify if needed. i am not a developer, just learned python in youtube , for me the code is slow unlike the way pandas_ta compute for super trend/qqe (super fast) import pandas as pd
import numpy as np
import talib
import pandas_ta
import schedule
import ccxt
exchange = ccxt.binance()
pair='ETH/USDT'
ohlc = exchange.fetch_ohlcv(pair, timeframe='5m')
df = pd.DataFrame(ohlc, columns = ['time', 'open', 'high', 'low', 'close', 'volume'])
#OTT variables
pds = 2
percent = 1.4
alpha = 2 / (pds + 1)
df['atr'] = talib.ATR(df['high'], df['low'], df['close'], timeperiod=14)
df['ud1'] = np.where(df['close'] > df['close'].shift(1), (df['close'] - df['close'].shift()) , 0)
df['dd1'] = np.where(df['close'] < df['close'].shift(1), (df['close'].shift() - df['close']) , 0)
df['UD'] = talib.SUM(df['ud1'], timeperiod=9)
df['DD'] = talib.SUM(df['dd1'], timeperiod=9)
df['CMO'] = ((df['UD'] - df['DD']) / (df['UD'] + df['DD'])).fillna(0).abs()
df['Var'] = 0.0
for i in range(pds, len(df)):
df['Var'].iat[i] = (alpha * df['CMO'].iat[i] * df['close'].iat[i]) + (1 - alpha * df['CMO'].iat[i]) * df['Var'].iat[i-1]
df['fark'] = df['Var'] * percent * 0.01
df['newlongstop'] = df['Var'] - df['fark']
df['newshortstop'] = df['Var'] + df['fark']
df['longstop'] = 0.0
df['shortstop'] = 999999999999999999
for i in (df['close']):
def maxlongstop():
df.loc[(df['newlongstop'] > df['longstop'].shift(1)) , 'longstop'] = df['newlongstop']
df.loc[(df['longstop'].shift(1) > df['newlongstop']), 'longstop'] = df['longstop'].shift(1)
return df['longstop']
def minshortstop():
df.loc[(df['newshortstop'] < df['shortstop'].shift(1)), 'shortstop'] = df['newshortstop']
df.loc[(df['shortstop'].shift(1) < df['newshortstop']), 'shortstop'] = df['shortstop'].shift(1)
return df['shortstop']
df['longstop']= np.where (
(
(df['Var'] > df['longstop'].shift(1))
),maxlongstop(),df['newlongstop']
)
df['shortstop'] = np.where(
(
(df['Var'] < df['shortstop'].shift(1))
), minshortstop(), df['newshortstop'])
#get xover
df['xlongstop'] = np.where (
(
(df['Var'].shift(1) > df['longstop'].shift(1)) &
(df['Var'] < df['longstop'].shift(1))
), 1,0)
df['xshortstop'] =np.where(
(
(df['Var'].shift(1) < df['shortstop'].shift(1)) &
(df['Var'] > df['shortstop'].shift(1))
), 1,0)
df['trend']=0
df['dir'] = 0
for i in df['close']:
df['trend'] = np.where(
(
(df['xshortstop'] == 1)
),1, (np.where((df['xlongstop'] == 1),-1,df['trend'].shift(1)))
)
df['dir'] = np.where(
(
(df['xshortstop'] == 1)
),1, (np.where((df['xlongstop'] == 1),-1,df['dir'].shift(1).fillna(1)))
)
#get OTT
df['MT'] = np.where(df['dir'] == 1, df['longstop'], df['shortstop'])
df['OTT'] = np.where(df['Var'] > df['MT'], (df['MT'] * (200 + percent) / 200), (df['MT'] * (200 - percent) / 200))
df['OTT'] = df['OTT'].shift(2)
#print OTT
pd.set_option('display.max_rows', None)
pd.set_option('display.max_columns', None)
pd.set_option('display.width', None)
pd.set_option('display.max_colwidth', None)
print(df[['close','Var','OTT']].round(2)) |
Hello @mhgutier, I will look into it as soon as I can. I will let you know when it is available to testing on the development branch. Kind Regards, |
Hi Kevin,
Please help to add OTT to pandas_ta by KivancOzbilgicin trading view.
i converted the pinescript to python, it has correct output though my logic seems to be not efficient as it takes 10 seconds or so to calculate.
i think it has almost similar logic with QQE. Thanks in advance
=================
my version
The text was updated successfully, but these errors were encountered: