From cf013140a6b7ed5847bcbf64e05cb7ccab091fbf Mon Sep 17 00:00:00 2001 From: Janne Sinivirta Date: Tue, 13 Feb 2018 11:37:59 +0200 Subject: [PATCH] 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]))