pandas-ta
pandas-ta copied to clipboard
chandelier_exit
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
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
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
@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
@bibinvargheset Sure will do. Could you point me to the file which requires changes
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