fix: Update Bollinger Bands calculation with correct pandas-ta column names
This commit is contained in:
parent
4feaf51b4c
commit
efe820317c
@ -56,12 +56,23 @@ class DynamicStrategy(Strategy):
|
||||
std = float(ind_config['params']['std'])
|
||||
|
||||
def bb_calc(x):
|
||||
result = ta.bbands(x, length=length, std=std)
|
||||
# Use pandas-ta bbands with explicit column names
|
||||
result = pd.DataFrame(ta.bbands(x, length=length, std=std))
|
||||
if result is None or result.empty:
|
||||
return np.zeros(len(x)), np.zeros(len(x)), np.zeros(len(x))
|
||||
return (result.iloc[:,0].fillna(method='ffill').fillna(0).values,
|
||||
result.iloc[:,1].fillna(method='ffill').fillna(0).values,
|
||||
result.iloc[:,2].fillna(method='ffill').fillna(0).values)
|
||||
|
||||
# Debug print
|
||||
print(f"BB calculation result columns: {result.columns}")
|
||||
print(f"First few rows of BB calculation:\n{result.head()}")
|
||||
|
||||
# Get the correct column names from pandas-ta output
|
||||
upper_col = f'BBU_{length}_{std}.0'
|
||||
middle_col = f'BBM_{length}_{std}.0'
|
||||
lower_col = f'BBL_{length}_{std}.0'
|
||||
|
||||
return (result[upper_col].fillna(method='ffill').fillna(0).values,
|
||||
result[middle_col].fillna(method='ffill').fillna(0).values,
|
||||
result[lower_col].fillna(method='ffill').fillna(0).values)
|
||||
|
||||
bb_vals = self.I(bb_calc, self.data.Close)
|
||||
self.indicators[f"{ind_name}_upper"] = bb_vals[0]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user