From 8b9ef53794591d7f4c9a1d04690ee5e763fed8de Mon Sep 17 00:00:00 2001 From: "Bobby (aider)" Date: Fri, 14 Feb 2025 00:37:18 -0800 Subject: [PATCH] fix: Improve ADX indicator calculation with proper Series conversion and parameter handling --- src/pages/backtesting/backtesting_page.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/pages/backtesting/backtesting_page.py b/src/pages/backtesting/backtesting_page.py index f29f2bd..65d31e7 100644 --- a/src/pages/backtesting/backtesting_page.py +++ b/src/pages/backtesting/backtesting_page.py @@ -145,8 +145,17 @@ class DynamicStrategy(Strategy): elif ind_config['type'] == 'ADX': def adx_calc(high, low, close): - result = ta.adx(high, low, close, length=int(ind_config['params']['length'])) - return result.fillna(method='ffill').fillna(0).values + result = ta.adx(high=pd.Series(high), + low=pd.Series(low), + close=pd.Series(close), + length=int(ind_config['params']['length']), + lensig=14) # Adding lensig parameter + if isinstance(result, pd.DataFrame): + # ADX is typically the third column in the result + return result.iloc[:, 2].fillna(method='ffill').fillna(0).values + else: + # If result is a Series, return it directly + return result.fillna(method='ffill').fillna(0).values self.indicators[ind_name] = self.I(adx_calc, self.data.High, self.data.Low, self.data.Close) elif ind_config['type'] == 'CCI':