fix: Improve Bollinger Bands calculation with dynamic column handling
This commit is contained in:
parent
6e965a2924
commit
aa5952e00b
@ -56,16 +56,19 @@ class DynamicStrategy(Strategy):
|
|||||||
std = float(ind_config['params']['std'])
|
std = float(ind_config['params']['std'])
|
||||||
|
|
||||||
def bb_calc(x):
|
def bb_calc(x):
|
||||||
|
# Ensure input is a pandas Series with proper index
|
||||||
|
series = pd.Series(x)
|
||||||
|
|
||||||
# Calculate BB using pandas-ta
|
# 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:
|
if bb_result is None or bb_result.empty:
|
||||||
return np.zeros(len(x)), np.zeros(len(x)), np.zeros(len(x))
|
return np.zeros(len(x)), np.zeros(len(x)), np.zeros(len(x))
|
||||||
|
|
||||||
# Get the column names (they should be BBL, BBM, BBU)
|
# Get the column names from bb_result
|
||||||
upper_col = f'BBU_{length}_{std}.0'
|
upper_col = bb_result.columns[2] # BBU
|
||||||
middle_col = f'BBM_{length}_{std}.0'
|
middle_col = bb_result.columns[1] # BBM
|
||||||
lower_col = f'BBL_{length}_{std}.0'
|
lower_col = bb_result.columns[0] # BBL
|
||||||
|
|
||||||
# Extract and process the values
|
# Extract and process the values
|
||||||
upper = bb_result[upper_col].fillna(method='ffill').fillna(0).values
|
upper = bb_result[upper_col].fillna(method='ffill').fillna(0).values
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user