Skip to content

Commit

Permalink
Merge pull request #356 from freqtrade/stash86-patch-1
Browse files Browse the repository at this point in the history
the zema written here is actually DEMA
  • Loading branch information
xmatthias committed Aug 11, 2023
2 parents 3df8153 + 0f68937 commit efbdb9a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 21 deletions.
5 changes: 1 addition & 4 deletions technical/indicators/indicators.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from numpy.core.records import ndarray
from pandas import DataFrame, Series

from .overlap_studies import sma, vwma, zema
from .overlap_studies import sma, vwma

########################################
#
Expand Down Expand Up @@ -1134,7 +1134,6 @@ def PMAX(dataframe, period=10, multiplier=3, length=12, MAtype=1, src=1): # noq
# MAtype==6 --> TEMA
# MAtype==7 --> WMA
# MAtype==8 --> VWMA
# MAtype==9 --> zema
if src == 1:
masrc = df["close"]
elif src == 2:
Expand All @@ -1157,8 +1156,6 @@ def PMAX(dataframe, period=10, multiplier=3, length=12, MAtype=1, src=1): # noq
df[mavalue] = ta.WMA(df, timeperiod=length)
elif MAtype == 8:
df[mavalue] = vwma(df, length)
elif MAtype == 9:
df[mavalue] = zema(df, period=length)
# Compute basic upper and lower bands
df["basic_ub"] = df[mavalue] + (multiplier * df[atr])
df["basic_lb"] = df[mavalue] - (multiplier * df[atr])
Expand Down
20 changes: 4 additions & 16 deletions technical/indicators/overlap_studies.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def bollinger_bands(


# DEMA Double Exponential Moving Average
def dema(dataframe, period, field="close"):
import talib.abstract as ta

return ta.DEMA(dataframe, timeperiod=period, price=field)


# EMA Exponential Moving Average
Expand Down Expand Up @@ -88,19 +92,3 @@ def hull_moving_average(dataframe, period, field="close") -> ndarray:

def vwma(df, window, price="close"):
return (df[price] * df["volume"]).rolling(window).sum() / df.volume.rolling(window).sum()


def zema(dataframe, period, field="close"):
"""
zero lag ema
:param dataframe:
:param period:
:param field:
:return:
"""
dataframe = dataframe.copy()
dataframe["ema1"] = ema(dataframe, period, field)
dataframe["ema2"] = ema(dataframe, period, "ema1")
dataframe["d"] = dataframe["ema1"] - dataframe["ema2"]
dataframe["zema"] = dataframe["ema1"] + dataframe["d"]
return dataframe["zema"]
2 changes: 1 addition & 1 deletion tests/test_indicators_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
(ti.sma, [10]),
(ti.stc, []),
(ti.td_sequential, []),
(ti.dema, [10]),
(ti.tema, [10]),
# (ti.tv_hma, []),
(ti.tv_wma, []),
Expand All @@ -42,7 +43,6 @@
(ti.vwma, [10]),
(ti.vwmacd, []),
(ti.williams_percent, []),
(ti.zema, [10]),
],
)
def test_indicators_generic_interface(function, args, testdata_1m_btc):
Expand Down

0 comments on commit efbdb9a

Please sign in to comment.