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

chandelier_exit #559

Open
bibinvargheset opened this issue Jul 2, 2022 · 5 comments
Open

chandelier_exit #559

bibinvargheset opened this issue Jul 2, 2022 · 5 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@bibinvargheset
Copy link

bibinvargheset commented Jul 2, 2022

Here is a code that i have written for chandelier_exit, if possible add to repo

 def chandelier_exit(df1, atr_length=14, roll_length=22, mult=2, use_close=False):
        df = df1.copy()
        df.columns = df.columns.str.lower()
        my_atr = ta.Strategy(
            name="atr",
            ta=[{"kind": "atr", "length": atr_length, "col_names": ("ATR",)}]
        )
        # Run it
        df.ta.strategy(my_atr, append=True)

        if use_close:
            df['chandelier_long'] = df.rolling(roll_length)["close"].max() + df.iloc[-1]["ATR"] * mult
            df['chandelier_short'] = df.rolling(roll_length)["close"].min() - df.iloc[-1]["ATR"] * mult
        else:
            df['chandelier_long'] = df.rolling(roll_length)["high"].max() - df.iloc[-1]["ATR"] * mult
            df['chandelier_short'] = df.rolling(roll_length)["low"].min() + df.iloc[-1]["ATR"] * mult
        df.loc[df['close'] > df['chandelier_long'].shift(1), 'chd_dir'] = 1
        df.loc[df['close'] < df['chandelier_short'].shift(1), 'chd_dir'] = -1
        # chd = df[['chandelier_long', 'chandelier_short', 'chd_dir']]
        return df
@bibinvargheset bibinvargheset added the enhancement New feature or request label Jul 2, 2022
@twopirllc twopirllc removed their assignment Jul 2, 2022
@twopirllc twopirllc added help wanted Extra attention is needed good first issue Good for newcomers labels Jul 2, 2022
@twopirllc
Copy link
Owner

Hi @bibinvargheset,

Sure. It can be added. Hopefully someone can convert it to proper method and make a PR so it can be included. 😎

Kind Regards,
KJ

@glunkad
Copy link

glunkad commented Jul 3, 2022

Hey @twopirllc @bibinvargheset , I'm interested in contributing to this issue, so before I start working on it, would you mind sparing your time explaining what the issue is about and pointing me to some resources to get started

@bibinvargheset
Copy link
Author

@9gl the code i shared is working, but needs structural changes to be, check psar.py or similar indicator and update to have similar structure and functionality

@glunkad
Copy link

glunkad commented Jul 3, 2022

@bibinvargheset Sure will do. Could you point me to the file which requires changes

@twopirllc
Copy link
Owner

Hi @9gl,

Thanks for your interest in taking this on. 😎

First, make sure you are using the development branch. README

$ pip install -U git+https://github.com/twopirllc/pandas-ta.git@development

Second, follow Creating a Custom Indicator: The Big 4 to add an indicator and hook it up to the DataFrame Extension.

Notes:

  • chandelier_exit.py should not accept a DataFrame as arguments but rather high, low, and close instead. By default, it should use the high & low Series.
    • For an example of how to construct conditional close case, check out ad.py. (Simply replace open_ with close.)
  • It must not call df.ta.strategy() internally.
  • Since it is returning three columns 'chandelier_long', 'chandelier_short' and 'chandelier_dir', reference macd.py's Name and Category Section for an example of preparing the returning DataFrame.

That should cover the majority. The indicator itself is not difficult. I can add tests after the PR, so don't worry about those unless you want to try.

Hope this helps! Let me know otherwise.

Kind Regards,
KJ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants