Skip to content
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

Issue #781 #797

Merged
merged 2 commits into from
Jul 2, 2024
Merged

Issue #781 #797

merged 2 commits into from
Jul 2, 2024

Conversation

Adewale-1
Copy link

Added

  • Added a new file smc.py in the pandas_ta/momentum folder for the Smart Money Indicator (SMI).
  • Included smc in the pandas_ta/__init__.py for module-level access.
  • Added def smc(self, fast=None, slow=None, signal=None, scalar=None, offset=None, **kwargs): to pandas_ta/core.py for core functionality of the SMI/ SMC
Screenshot 2024-05-25 at 12 38 20 AM indicator. - Created tests for the SMI indicator in `tests/test_ext_indicator_momentum.py`. - Created tests for the SMI indicator in `tests/test_indicator_momentum.py`.

Fixed

  • Ensured all tests pass after adding the new indicator and its corresponding tests.

@twopirllc
Copy link
Owner

Hi @Adewale-1,

Out of curiosity, are you using an (auto) linter? A bunch of additional whitespace and newlines have been added.

Anyhow, I plan to merge it into developement hopefully no later than the end of the coming week.

Kind Regards
KJ

@twopirllc
Copy link
Owner

Upon further review, this will take longer.

@Adewale-1
Copy link
Author

Yes I used Autolinter

@twopirllc
Copy link
Owner

Also @Adewale-1,

What are the required columns to return? Which columns are optional?

Thanks ✅

@Adewale-1
Copy link
Author

The required columns are time, High, Low,
Open, high_volatility, top_imbalance_size,
top_imbalance_percentage, bottom_imbalance_size,
bottom_imbalance_percentage.

The optional columns are up, down,
doji, body_hi, body_lo, body, body_avg, small_body, long_body,
white_body, black_body, up_shadow, dn_shadow, has_up_shadow,
has_dn_shadow, down_trend, volatility, vol_avg,
top_imbalance_flag, bottom_imbalance_flag.

@twopirllc
Copy link
Owner

@Adewale-1

Awesome! Next, of those... what are required to return/append to the DataFrame and which can be excluded?

@Adewale-1
Copy link
Author

Adewale-1 commented Jun 23, 2024

The returned Dataframe contains the required columns, and also the optional columns that could be excluded are the up, down,doji, body_hi, body_lo, body, body_avg, small_body, long_body,white_body, black_body, up_shadow, dn_shadow, has_up_shadow,has_dn_shadow, down_trend, volatility, vol_avg,top_imbalance_flag, bottom_imbalance_flag.

For the image, I used plotly, and the method shows the imbalance by using the required columns returned from the modified Dataframe :

def indicator(df, fig):
    df = smc(df)
    print(df.head())
    for index, row in df.iterrows():
        if (
            index > 1 and row["high_volatility"]
        ):  # Only consider high volatility situations
            if row["top_imbalance_size"] > 0 and row["top_imbalance_percentage"] > 1:
                fig.add_shape(
                    type="rect",
                    x0=df.loc[index - 1, "time"],
                    x1=row["time"],
                    y0=df.loc[index - 2, "Open"],
                    y1=row["High"],
                    xref="x",
                    yref="y",
                    fillcolor="rgba(255, 0, 0, 0.5)",
                    opacity=0.5,
                    line=dict(color="rgba(255, 0, 0, 0.5)", width=7),
                )
            if (
                row["bottom_imbalance_size"] > 0
                and row["bottom_imbalance_percentage"] > 1
            ):
                fig.add_shape(
                    type="rect",
                    x0=df.loc[index - 1, "time"],
                    x1=row["time"],
                    y0=row["Low"],
                    y1=df.loc[index - 2, "High"],
                    xref="x",
                    yref="y",
                    fillcolor="rgba(0, 255, 0, 0.5)",
                    opacity=0.5,
                    line=dict(color="rgba(0, 255, 0, 0.5)", width=7),
                )



indicator(dataFrame, figure)

# Update the layout of the chart
figure.update_layout(
    title="BTC-USD Candlestick Chart with Moving Averages and Imbalances",
    xaxis_title="Time",
    yaxis_title="Price",
    xaxis_rangeslider_visible=False,
)
# Show the plot
figure.show()

@twopirllc twopirllc merged commit 56761f2 into twopirllc:development Jul 2, 2024
@Adewale-1
Copy link
Author

Thank you, I noticed I forgot to cite my name in the source section of the method, do I need to fork the repo again?

@twopirllc
Copy link
Owner

@Adewale-1

You have already forked it. However, you can make another PR from the current development branch and add your name to the indicator docstring. That would be the easiest to do on your end. 😎

Also if you submit another indicator, please follow the indicator programming convention on the development branch. For instance, none of the indicators take a DataFrame as indicator input. This library follows the classical style of TA Lib; see ADX for example. Note it is not a hard rule, but it does reduce the turn around time for inclusion.

Thanks
KJ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants