Giter VIP home page Giter VIP logo

Comments (3)

DanielGoldfarb avatar DanielGoldfarb commented on May 24, 2024

@Branden720 talk about "wasn't sufficient" ... it's virtually impossible to debug code from a single line of code. Please show the entire code, and provide a data example, so that others can reproduce the problem.

from mplfinance.

Branden720 avatar Branden720 commented on May 24, 2024

@DanielGoldfarb CODE IS AS BELOW,what i was trying to accomplish with the code here is i want to calculate when the current EMA is above the previous EMA for a buy signal and vice versa using the ydata from the already plotted figure instead of using ema value. So i keep getting errors as i mentioned above

period = 1260
exp= pdf1 ['open' ].ewm(span=period, adjust=False) .mean ()

apds = [mpf.make_addplot (exp, color='blue')]
s1 = mpf.make_mpf_style (base_mpf_style='yahoo', y_on_right=False)

fig, axlist = mpf.plot(pdf1, type='candle', addplot=apds, style=s1, returnfig=True)

ema_plot_ydata = apds[0].plot[0].lines[0].get_ydata (). <<<KEY

buy_signals = []
sell_signals = []

for i in range (1, len (ema_plot_ydata)):
if ema_plot_ydata[i] > ema_plot_ydatali - 1]:
buy_signals.append(i) # Buy signal elif ema_plot_ydata[i] < ema_plot_ydata[i - 1]:
sell_signals.append(i) # Sell signal

add_buy_signals = mpf.make_addplot(buy_signals, type='scatter', markersize=50,
marker=‘^’, color='green')
add_sell_signals = mpf.make_addplot (sell_signals, type='scatter', markersize=50,
marker='v', color='red')

fig, axlist = mpf.plot (pdf1, type=‘candle’,
style=s1, addplot=[apds,
add_buy_signals, add_sell_signals], returnfig=True)

mpf.show ()

from mplfinance.

DanielGoldfarb avatar DanielGoldfarb commented on May 24, 2024

@Branden720
First of all, your code won't run as written. Perhaps you have some typos in it.

Second, and more importantly, what you are trying to do makes no sense. You already have you exponential moving average here:

exp = pdf1['open'].ewm(span=period,adjust=False).mean()

Why plot it and then try to extract it from the plot?
That's just wasteful. Instead, use the data that you have already:

for i in range (1, len(exp)):
    if exp[i] > exp[i - 1]:
        ...

I won't go into everything else that's wrong with the code as you have written it above. It clearly won't work. That said, if you wanted to correctly extract the data from the plot, the appropriate line of code would be:

data = axlist[0].get_lines()[0].get_ydata()

If you were to then compare data to exp you would find they are identical!

from mplfinance.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.