def chop(high, low, close, length=None, atr_length=None, ln=None, scalar=None, drift=None, offset=None, **kwargs): """Indicator: Choppiness Index (CHOP)""" # Validate Arguments length = int(length) if length and length > 0 else 14 atr_length = int( atr_length) if atr_length is not None and atr_length > 0 else 1 ln = bool(ln) if isinstance(ln, bool) else False scalar = float(scalar) if scalar else 100 high = verify_series(high, length) low = verify_series(low, length) close = verify_series(close, length) drift = get_drift(drift) offset = get_offset(offset) if high is None or low is None or close is None: return # Calculate Result diff = high.rolling(length).max() - low.rolling(length).min() atr_ = atr(high=high, low=low, close=close, length=atr_length) atr_sum = atr_.rolling(length).sum() chop = scalar if ln: chop *= (npLn(atr_sum) - npLn(diff)) / npLn(length) else: chop *= (npLog10(atr_sum) - npLog10(diff)) / npLog10(length) # Offset if offset != 0: chop = chop.shift(offset) # Handle fills if "fillna" in kwargs: chop.fillna(kwargs["fillna"], inplace=True) if "fill_method" in kwargs: chop.fillna(method=kwargs["fill_method"], inplace=True) # Name and Categorize it chop.name = f"CHOP{'ln' if ln else ''}_{length}_{atr_length}_{scalar}" chop.category = "trend" return chop
def chop( high, low, close, length=None, atr_length=None, scalar=None, drift=None, offset=None, **kwargs, ): """Indicator: Choppiness Index (CHOP)""" # Validate Arguments high = verify_series(high) low = verify_series(low) close = verify_series(close) length = int(length) if length and length > 0 else 14 atr_length = int( atr_length) if atr_length is not None and atr_length > 0 else 1 scalar = float(scalar) if scalar else 100 drift = get_drift(drift) offset = get_offset(offset) # Calculate Result diff = high.rolling(length).max() - low.rolling(length).min() atr_ = atr(high=high, low=low, close=close, length=atr_length) atr_sum = atr_.rolling(length).sum() chop = scalar * (npLog10(atr_sum) - npLog10(diff)) chop /= npLog10(length) # Offset if offset != 0: chop = chop.shift(offset) # Handle fills if "fillna" in kwargs: chop.fillna(kwargs["fillna"], inplace=True) if "fill_method" in kwargs: chop.fillna(method=kwargs["fill_method"], inplace=True) # Name and Categorize it chop.name = f"CHOP_{length}_{atr_length}_{scalar}" chop.category = "trend" return chop