Back to Community
Error computing super trend indicator

Hello All,

I'm trying to compute a supertrend indicator, but I cannot manage to compute correctly the final lower and upper bands. I dont understand why the np.where formula do not give the desired output, i.e.:

IF basic_upper_band(n) < final upper band(n-1) OR close price(n-1) > final_upper_band(n-1):
final_upper_band(n) = basic_upper_band(n)
final_upper_band(n) = basic_upper_band(n-1)

I systematically get final_upper_band(n) = basic_upper_band(n), like if the first condition was always true, while it's not...

Thanks in advance for your help

Loading notebook preview...
1 response

For anyone interested, the method above does not work because final bands are computed with previous occurrences of the same dataframe column, which is not allow with panda.
The only solution I found is to loop over the rows. If someone has a faster way to compute this indicator, please let me know

Loading notebook preview...