From cf013140a6b7ed5847bcbf64e05cb7ccab091fbf Mon Sep 17 00:00:00 2001 From: Janne Sinivirta Date: Tue, 13 Feb 2018 11:37:59 +0200 Subject: [PATCH 1/4] add went_up and went_down helpers --- freqtrade/indicator_helpers.py | 9 +++++++++ freqtrade/tests/test_indicator_helpers.py | 12 ++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 freqtrade/indicator_helpers.py create mode 100644 freqtrade/tests/test_indicator_helpers.py diff --git a/freqtrade/indicator_helpers.py b/freqtrade/indicator_helpers.py new file mode 100644 index 000000000..7464710d6 --- /dev/null +++ b/freqtrade/indicator_helpers.py @@ -0,0 +1,9 @@ +from pandas import Series + + +def went_up(series: Series) -> Series: + return series > series.shift(1) + + +def went_down(series: Series) -> Series: + return series < series.shift(1) diff --git a/freqtrade/tests/test_indicator_helpers.py b/freqtrade/tests/test_indicator_helpers.py new file mode 100644 index 000000000..90330a6ef --- /dev/null +++ b/freqtrade/tests/test_indicator_helpers.py @@ -0,0 +1,12 @@ +import pandas as pd +from freqtrade.indicator_helpers import went_up, went_down + + +def test_went_up(): + series = pd.Series([1, 2, 3, 1]) + assert went_up(series).equals(pd.Series([False, True, True, False])) + + +def test_went_down(): + series = pd.Series([1, 2, 3, 1]) + assert went_down(series).equals(pd.Series([False, False, False, True])) From 178d1ed4237505a5b5c2a2406ec15a6aecd70933 Mon Sep 17 00:00:00 2001 From: Janne Sinivirta Date: Tue, 13 Feb 2018 17:47:26 +0200 Subject: [PATCH 2/4] add ehlers super smoother --- freqtrade/indicator_helpers.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/freqtrade/indicator_helpers.py b/freqtrade/indicator_helpers.py index 7464710d6..ef2db0193 100644 --- a/freqtrade/indicator_helpers.py +++ b/freqtrade/indicator_helpers.py @@ -1,3 +1,5 @@ +from math import exp, pi, sqrt, cos + from pandas import Series @@ -7,3 +9,19 @@ def went_up(series: Series) -> Series: def went_down(series: Series) -> Series: return series < series.shift(1) + + +def ehlers_super_smoother(series: Series, smoothing: float = 6): + magic = pi * sqrt(2) / smoothing + a1 = exp(-magic) + coeff2 = 2 * a1 * cos(magic) + coeff3 = -a1 * a1 + coeff1 = (1 - coeff2 - coeff3) / 2 + + filtered = series.copy() + + for i in range(2, len(series)): + filtered.iloc[i] = coeff1 * (series.iloc[i] + series.iloc[i-1]) + \ + coeff2 * filtered.iloc[i-1] + coeff3 * filtered.iloc[i-2] + + return filtered From 340ab0214be0b6bcea0b576d4b1a7f5bcdc82c30 Mon Sep 17 00:00:00 2001 From: Janne Sinivirta Date: Wed, 14 Feb 2018 10:17:43 +0200 Subject: [PATCH 3/4] add generic fishers inverse transformation with smoothing --- freqtrade/indicator_helpers.py | 13 +++++++++++++ freqtrade/strategy/default_strategy.py | 6 +++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/freqtrade/indicator_helpers.py b/freqtrade/indicator_helpers.py index ef2db0193..c3cc42e6a 100644 --- a/freqtrade/indicator_helpers.py +++ b/freqtrade/indicator_helpers.py @@ -1,5 +1,7 @@ from math import exp, pi, sqrt, cos +import numpy +import talib as ta from pandas import Series @@ -25,3 +27,14 @@ def ehlers_super_smoother(series: Series, smoothing: float = 6): coeff2 * filtered.iloc[i-1] + coeff3 * filtered.iloc[i-2] return filtered + + +def fishers_inverse(series: Series, smoothing: float = 0): + """ Does a smoothed fishers inverse transformation. + Can be used with any oscillator that goes from 0 to 100 like RSI or MFI """ + v1 = 0.1 * (series - 50) + if smoothing > 0: + v2 = ta.WMA(v1.values, timeperiod=smoothing) + else: + v2 = v1 + return (numpy.exp(2 * v2)-1) / (numpy.exp(2 * v2) + 1) diff --git a/freqtrade/strategy/default_strategy.py b/freqtrade/strategy/default_strategy.py index abccf065b..adfa66826 100644 --- a/freqtrade/strategy/default_strategy.py +++ b/freqtrade/strategy/default_strategy.py @@ -4,7 +4,7 @@ import talib.abstract as ta from pandas import DataFrame import freqtrade.vendor.qtpylib.indicators as qtpylib from freqtrade.strategy.interface import IStrategy - +from freqtrade.indicator_helpers import fishers_inverse class_name = 'DefaultStrategy' @@ -76,8 +76,8 @@ class DefaultStrategy(IStrategy): dataframe['rsi'] = ta.RSI(dataframe) """ # Inverse Fisher transform on RSI, values [-1.0, 1.0] (https://goo.gl/2JGGoy) - rsi = 0.1 * (dataframe['rsi'] - 50) - dataframe['fisher_rsi'] = (numpy.exp(2 * rsi) - 1) / (numpy.exp(2 * rsi) + 1) + dataframe['fisher_rsi'] = fishers_inverse(dataframe['rsi']) + # Inverse Fisher transform on RSI normalized, value [0.0, 100.0] (https://goo.gl/2JGGoy) dataframe['fisher_rsi_norma'] = 50 * (dataframe['fisher_rsi'] + 1) # Stoch From 459611516c4bd1ba1627bccaeffb447d21793acf Mon Sep 17 00:00:00 2001 From: Janne Sinivirta Date: Wed, 14 Feb 2018 13:01:30 +0200 Subject: [PATCH 4/4] enable stochastic and fisherRSI in default strategy --- freqtrade/strategy/default_strategy.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/freqtrade/strategy/default_strategy.py b/freqtrade/strategy/default_strategy.py index adfa66826..2247ecf27 100644 --- a/freqtrade/strategy/default_strategy.py +++ b/freqtrade/strategy/default_strategy.py @@ -74,17 +74,18 @@ class DefaultStrategy(IStrategy): """ # RSI dataframe['rsi'] = ta.RSI(dataframe) - """ + # Inverse Fisher transform on RSI, values [-1.0, 1.0] (https://goo.gl/2JGGoy) dataframe['fisher_rsi'] = fishers_inverse(dataframe['rsi']) # Inverse Fisher transform on RSI normalized, value [0.0, 100.0] (https://goo.gl/2JGGoy) dataframe['fisher_rsi_norma'] = 50 * (dataframe['fisher_rsi'] + 1) + # Stoch stoch = ta.STOCH(dataframe) dataframe['slowd'] = stoch['slowd'] dataframe['slowk'] = stoch['slowk'] - """ + # Stoch fast stoch_fast = ta.STOCHF(dataframe) dataframe['fastd'] = stoch_fast['fastd']