From bb5e20bd2a5a9bb5497f9442c5b63597ab08114c Mon Sep 17 00:00:00 2001 From: Kevin Johnson Date: Sat, 8 Aug 2020 11:48:24 -0700 Subject: [PATCH 1/9] Update issue templates --- .github/ISSUE_TEMPLATE/feature_request.md | 31 +++++++++++++++++++ .../indicator-or-feature-request.md | 31 +++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100644 .github/ISSUE_TEMPLATE/indicator-or-feature-request.md diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..7979f3a --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,31 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: enhancement +assignees: '' + +--- + +**Which version are you running? The lastest version is Github. Pip is for major updates.** +```python +import pandas_ta as ta +print(ta.version) +``` + +**Upgrade.** +```sh +$ pip install -U git+https://github.com/twopirllc/pandas-ta +``` + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/.github/ISSUE_TEMPLATE/indicator-or-feature-request.md b/.github/ISSUE_TEMPLATE/indicator-or-feature-request.md new file mode 100644 index 0000000..14b521a --- /dev/null +++ b/.github/ISSUE_TEMPLATE/indicator-or-feature-request.md @@ -0,0 +1,31 @@ +--- +name: Indicator or Feature Request +about: Thanks for using Pandas TA! Please be as detailed as possible with links please. +title: '' +labels: enhancement +assignees: twopirllc + +--- + +**Which version are you running? The lastest version is Github. Pip is for major updates.** +```python +import pandas_ta as ta +print(ta.version) +``` + +**Upgrade.** +```sh +$ pip install -U git+https://github.com/twopirllc/pandas-ta +``` + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context, web links, or screenshots about the feature request here. From 1d735d7a21da1656ef6c23d5ae7967c27dd03376 Mon Sep 17 00:00:00 2001 From: Kevin Johnson Date: Thu, 13 Aug 2020 15:34:14 -0700 Subject: [PATCH 2/9] MAINT .gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index dd90ffa..bcfb84e 100644 --- a/.gitignore +++ b/.gitignore @@ -119,7 +119,9 @@ pandas_ta/_wrapper.py data/datas.csv data/SPY_5min.csv data/SPY_1min.csv +data/SPY_D_lbsz.csv data/similang-ch.csv +data/TV_5min.csv data/tulip.csv examples/taplot.py examples/charting.ipynb @@ -132,6 +134,7 @@ driver.py doc.py bt.ipynb ta_extension.ipynb +scratch.ipynb kerasmodeller.ipynb Charts.ipynb pandas_pips From 31a1758d521660bfae6b199de562084b51555bb0 Mon Sep 17 00:00:00 2001 From: Kevin Johnson Date: Thu, 13 Aug 2020 15:52:09 -0700 Subject: [PATCH 3/9] ENH remove df.ta.mp setting hint --- README.md | 1 + pandas_ta/core.py | 6 +----- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 189171a..8261533 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,7 @@ Please take a moment to read **this** and the rest of this **README** before pos * Improved the calculation performance of indicators: _Exponential Moving Averagage_ and _Weighted Moving Average_. * Removed internal core optimizations when running ```df.ta.strategy('all')``` with multiprocessing. See the ```ta.strategy()``` method for more details. +* Removed multiprocessing hint. * __New Indicators:__ Kaufman's _Efficiency Ratio_ **er**, Johnson's _Pretty Good Oscillator_ **pgo**, _Elder Ray Index_ **eri**, Martin's _Ulcer Index_ **ui**, _Squeeze_ **squeeze** (John Carter's TTM **and** Lazybear's TradingView versions) diff --git a/pandas_ta/core.py b/pandas_ta/core.py index cad6e43..e30a354 100644 --- a/pandas_ta/core.py +++ b/pandas_ta/core.py @@ -22,7 +22,7 @@ from pandas_ta.volatility import * from pandas_ta.volume import * from pandas_ta.utils import * -version = ".".join(("0", "1", "90b")) +version = ".".join(("0", "1", "91b")) # Dictionary of files for each category, used in df.ta.strategy() Category = {name: category_files(name) for name in categories} @@ -512,10 +512,6 @@ class AnalysisIndicators(BasePandasObject): if timed: ftime = final_time(stime) else: - # Display multiprocessing tip 10% of the time. - if random() < 0.1: - print(f"[i] Set 'df.ta.mp = True' to enable multiprocessing. This computer has {cpus} cores. Default: False") - if timed: stime = perf_counter() if name.lower() in categories or is_all: indicators = [getattr(self, kind) for kind in ta] From 2e898b00d74d1e047c15e46aafe9ef404737b1ce Mon Sep 17 00:00:00 2001 From: Kevin Johnson Date: Fri, 14 Aug 2020 07:15:23 -0700 Subject: [PATCH 4/9] Update issue templates --- .github/ISSUE_TEMPLATE/bug_report.md | 34 +++++++++++++++++++ .github/ISSUE_TEMPLATE/feature_request.md | 4 ++- .../indicator-or-feature-request.md | 2 +- 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..ecbc307 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,34 @@ +--- +name: Bug report +about: Thanks for using Pandas TA!. Create a report to help us improve. +title: '' +labels: '' +assignees: '' + +--- + +**Which version are you running? The lastest version is on Github. Pip is for major releases.** +```python +import pandas_ta as ta +print(ta.version) +``` + +**Upgrade.** +```sh +$ pip install -U git+https://github.com/twopirllc/pandas-ta +``` + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Provide sample code. + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index 7979f3a..d05ca96 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -7,7 +7,7 @@ assignees: '' --- -**Which version are you running? The lastest version is Github. Pip is for major updates.** +**Which version are you running? The lastest version is Github. Pip is for major releases.** ```python import pandas_ta as ta print(ta.version) @@ -29,3 +29,5 @@ A clear and concise description of any alternative solutions or features you've **Additional context** Add any other context or screenshots about the feature request here. + +Thanks for using Pandas TA! diff --git a/.github/ISSUE_TEMPLATE/indicator-or-feature-request.md b/.github/ISSUE_TEMPLATE/indicator-or-feature-request.md index 14b521a..cf0ac44 100644 --- a/.github/ISSUE_TEMPLATE/indicator-or-feature-request.md +++ b/.github/ISSUE_TEMPLATE/indicator-or-feature-request.md @@ -7,7 +7,7 @@ assignees: twopirllc --- -**Which version are you running? The lastest version is Github. Pip is for major updates.** +**Which version are you running? The lastest version is Github. Pip is for major releases.** ```python import pandas_ta as ta print(ta.version) From 2a31019ebf046dd5557f932aa0ff7453982bdc12 Mon Sep 17 00:00:00 2001 From: Kevin Johnson Date: Fri, 14 Aug 2020 07:19:44 -0700 Subject: [PATCH 5/9] Update issue templates --- .github/ISSUE_TEMPLATE/bug_report.md | 8 +++-- .github/ISSUE_TEMPLATE/feature_request.md | 2 +- .github/ISSUE_TEMPLATE/indicator-request.md | 33 +++++++++++++++++++++ 3 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE/indicator-request.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index ecbc307..3d69cb4 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -1,9 +1,9 @@ --- name: Bug report -about: Thanks for using Pandas TA!. Create a report to help us improve. +about: Create a report to help us improve. title: '' -labels: '' -assignees: '' +labels: bug +assignees: twopirllc --- @@ -32,3 +32,5 @@ If applicable, add screenshots to help explain your problem. **Additional context** Add any other context about the problem here. + +Thanks for using Pandas TA! diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index d05ca96..7933e03 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -1,6 +1,6 @@ --- name: Feature request -about: Suggest an idea for this project +about: Suggest an idea for this project. title: '' labels: enhancement assignees: '' diff --git a/.github/ISSUE_TEMPLATE/indicator-request.md b/.github/ISSUE_TEMPLATE/indicator-request.md new file mode 100644 index 0000000..1fcec8e --- /dev/null +++ b/.github/ISSUE_TEMPLATE/indicator-request.md @@ -0,0 +1,33 @@ +--- +name: Indicator Request +about: Be as detailed as possible with links please. +title: '' +labels: enhancement +assignees: twopirllc + +--- + +**Which version are you running? The lastest version is on Github. Pip is for major releases.** +```python +import pandas_ta as ta +print(ta.version) +``` + +**Upgrade.** +```sh +$ pip install -U git+https://github.com/twopirllc/pandas-ta +``` + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context, web links, or screenshots about the feature request here. + +Thanks for using Pandas TA! From 87ef2ee5846fd3f58d3afe624c62790d3d5b0816 Mon Sep 17 00:00:00 2001 From: Kevin Johnson Date: Fri, 14 Aug 2020 07:20:41 -0700 Subject: [PATCH 6/9] Update issue templates --- .../indicator-or-feature-request.md | 31 ------------------- 1 file changed, 31 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE/indicator-or-feature-request.md diff --git a/.github/ISSUE_TEMPLATE/indicator-or-feature-request.md b/.github/ISSUE_TEMPLATE/indicator-or-feature-request.md deleted file mode 100644 index cf0ac44..0000000 --- a/.github/ISSUE_TEMPLATE/indicator-or-feature-request.md +++ /dev/null @@ -1,31 +0,0 @@ ---- -name: Indicator or Feature Request -about: Thanks for using Pandas TA! Please be as detailed as possible with links please. -title: '' -labels: enhancement -assignees: twopirllc - ---- - -**Which version are you running? The lastest version is Github. Pip is for major releases.** -```python -import pandas_ta as ta -print(ta.version) -``` - -**Upgrade.** -```sh -$ pip install -U git+https://github.com/twopirllc/pandas-ta -``` - -**Is your feature request related to a problem? Please describe.** -A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] - -**Describe the solution you'd like** -A clear and concise description of what you want to happen. - -**Describe alternatives you've considered** -A clear and concise description of any alternative solutions or features you've considered. - -**Additional context** -Add any other context, web links, or screenshots about the feature request here. From e83ecbcb83c807071875c0b3bacf001e003b47f3 Mon Sep 17 00:00:00 2001 From: Kevin Johnson Date: Mon, 17 Aug 2020 13:00:26 -0700 Subject: [PATCH 7/9] DOC bullets added --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 10db3b4..acfe455 100644 --- a/README.md +++ b/README.md @@ -55,10 +55,11 @@ and _Weighted Moving Average_. * Removed internal core optimizations when running ```df.ta.strategy('all')``` with multiprocessing. See the ```ta.strategy()``` method for more details. ## __New Indicators__ -_Squeeze_ (**squeeze**). A Momentum indicator. Both John Carter's TTM **and** Lazybear's TradingView versions are implemented. The default is John Carter's, or ```lazybear=False```. Set ```lazybear=True``` to enable Lazybear's. +* _Squeeze_ (**squeeze**). A Momentum indicator. Both John Carter's TTM **and** Lazybear's TradingView versions are implemented. The default is John Carter's, or ```lazybear=False```. Set ```lazybear=True``` to enable Lazybear's. + ## __Updated Indicators__ -_Fisher Transform_ **fisher**: Added Fisher's default **ema** signal line. To change the length of the signal line, use the argument: ```signal=5```. Default: 5 -_Fisher Transform_ **fisher** and _Kaufman's Adaptive Moving Average_ **kama**: Fixed a bug where their columns were not added to final DataFrame when using the _strategy_ method. +* _Fisher Transform_ **fisher**: Added Fisher's default **ema** signal line. To change the length of the signal line, use the argument: ```signal=5```. Default: 5 +* _Fisher Transform_ **fisher** and _Kaufman's Adaptive Moving Average_ **kama**: Fixed a bug where their columns were not added to final DataFrame when using the _strategy_ method. ## What is a Pandas DataFrame Extension? From e2dd45a678e10ba5e9f6998b514e55f47573ab36 Mon Sep 17 00:00:00 2001 From: alexonab Date: Fri, 28 Aug 2020 21:12:15 -0400 Subject: [PATCH 8/9] add-ttm-trend --- pandas_ta/core.py | 11 ++++- pandas_ta/trend/__init__.py | 3 +- pandas_ta/trend/ttm_trend.py | 77 +++++++++++++++++++++++++++++++ tests/test_indicator_trend.py | 7 ++- tests/test_indicator_trend_ext.py | 5 ++ 5 files changed, 100 insertions(+), 3 deletions(-) create mode 100644 pandas_ta/trend/ttm_trend.py diff --git a/pandas_ta/core.py b/pandas_ta/core.py index 712a3e7..98bf01b 100644 --- a/pandas_ta/core.py +++ b/pandas_ta/core.py @@ -838,6 +838,15 @@ class AnalysisIndicators(BasePandasObject): result = stoch(high=high, low=low, close=close, fast_k=fast_k, slow_k=slow_k, slow_d=slow_d, offset=offset, **kwargs) return result + @finalize + def ttm_trend(self, high=None, low=None, close=None, offset=None, length=None, **kwargs): + high = self._get_column(high, "high") + low = self._get_column(low, "low") + close = self._get_column(close, "close") + + result = ttm_trend(high=high, low=low, close=close, length=length, offset=offset, **kwargs) + return result + @finalize def trix(self, close=None, length=None, signal=None, scalar=None, drift=None, offset=None, **kwargs): close = self._get_column(close, "close") @@ -1588,4 +1597,4 @@ class AnalysisIndicators(BasePandasObject): volume = self._get_column(volume, 'volume') result = vp(close=close, volume=volume, width=width, percent=percent, **kwargs) - return result \ No newline at end of file + return result diff --git a/pandas_ta/trend/__init__.py b/pandas_ta/trend/__init__.py index dbdce91..372e815 100644 --- a/pandas_ta/trend/__init__.py +++ b/pandas_ta/trend/__init__.py @@ -12,4 +12,5 @@ from .long_run import long_run from .psar import psar from .qstick import qstick from .short_run import short_run -from .vortex import vortex \ No newline at end of file +from .ttm_trend import ttm_trend +from .vortex import vortex diff --git a/pandas_ta/trend/ttm_trend.py b/pandas_ta/trend/ttm_trend.py new file mode 100644 index 0000000..1d469e4 --- /dev/null +++ b/pandas_ta/trend/ttm_trend.py @@ -0,0 +1,77 @@ +# -*- coding: utf-8 -*- +from pandas import DataFrame +from pandas_ta.utils import get_offset, verify_series + +def ttm_trend(high, low, close, length=None, offset=None, **kwargs): + """Indicator: TTM Trend""" + # Validate arguments + high = verify_series(high) + low = verify_series(low) + close = verify_series(close) + length = int(length) if length and length > 0 else 6 + offset = get_offset(offset) + + # Calculate Result + trend_avg = ((high + low)/2) + for i in range(1, length): + trend_avg = trend_avg + ((high.shift(i) + low.shift(i))/2) + + trend_avg = trend_avg / length + + tm_trend = (close > trend_avg).astype(int) + tm_trend.replace(0, -1, inplace=True) + + # Offset + if offset != 0: + tm_trend = tm_trend.shift(offset) + + # Handle fills + if 'fillna' in kwargs: + tm_trend.fillna(kwargs['fillna'], inplace=True) + if 'fill_method' in kwargs: + tm_trend.fillna(method=kwargs['fill_method'], inplace=True) + + # Name and Categorize it + tm_trend.name = f"TTM_TRND_{length}" + tm_trend.category = "momentum" + + # Prepare DataFrame to return + data = {tm_trend.name: tm_trend} + df = DataFrame(data) + df.name = f"TTMTREND_{length}" + df.category = tm_trend.category + + return df + + + +ttm_trend.__doc__ = \ +"""This indicator is from John Carters book “Mastering the trade” an plots the bars green or red. +It checks if the price is above or under the average price of the previous 5 bars. +The indicator should hep you stay in a trade until the colors chance. +Two bars of the opposite color is the signal to get in or out. +Sources: + https://www.prorealcode.com/prorealtime-indicators/ttm-trend-price/ +Calculation: + Default Inputs: + length=6 + averageprice = (((high[5]+low[5])/2)+((high[4]+low[4])/2)+((high[3]+low[3])/2)+((high[2]+low[2])/2)+((high[1]+low[1])/2)+((high[6]+low[6])/2))/6 + if close > averageprice then + drawcandle(open,high,low,close) coloured(0,255,0) + endif + + if close < averageprice then + drawcandle(open,high,low,close) coloured(255,0,0) + endif +Args: + high (pd.Series): Series of 'high's + low (pd.Series): Series of 'low's + close (pd.Series): Series of 'close's + length (int): It's period. Default: 6 + offset (int): How many periods to offset the result. Default: 0 +Kwargs: + fillna (value, optional): pd.DataFrame.fillna(value) + fill_method (value, optional): Type of fill method +Returns: + pd.DataFrame: ttm_trend. +""" diff --git a/tests/test_indicator_trend.py b/tests/test_indicator_trend.py index f6a7152..954756a 100644 --- a/tests/test_indicator_trend.py +++ b/tests/test_indicator_trend.py @@ -154,7 +154,12 @@ class TestTrend(TestCase): self.assertIsInstance(result, Series) self.assertEqual(result.name, "SR_2") + def test_ttm_trend(self): + result = pandas_ta.ttm_trend(self.high, self.low, self.close) + self.assertIsInstance(result, DataFrame) + self.assertEqual(result.name, "TTMTREND_6") + def test_vortex(self): result = pandas_ta.vortex(self.high, self.low, self.close) self.assertIsInstance(result, DataFrame) - self.assertEqual(result.name, "VTX_14") \ No newline at end of file + self.assertEqual(result.name, "VTX_14") diff --git a/tests/test_indicator_trend_ext.py b/tests/test_indicator_trend_ext.py index a3df15f..cce0a25 100644 --- a/tests/test_indicator_trend_ext.py +++ b/tests/test_indicator_trend_ext.py @@ -98,6 +98,11 @@ class TestTrendExtension(TestCase): self.assertIsInstance(self.data, DataFrame) self.assertEqual(self.data.columns[-1], "SR_2") + def test_ttm_trend_ext(self): + self.data.ta.ttm_trend(append=True) + self.assertIsInstance(self.data, DataFrame) + self.assertEqual(list(self.data.columns[-1:]), ["TTM_TRND_6"]) + def test_vortext_ext(self): self.data.ta.vortex(append=True) self.assertIsInstance(self.data, DataFrame) From cb57bd5e2aa76793a9d85d033cfa499277849563 Mon Sep 17 00:00:00 2001 From: alexonab Date: Fri, 28 Aug 2020 23:33:02 -0400 Subject: [PATCH 9/9] add-ttm-trend --- pandas_ta/core.py | 2 +- tests/test_indicator_trend.py | 2 +- tests/test_indicator_trend_ext.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas_ta/core.py b/pandas_ta/core.py index 98bf01b..962a10a 100644 --- a/pandas_ta/core.py +++ b/pandas_ta/core.py @@ -838,7 +838,7 @@ class AnalysisIndicators(BasePandasObject): result = stoch(high=high, low=low, close=close, fast_k=fast_k, slow_k=slow_k, slow_d=slow_d, offset=offset, **kwargs) return result - @finalize + @finalize def ttm_trend(self, high=None, low=None, close=None, offset=None, length=None, **kwargs): high = self._get_column(high, "high") low = self._get_column(low, "low") diff --git a/tests/test_indicator_trend.py b/tests/test_indicator_trend.py index 954756a..47537bd 100644 --- a/tests/test_indicator_trend.py +++ b/tests/test_indicator_trend.py @@ -154,7 +154,7 @@ class TestTrend(TestCase): self.assertIsInstance(result, Series) self.assertEqual(result.name, "SR_2") - def test_ttm_trend(self): + def test_ttm_trend(self): result = pandas_ta.ttm_trend(self.high, self.low, self.close) self.assertIsInstance(result, DataFrame) self.assertEqual(result.name, "TTMTREND_6") diff --git a/tests/test_indicator_trend_ext.py b/tests/test_indicator_trend_ext.py index cce0a25..83ddcb0 100644 --- a/tests/test_indicator_trend_ext.py +++ b/tests/test_indicator_trend_ext.py @@ -98,7 +98,7 @@ class TestTrendExtension(TestCase): self.assertIsInstance(self.data, DataFrame) self.assertEqual(self.data.columns[-1], "SR_2") - def test_ttm_trend_ext(self): + def test_ttm_trend_ext(self): self.data.ta.ttm_trend(append=True) self.assertIsInstance(self.data, DataFrame) self.assertEqual(list(self.data.columns[-1:]), ["TTM_TRND_6"])