TA-Lib / ta-lib-python

Python wrapper for TA-Lib (http://ta-lib.org/).
http://ta-lib.github.io/ta-lib-python
Other
9.63k stars 1.76k forks source link

Bollinger band result issue #679

Open infographie35 opened 2 hours ago

infographie35 commented 2 hours ago

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

# 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'])
mrjbq7 commented 2 hours ago

It is documented as returning

upper, middle, lower

https://github.com/TA-Lib/ta-lib-python/blob/287eb535aba4a95828a382d6ffd418f96b7a0712/talib/_func.pxi#L596

Are you seeing something else?

infographie35 commented 2 hours ago

Thank you for the link I now fully understand MY mistake

All solve