Output result shows BB_Middle > BB_Upper
BB_Middle results are really BB_Upper
BB_Upper results are really BB_Middle
I switch formula and got no problem now I have logic result BB_Middle < BB_Upper
# Bollinger Bands
# Set the period for Bollinger Bands (20 is a common choice)
period = 20
std_dev = 2
# Calculate the Middle Band (SMA)
df['BB_Middle'] = df['close'].rolling(window=period).mean()
# Calculate the Standard Deviation
df['BB_Std_Dev'] = df['close'].rolling(window=period).std()
# Calculate the Upper Band
df['BB_Upper'] = df['BB_Middle'] + (std_dev * df['BB_Std_Dev'])
# Calculate the Lower Band
df['BB_Lower'] = df['BB_Middle'] - (std_dev * df['BB_Std_Dev'])
I hope it is not on my side, but I scratch my hair
Python 3.13 df['BB_Middle'], df['BB_Upper'], df['BB_Lower'] = talib.BBANDS
Output result shows BB_Middle > BB_Upper BB_Middle results are really BB_Upper BB_Upper results are really BB_Middle
I switch formula and got no problem now I have logic result BB_Middle < BB_Upper