fix: Improve ADX indicator calculation with proper Series conversion and parameter handling

This commit is contained in:
Bobby (aider) 2025-02-14 00:37:18 -08:00
parent 071559a8e1
commit 8b9ef53794

View File

@ -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':