Hello everyone, I've encountered dangerous behavior of library while calculating MACD with signalperiod = 1:
How to reproduce:
np.random.seed(42)
test_data=np.random.randn(2000) *100+1000fastperiod=2slowperiod=32signalperiod=1macd_1, macdsignal_1, macdhist_1=ta.MACD(
real=np.append(test_data[:1500],-999999999), fastperiod=fastperiod, slowperiod=slowperiod, signalperiod=signalperiod
)
macd_2, macdsignal_2, macdhist_2=ta.MACD(
real=test_data[:1501], fastperiod=fastperiod, slowperiod=slowperiod, signalperiod=signalperiod
)
print(macdsignal_2[-3] -macdsignal_1[-3]) # Equals 606061258.6885501
As I am checking [-3] index in the array - it shouldn't know about the upcoming value in the end, but the calculated delta shows that TA-Lib takes this value into account.
Also I checked the correct parameters:
np.random.seed(42)
test_data=np.random.randn(2000) *100+1000fastperiod=2slowperiod=32signalperiod=2macd_1, macdsignal_1, macdhist_1=ta.MACD(
real=np.append(test_data[:1500],-999999999), fastperiod=fastperiod, slowperiod=slowperiod, signalperiod=signalperiod
)
macd_2, macdsignal_2, macdhist_2=ta.MACD(
real=test_data[:1501], fastperiod=fastperiod, slowperiod=slowperiod, signalperiod=signalperiod
)
print(macdsignal_2[-3] -macdsignal_1[-3]) # Equals 0.0
I think it is needed either to forbid signalperiod = 1 or to manually fill the macdhist array with zeros in this edge case.
Hello everyone, I've encountered dangerous behavior of library while calculating MACD with signalperiod = 1:
How to reproduce:
As I am checking [-3] index in the array - it shouldn't know about the upcoming value in the end, but the calculated delta shows that TA-Lib takes this value into account.
Also I checked the correct parameters:
I think it is needed either to forbid signalperiod = 1 or to manually fill the macdhist array with zeros in this edge case.