From c3ae5c6c2a937b2ceee0131e7aebae1b34f40e4f Mon Sep 17 00:00:00 2001 From: egrafeuille Date: Thu, 9 Feb 2023 15:56:05 -0300 Subject: [PATCH] Update supertrend to match Tradinview indicator Hi, lowerband (lb) and upperband (ub) should be updated with previous value (if condition is met) despite change direction (dir_) occurs or not. This change match with supertrend TradingView indicator. --- pandas_ta/overlap/supertrend.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pandas_ta/overlap/supertrend.py b/pandas_ta/overlap/supertrend.py index 28e3f889..6cb3e6a5 100644 --- a/pandas_ta/overlap/supertrend.py +++ b/pandas_ta/overlap/supertrend.py @@ -70,10 +70,11 @@ def supertrend( dir_[i] = -1 else: dir_[i] = dir_[i - 1] - if dir_[i] > 0 and lb.iloc[i] < lb.iloc[i - 1]: - lb.iloc[i] = lb.iloc[i - 1] - if dir_[i] < 0 and ub.iloc[i] > ub.iloc[i - 1]: - ub.iloc[i] = ub.iloc[i - 1] + + if dir_[i] > 0 and lb.iloc[i] < lb.iloc[i - 1]: + lb.iloc[i] = lb.iloc[i - 1] + if dir_[i] < 0 and ub.iloc[i] > ub.iloc[i - 1]: + ub.iloc[i] = ub.iloc[i - 1] if dir_[i] > 0: trend[i] = long[i] = lb.iloc[i]