Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def FVE(cls, ohlc: DataFrame, period: int = 22, factor: int = 0.3) -> Series:
"""
FVE is a money flow indicator, but it has two important innovations: first, the F VE takes into account both intra and
interday price action, and second, minimal price changes are taken into account by introducing a price threshold.
"""
hl2 = (ohlc["high"] + ohlc["low"]) / 2
tp = TA.TP(ohlc)
smav = ohlc["volume"].rolling(window=period).mean()
mf = pd.Series((ohlc["close"] - hl2 + tp.diff()), name="mf")
_mf = pd.concat([ohlc["close"], ohlc["volume"], mf], axis=1)
def vol_shift(row):
if row["mf"] > factor * row["close"] / 100:
return row["volume"]
elif row["mf"] < -factor * row["close"] / 100:
return -row["volume"]
else:
return 0
_mf["vol_shift"] = _mf.apply(vol_shift, axis=1)
_sum = _mf["vol_shift"].rolling(window=period).sum()
def PERCENT_B(
cls, ohlc: DataFrame, period: int = 20, MA: Series = None, column: str = "close"
) -> Series:
"""
%b (pronounced 'percent b') is derived from the formula for Stochastics and shows where price is in relation to the bands.
%b equals 1 at the upper band and 0 at the lower band.
"""
BB = TA.BBANDS(ohlc, period, MA, column)
percent_b = pd.Series(
(ohlc["close"] - BB["BB_LOWER"]) / (BB["BB_UPPER"] - BB["BB_LOWER"]),
name="%b",
)
return percent_b
name="EMA_slow",
)
MACD = pd.Series((EMA_fast - EMA_slow), name="MACD")
STOK = ((MACD - MACD.rolling(window=period).min()) / (
MACD.rolling(window=period).max() - MACD.rolling(window=period).min())) * 100
STOD = STOK.rolling(window=period).mean()
return pd.Series(
100 * (MACD - (STOK * MACD)) / ((STOD * MACD) - (STOK * MACD)),
name="{0} period STC.".format(period)
)
if __name__ == "__main__":
print([k for k in TA.__dict__.keys() if k[0] not in "_"])