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

EBSW indicator #350

Closed
Squigglez2 opened this issue Jul 23, 2021 · 7 comments
Closed

EBSW indicator #350

Squigglez2 opened this issue Jul 23, 2021 · 7 comments
Labels
enhancement New feature or request

Comments

@Squigglez2
Copy link

Squigglez2 commented Jul 23, 2021

I don't know if this goes anywhere really, I tried using the Even Better Sine Wave indicator and noticed the note in the docs about the logic. So I made the function below based off the code in the two links:

  1. prorealcode
  2. tradingview
import numpy as np
import pandas as pd
def testEBSW(close,length = 40,bars = 10):
    '''Just making the ebsw indicator from pro real code'''
    #Instance Variables
    lastHP = lastClose = 0
    filtHist = np.zeros(3)
    result = [np.nan]*(length-1)+[0]

    #Calculate constants
    angle = 2*np.pi/length
    alpha1 = (1-np.sin(angle))/np.cos(angle)
    ang = 2**.5*np.pi/bars
    a1 = np.exp(-ang)
    c2 = 2*a1*np.cos(ang)
    c3 = -a1**2
    c1 = 1-c2-c3

    for i in range(length,close.size):
        HP = 0.5*(1+alpha1)*(close[i]-lastClose)+alpha1*lastHP

        #Rotate filters to overwrite oldest value
        filtHist = np.roll(filtHist,-1)
        filtHist[-1] = c1*(HP+lastHP)/2+c2*filtHist[1]+c3*filtHist[0]

        #Wave calculation
        wave = np.mean(filtHist)
        rms = np.sqrt(np.mean(filtHist**2))
        wave = wave/rms

        #Update past values
        lastHP = HP
        lastClose = close[i]
        result.append(wave)
    return pd.Series(result, index=close.index)

The outputs are pretty different so this code could be bugged, either way I think the original code could be changed slightly to not calculate the constants on every loop as they don't change. Sorry if this serves no purpose, I just signed up to post this so I don't know how any of this works.

Figure_1

I realized after posting this graph is pretty ambiguous, but it's the result of both indicator types on 100 days of EURUSD data I have saved to my computer. Blue line is the one in this library and the orange one is my test function.

@Squigglez2 Squigglez2 added the enhancement New feature or request label Jul 23, 2021
@twopirllc
Copy link
Owner

Hello @Squigglez2,

Interesting. I will add it to the list of things. Have you tried exporting data and it's indicator values from TradingView and run a correlation test to see how inline your version is with TradingView? If not, that would help you see if there are bugs in your code.

How to do a TV Correlation Test

Are you using a different data source for Pandas TA and then visually comparing the numbers displayed from TradingView? If so, then that can cause deviations in calculation because they are not the same data source. You can Export Chart Data from TradingView data for comparison by using the hamburger menu in the upper left corner; select the ISO format.

Screen Shot 2020-09-02 at 7 54 25 AM

Once you have exported your chart data from TradingView, try the following:

import pandas as pd
import pandas_ta as ta

# Load the TV export data or whatever you saved it as
data = pd.read_csv("path/to/tradingview_data.csv") 
data.ta.chop(length=14, append=True) # Example using the choppiness index. Replace with your indicator
# data.drop()   # https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.drop.html
print(data.corr()) # Check their correlation

Also, @rengel8 would you mind taking a look at this Issue when you have a moment?

Kind Regards,
KJ

@Squigglez2
Copy link
Author

Squigglez2 commented Jul 23, 2021

I'll give it a try. The graph I posted was the version in Pandas_TA and my custom function both run on the same EURUSD data. I just compared the tradingview and prorealcode to make sure I didn't miss any steps since I've never used either of those languages and figured it help prevent mistakes.

EDIT: Sadly, it seems that exporting chart data requires a premium account which I don't have.

@twopirllc
Copy link
Owner

@Squigglez2,

EDIT: Sadly, it seems that exporting chart data requires a premium account which I don't have.

Understandable. Thanks for providing links to the TradingView source so I can do it. Unfortunately, I do not have a time frame on the resolution of this Issue.

Kind Regards,
KJ

@Squigglez2
Copy link
Author

Squigglez2 commented Jul 24, 2021

Understandable, the code I posted should be runnable at least, if anyone else with a premium account has the chance. Or can somehow give me a copy of the close data and indicator output.

@rengel8
Copy link
Contributor

rengel8 commented Aug 11, 2021

@Squigglez2 Thank you very much for providing the function of the EBSW. That made it easy to look into it.

With the data, @twopirllc provided, I made a comparison between TradingView and the updated version, which is now very close (despite some bars 4 to 6 decimal places are identical) to TradingView.
TV offers a very fast pre-roll of only one bar probably with historical data under the hood. That is interesting, but the recent version in Pandas TA is now closely to TV with the advantage of providing the same results each time one bar earlier.
TV offers a very fast pre-roll of only one bar probably with historical data under the hood. That is interesting, but the recent version in Pandas TA is now closely to TV with the advantage of providing the same results each time one bar earlier.

@Squigglez2
Copy link
Author

Has the code been updated for this then?

@twopirllc
Copy link
Owner

Hello @Squigglez2,

Please test the updated version using by installing the development branch and let us know if it is working better.

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

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
Projects
None yet
Development

No branches or pull requests

3 participants