diff --git a/pandas_ta/utils/_signals.py b/pandas_ta/utils/_signals.py index 18b71e0..4c90a52 100644 --- a/pandas_ta/utils/_signals.py +++ b/pandas_ta/utils/_signals.py @@ -77,6 +77,8 @@ def cross(series_a: Series, series_b: Series, above: bool = True, asint: bool = previous = series_a.shift(1) < series_b.shift(1) # previous is below # above if both are true, below if both are false cross = current & previous if above else ~current & ~previous + # ensure there is no cross on the first entry + cross[0] = False if asint: cross = cross.astype(int) diff --git a/tests/test_utils.py b/tests/test_utils.py index 62c645e..7d83d1e 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -2,7 +2,6 @@ from .config import sample_data from .context import pandas_ta from unittest import skip, TestCase -from unittest.mock import patch import numpy as np import numpy.testing as npt @@ -139,6 +138,9 @@ class TestUtilities(TestCase): self.assertIsInstance(result, Series) npt.assert_array_equal(result, self.crosseddf["crossed"]) + result = self.utils.cross(self.crosseddf["a"], self.crosseddf["b"], above=False) + self.assertFalse(result[0]) + def test_df_dates(self): result = self.utils.df_dates(self.data) self.assertEqual(None, result) @@ -184,7 +186,6 @@ class TestUtilities(TestCase): npt.assert_allclose(self.utils.fibonacci(n=5, zero=True, weighted=True), np.array([0, 1 / 12, 1 / 12, 1 / 6, 1 / 4, 5 / 12])) npt.assert_allclose(self.utils.fibonacci(n=5, zero=False, weighted=True), np.array([1 / 12, 1 / 12, 1 / 6, 1 / 4, 5 / 12])) - def test_geometric_mean(self): returns = pandas_ta.percent_return(self.data.close) result = self.utils.geometric_mean(returns)