-
Notifications
You must be signed in to change notification settings - Fork 299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Supertrend indicator seems to incorrectly change orientation #125
Comments
I think, I was able to find a solution. I have adjusted the trend switching logic to watch candle close and last supetrend (lower/upper) value, instead of current. See lines It's the same logic used in pandas-ta, lines Original code if last_st == last_ub:
if curr_close <= ub[i]:
st[i] = ub[i]
else:
st[i] = lb[i]
elif last_st == last_lb:
if curr_close > lb[i]:
st[i] = lb[i]
else:
st[i] = ub[i] After my adjustment if last_st == last_ub:
if curr_close <= last_ub:
st[i] = ub[i]
else:
st[i] = lb[i]
elif last_st == last_lb:
if curr_close > last_lb:
st[i] = lb[i]
else:
st[i] = ub[i] |
Okay, I have opened a PR 126 which is implementing the suggested fix. |
On the other hand, I am still unsure about this. The algorithm mentioned in comment inside the current codebase refers to current candle close, not previous. # IF PREV.ST > PREV.CLOSE AND CUR.ST < CUR.CLOSE ==> BUY SIGNAL
# IF PREV.ST < PREV.CLOSE AND CUR.ST > CUR.CLOSE ==> SELL SIGNAL
for i in range(len(supertrend)):
if close[i] > supertrend.iloc[i, 0]:
upt.append(supertrend.iloc[i, 0])
dt.append(np.nan)
elif close[i] < supertrend.iloc[i, 0]:
upt.append(np.nan)
dt.append(supertrend.iloc[i, 0])
else:
upt.append(np.nan)
dt.append(np.nan) Also this code computes is in the similar way. #SUPERTREND = IF((Previous SUPERTREND = Previous FINAL UPPERBAND) and (Current Close <= Current FINAL UPPERBAND)) THEN...
# Line 175 -> df[ohlc[3]]
df[st].iat[i] = df['final_ub'].iat[i] if df[st].iat[i - 1] == df['final_ub'].iat[i - 1] and df[ohlc[3]].iat[ Also this strategy on Tradingview uses current price...
I think, I am missing something.... |
Thanks for opening this issue. |
Hello,
I have switched my supertrend calculations from
pandas_ta
and I observe a inconsistency in supertrend values. The issue is (probably) caused by specific candle wicks.I will continously work the description of this issue, since it's a bit difficult to be to debug or even describe.
Current behaviour
The issue occurs at
08:45
or08:46
. The extreme weird looking candles happens and the supertrend flips for a period of one candle.3.10
0.4.1
Note: I am using an web UI which is displaying only "active" supertrend. This is why is the other line missing from the chart. However I am going to provide charts with both lines, but it's a bit confusing a bit since it's not clear which one is "active".
Code snippet
Supertrend values (raw)
OHCL with supertrend (
stockstats
)OHCL with supertrend (
pandas_ta
)OHCL with supertrend and both [upper and lowes] values displayed (
stockstats
)Used data source -
binance_btcusdt_ohcl_1m.parquet
I am using Pandas to work with data, loading parquet is very easy - guide - however in case of any issues, I can export data in different format (JSON etc.)
binance_btcusdt_ohcl_1m.parquet.zip
Expected behaviour
I do not think that the supertrend - trend should end (change). I think it should continue since the bull (positive/long) candle did not broke it.
The text was updated successfully, but these errors were encountered: