-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
feature/heikin-ashi-candles: Adds a flag for Heikin Ashi Candles on stocks/candle #4979
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jmaslek
reviewed
May 5, 2023
jmaslek
reviewed
May 5, 2023
if you want to use the code from bot you can do this def heikin_ashi(df_data: pd.DataFrame) -> pd.DataFrame:
"""Attempts to calaculate heikin ashi based on given stock ticker data frame."""
HA_df = df_data.copy()
# Close column
HA_df["Close"] = round(
((df_data["Open"] + df_data["High"] + df_data["Low"] + df_data["Close"]) / 4), 2
)
HA_df.iat[0, 0] = round(
((df_data["Open"].iloc[0] + df_data["Close"].iloc[0]) / 2), 2
)
# Open column
for i in range(1, len(df_data)):
HA_df.iat[i, 0] = round(((HA_df.iat[i - 1, 0] + HA_df.iat[i - 1, 3]) / 2), 2)
# High and Low column
HA_df["High"] = HA_df.loc[:, ["Open", "Close"]].join(df_data["High"]).max(axis=1)
HA_df["Low"] = HA_df.loc[:, ["Open", "Close"]].join(df_data["Low"]).min(axis=1)
return HA_df has easy return data = heikin_ashi(data) |
Pretty much the same thing as what def ha(open_, high, low, close, offset=None, **kwargs):
"""Candle Type: Heikin Ashi"""
# Validate Arguments
open_ = verify_series(open_)
high = verify_series(high)
low = verify_series(low)
close = verify_series(close)
offset = get_offset(offset)
# Calculate Result
m = close.size
df = DataFrame({
"HA_open": 0.5 * (open_.iloc[0] + close.iloc[0]),
"HA_high": high,
"HA_low": low,
"HA_close": 0.25 * (open_ + high + low + close),
})
for i in range(1, m):
df["HA_open"][i] = 0.5 * (df["HA_open"][i - 1] + df["HA_close"][i - 1])
df["HA_high"] = df[["HA_open", "HA_high", "HA_close"]].max(axis=1)
df["HA_low"] = df[["HA_open", "HA_low", "HA_close"]].min(axis=1)
# Offset
if offset != 0:
df = df.shift(offset)
# Handle fills
if "fillna" in kwargs:
df.fillna(kwargs["fillna"], inplace=True)
if "fill_method" in kwargs:
df.fillna(method=kwargs["fill_method"], inplace=True)
# Name and Categorize it
df.name = "Heikin-Ashi"
df.category = "candles"
return df |
jmaslek
reviewed
May 9, 2023
jmaslek
approved these changes
May 11, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR adds a flag for showing Heikin Ashi candles from the
/stocks/candle
command.Updates files:
Minor details are updated, such as this description.
Also touched is the default title, removing the arbitrary default label, "Stock".
Regular:
Heikin Ashi:
Relevant motivation and context.
An option to smooth noise in a candle chart.
This could become a synced preference in Hub that aligns with the Bot.
How has this been tested?
Checklist:
feature/feature-name
orhotfix/hotfix-name
.Others