Open coinrazzi opened 3 years ago
Hello @coinrazzi,
Seems interesting. Can you provide the Author or link to the indicator so that I can find it via TradingView? I would like to add Pivots to Pandas TA and hopefully someone has knowledge or experience to get this or other basic Pivot systems implemented. There are some complexities involved to get these to work.
Unfortunately, I do not have a time frame for this addition as the library is currently overwhelmed with Issues and current enhancements. If you want to make some head way, please fork, add the indicator with a new directory called pivots and submit a PR. I can take it from there.
Kind Regards, KJ
This is script and profile link. https://www.tradingview.com/script/JAW0oW7R-Support-Resistance-V2-Indicator/
Ok. I will try to python code this script.
@coinrazzi,
Awesome! Let me know if you need help getting started. I would look at some other PRs on which files need editing to integrate it into Pandas TA.
Thanks, KJ
I fund another python script about support resistance on github. I am using in my project now. it's well too. Maybe you want to check. This is Class Code (using numpy)
import numpy as np
class Sup_Res_Finder():
def isSupport(self, df,i):
support = df['Low'][i] < df['Low'][i-1] and df['Low'][i] < df['Low'][i+1] \
and df['Low'][i+1] < df['Low'][i+2] and df['Low'][i-1] < df['Low'][i-2]
return support
def isResistance(self, df,i):
resistance = df['High'][i] > df['High'][i-1] and df['High'][i] > df['High'][i+1] \
and df['High'][i+1] > df['High'][i+2] and df['High'][i-1] > df['High'][i-2]
return resistance
def find_levels(self, df):
levels = []
s = np.mean(df['High'] - df['Low'])
for i in range(2, df.shape[0]-2):
if self.isSupport(df,i):
l = df['Low'][i]
if np.sum([abs(l-x) < s for x in levels]) == 0:
levels.append((i,l))
elif self.isResistance(df,i):
l = df['High'][i]
if np.sum([abs(l-x) < s for x in levels]) == 0:
levels.append((i,l))
return levels
Hello @coinrazzi,
Thanks but there is no link 😬 .
KJ
Sorry this is link. https://github.com/Reed-Schimmel/support_resistance_finder
Kubilay
Seems very interesting, what can be the equivilent of fixnan() from pine?
pine has brought a lot of positive processing to dataframes and indicators world, contributing to pandas-ta will provide great benefits to the community using it.
@twopirllc Kevin, I have some indicators to contribute but I might need some guidance to have the code written in the pandas-ta fashion and merge it properly.
Would you consider a benchmark of pandas-ta TA's vs TVs TA's ?
Hello @talhazan,
Seems very interesting, what can be the equivilent of fixnan() from pine?
Pinescript fixnan sounds like a Pandas Forward Fill: df.fillna("ffill", inplace=True)
.
pine has brought a lot of positive processing to dataframes and indicators world, contributing to pandas-ta will provide great benefits to the community using it.
Yeah TradingView has. Good for prototyping indicators before porting them to other languages. Plan to implement more when possible.
Kevin, I have some indicators to contribute but I might need some guidance to have the code written in the pandas-ta fashion and merge it properly.
Great! I've ported some of mine here as well. To add indicators or utility methods, please follow Issue #264 Is there a proper way to extend pandas-ta with Custom Indicator?.
Make PRs when your ready. One indicator per PR. 😎
Would you consider a benchmark of pandas-ta TA's vs TVs TA's ?
Sure if you know an automatic way to do it without having to build a a New Chart Layout with said indicator(s), manually downloading their data with processed indicators.
At a minimum, if there are common indicators between TA Lib and Pandas TA, I correlation test those. I have to do the manual process above to run correlation tests with TradingView indicators.
Kind Regards, KJ
A second iteration on the version shared by the author of #551, thanks for the code!
The version below is ~10x times faster on my machine.
def supres2(open, high, low, close, offset=None, suffix=None, **kwargs):
# Validate and prepare data
length = len(close)
open, high, low, close = map(lambda s: v_series(s, length), [open, high, low, close])
offset = v_offset(offset)
# Compute basic indicators
src1 = ta.hma(open, length=5, offset=1)
src2 = ta.hma(close, length=12)
momm1, momm2 = src1.diff(), src2.diff()
rsi_new = ta.rsi(close, length=9)
sh, sl = high.rolling(2).max().rolling(2).mean(), low.rolling(2).min().rolling(2).mean()
# Calculate momentum and CMO
m1 = momm1 >= momm2
m2 = -1 * momm1.where(momm1 < momm2, 0)
sm1, sm2 = m1.rolling(1).sum(), m2.rolling(1).sum()
CMO = 100 * (sm1 - sm2) / (sm1 + sm2).replace(0, float('nan'))
# Calculate support and resistance
h1, l1 = (high - sh).abs().expanding().mean(), (low - sl).abs().expanding().mean()
hpivot, lpivot = h1 != 0, l1 != 0
hpivot_new, lpivot_new = high.where(hpivot), low.where(lpivot)
RESISTANCE = hpivot_new.where((rsi_new > 75) & (CMO < -50))
SUPPORT = lpivot_new.where((rsi_new < 25) & (CMO > 50))
# Prepare DataFrame to return
props = f"_{length}" if suffix == "length" else ""
df = pd.DataFrame({f"SUPPORT{props}": SUPPORT, f"RESISTANCE{props}": RESISTANCE}, index=close.index)
df.name = f"SUPPORT{props}"
df.category = "overlap"
df.ffill(inplace=True)
# Apply offset if needed
return df.shift(offset)
Hey @twopirllc,
Was this somehow merged and released? The related PR is noted as merged, but this issue is kept open.
Also, I can't find any reference to supres
in the docs or in pandas_ta
, using 0.3.14b
.
Many thanks.
Hello @vpmartin,
This issue is still open because it has not been completed, see my latest comment in #551.
Kind Regards, KJ
Which version are you running? The lastest version is on Github. Pip is for major releases. Pandas Ta version : 0.2.42b0
I am using an indicator for automatic drawing support and resistance levels. It's working well. Can you add to pandas ta? I am pasting pine script code.