def keltnerChannel(df, kc_len): df_kc = df.ta.kc(length=kc_len) kc_low = df_kc.iloc[:, 0] kc_upp = df_kc.iloc[:, 2] kc_ul = ta.above(df.close, kc_upp) kc_ll = ta.below(df.close, kc_low) kc_ul.iloc[:kc_len] = np.nan kc_ll.iloc[:kc_len] = np.nan return kc_ll, kc_ul
def donchianChannel(df, dc_llen, dc_ulen): df_dc = ta.donchian(df.close, uper_lenght=dc_ulen, lower_length=dc_llen) dc_low = df_dc.iloc[:, 0] dc_upp = df_dc.iloc[:, 2] dc_ul = ta.above(df.close, dc_upp) dc_ll = ta.below(df.close, dc_low) dc_ul.iloc[:max([dc_llen, dc_ulen])] = np.nan dc_ll.iloc[:max([dc_llen, dc_ulen])] = np.nan return dc_ll, dc_ul
def bollingerBands(df, bb_per): df_bb = df.ta.bbands(length=bb_per) bol_low = df_bb.iloc[:, 0] bol_upp = df_bb.iloc[:, 2] bb_ll = ta.below(df.close, bol_low) bb_ul = ta.above(df.close, bol_upp) bb_ll.iloc[:bb_per] = np.nan bb_ul.iloc[:bb_per] = np.nan return bb_ll, bb_ul
def movingAverage(df, fast_p, slow_p): smas = df.ta.sma(length=fast_p) smal = df.ta.sma(length=slow_p) ma_buy = ta.cross(smas, smal, above=True) ma_sell = ta.cross(smas, smal, above=False) ma_upw = ta.above(smas, smal) ma_buy.iloc[:fast_p] = np.nan ma_sell.iloc[:fast_p] = np.nan ma_upw.iloc[:fast_p] = np.nan return ma_buy, ma_sell, ma_upw
def adx(df, adx_len, adx_ul): df_adx = df.ta.adx(length=adx_len) adx, dmp, dmm = df_adx.iloc[:, 0], df_adx.iloc[:, 1], df_adx.iloc[:, 2] adx_force = ta.above_value(adx, adx_ul) adx_buy = ta.cross(dmp, dmm, above=True) adx_sell = ta.cross(dmp, dmm, above=False) adx_upw = ta.above(dmp, dmm) adx_force.iloc[:adx_len] = np.nan adx_buy.iloc[:adx_len] = np.nan adx_sell.iloc[:adx_len] = np.nan adx_upw.iloc[:adx_len] = np.nan return adx_force, adx_buy, adx_sell, adx_upw
def macd(df, macd_fast_p, macd_slow_p, macd_sign_p): df_macd = df.ta.macd(fast=macd_fast_p, slow=macd_slow_p, signal=macd_sign_p) macd_macd = df_macd.iloc[:, 0] macd_sign = df_macd.iloc[:, 2] macd_buy = ta.cross(macd_sign, macd_macd, above=True) macd_sell = ta.cross(macd_sign, macd_macd, above=False) macd_upw = ta.above(macd_sign, macd_macd) macd_buy.iloc[:macd_slow_p] = np.nan macd_sell.iloc[:macd_slow_p] = np.nan macd_upw.iloc[:macd_slow_p] = np.nan return macd_buy, macd_sell, macd_upw