diff --git a/src/pages/backtesting/backtesting_page.py b/src/pages/backtesting/backtesting_page.py index b7523de..d75392d 100644 --- a/src/pages/backtesting/backtesting_page.py +++ b/src/pages/backtesting/backtesting_page.py @@ -56,16 +56,19 @@ class DynamicStrategy(Strategy): std = float(ind_config['params']['std']) def bb_calc(x): + # Ensure input is a pandas Series with proper index + series = pd.Series(x) + # Calculate BB using pandas-ta - bb_result = ta.bbands(close=pd.Series(x), length=length, std=std) + bb_result = ta.bbands(series, length=length, std=std) if bb_result is None or bb_result.empty: return np.zeros(len(x)), np.zeros(len(x)), np.zeros(len(x)) - # Get the column names (they should be BBL, BBM, BBU) - upper_col = f'BBU_{length}_{std}.0' - middle_col = f'BBM_{length}_{std}.0' - lower_col = f'BBL_{length}_{std}.0' + # Get the column names from bb_result + upper_col = bb_result.columns[2] # BBU + middle_col = bb_result.columns[1] # BBM + lower_col = bb_result.columns[0] # BBL # Extract and process the values upper = bb_result[upper_col].fillna(method='ffill').fillna(0).values