def fwma(close, length=None, asc=None, offset=None, **kwargs): """Indicator: Fibonacci's Weighted Moving Average (FWMA)""" # Validate Arguments length = int(length) if length and length > 0 else 10 asc = asc if asc else True close = verify_series(close, length) offset = get_offset(offset) if close is None: return # Calculate Result fibs = fibonacci(n=length, weighted=True) fwma = close.rolling(length, min_periods=length).apply(weights(fibs), raw=True) # Offset if offset != 0: fwma = fwma.shift(offset) # Handle fills if "fillna" in kwargs: fwma.fillna(kwargs["fillna"], inplace=True) if "fill_method" in kwargs: fwma.fillna(method=kwargs["fill_method"], inplace=True) # Name & Category fwma.name = f"FWMA_{length}" fwma.category = "overlap" return fwma
def sinwma(close, length=None, offset=None, **kwargs): """Indicator: Sine Weighted Moving Average (SINWMA) by Everget of TradingView""" # Validate Arguments length = int(length) if length and length > 0 else 14 close = verify_series(close, length) offset = get_offset(offset) if close is None: return # Calculate Result sines = Series([npSin((i + 1) * npPi / (length + 1)) for i in range(0, length)]) w = sines / sines.sum() sinwma = close.rolling(length, min_periods=length).apply(weights(w), raw=True) # Offset if offset != 0: sinwma = sinwma.shift(offset) # Handle fills if "fillna" in kwargs: sinwma.fillna(kwargs["fillna"], inplace=True) if "fill_method" in kwargs: sinwma.fillna(method=kwargs["fill_method"], inplace=True) # Name & Category sinwma.name = f"SINWMA_{length}" sinwma.category = "overlap" return sinwma
def cg(close, length=None, offset=None, **kwargs): """Indicator: Center of Gravity (CG)""" # Validate Arguments close = verify_series(close) length = int(length) if length and length > 0 else 10 offset = get_offset(offset) # Calculate Result coefficients = [length - i for i in range(0, length)] numerator = -close.rolling(length).apply(weights(coefficients), raw=True) cg = numerator / close.rolling(length).sum() # Offset if offset != 0: cg = cg.shift(offset) # Handle fills if "fillna" in kwargs: cg.fillna(kwargs["fillna"], inplace=True) if "fill_method" in kwargs: cg.fillna(method=kwargs["fill_method"], inplace=True) # Name and Categorize it cg.name = f"CG_{length}" cg.category = "momentum" return cg
def swma(close, length=None, asc=None, offset=None, **kwargs): """Indicator: Symmetric Weighted Moving Average (SWMA)""" # Validate Arguments length = int(length) if length and length > 0 else 10 # min_periods = int(kwargs["min_periods"]) if "min_periods" in kwargs and kwargs["min_periods"] is not None else length asc = asc if asc else True close = verify_series(close, length) offset = get_offset(offset) if close is None: return # Calculate Result triangle = symmetric_triangle(length, weighted=True) swma = close.rolling(length, min_periods=length).apply(weights(triangle), raw=True) # swma = close.rolling(length).apply(weights(triangle), raw=True) # Offset if offset != 0: swma = swma.shift(offset) # Handle fills if "fillna" in kwargs: swma.fillna(kwargs["fillna"], inplace=True) if "fill_method" in kwargs: swma.fillna(method=kwargs["fill_method"], inplace=True) # Name & Category swma.name = f"SWMA_{length}" swma.category = "overlap" return swma
def pwma(close, length=None, asc=None, offset=None, **kwargs): """Indicator: Pascals Weighted Moving Average (PWMA)""" # Validate Arguments close = verify_series(close) length = int(length) if length and length > 0 else 10 min_periods = int( kwargs["min_periods"]) if "min_periods" in kwargs and kwargs[ "min_periods"] is not None else length asc = asc if asc else True offset = get_offset(offset) # Calculate Result triangle = pascals_triangle(n=length - 1, weighted=True) pwma = close.rolling(length, min_periods=length).apply(weights(triangle), raw=True) # Offset if offset != 0: pwma = pwma.shift(offset) # Name & Category pwma.name = f"PWMA_{length}" pwma.category = "overlap" return pwma
def pwma(close, length=None, asc=None, offset=None, **kwargs): """Indicator: Pascals Weighted Moving Average (PWMA)""" # Validate Arguments length = int(length) if length and length > 0 else 10 asc = asc if asc else True close = verify_series(close, length) offset = get_offset(offset) if close is None: return # Calculate Result triangle = pascals_triangle(n=length - 1, weighted=True) pwma = close.rolling(length, min_periods=length).apply(weights(triangle), raw=True) # Offset if offset != 0: pwma = pwma.shift(offset) # Handle fills if "fillna" in kwargs: pwma.fillna(kwargs["fillna"], inplace=True) if "fill_method" in kwargs: pwma.fillna(method=kwargs["fill_method"], inplace=True) # Name & Category pwma.name = f"PWMA_{length}" pwma.category = "overlap" return pwma
def sinwma(close, length=None, asc=None, offset=None, **kwargs): """Indicator: Sine Weighted Moving Average (SINWMA) by Everget of TradingView""" # Validate Arguments close = verify_series(close) length = int(length) if length and length > 0 else 14 min_periods = int( kwargs["min_periods"]) if "min_periods" in kwargs and kwargs[ "min_periods"] is not None else length offset = get_offset(offset) # Calculate Result sines = Series( [sin((i + 1) * pi / (length + 1)) for i in range(0, length)]) w = sines / sines.sum() sinwma = close.rolling(length, min_periods=length).apply(weights(w), raw=True) # Offset if offset != 0: sinwma = sinwma.shift(offset) # Name & Category sinwma.name = f"SINWMA_{length}" sinwma.category = "overlap" return sinwma
def fwma(close, length=None, asc=None, offset=None, **kwargs): """Indicator: Fibonacci's Weighted Moving Average (FWMA)""" # Validate Arguments close = verify_series(close) length = int(length) if length and length > 0 else 10 min_periods = int(kwargs["min_periods"]) if "min_periods" in kwargs and kwargs["min_periods"] is not None else length asc = asc if asc else True offset = get_offset(offset) # Calculate Result fibs = fibonacci(n=length, weighted=True) fwma = close.rolling(length, min_periods=length).apply(weights(fibs), raw=True) # Offset if offset != 0: fwma = fwma.shift(offset) # Name & Category fwma.name = f"FWMA_{length}" fwma.category = "overlap" return fwma