Comments (3)
@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.
@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.
@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)
- Subplot and panel work fine when they use separately, but mix up when I try to use them in same figure, how can I solve? HOT 8
- Feature Request: HOT 2
- How do i get renko values without ploting the chart? HOT 2
- weird orange line appearing in axes' .plot() HOT 1
- Parabolic Sar and supertrend for renko
- Assist to draw Simple Moving Average. HOT 2
- I just don't know who to ask…. HOT 1
- mplfinance warn if user passes an empty data set. HOT 1
- Feature Request: The line width argument adding request for 'candlestick_ohlc' about the 'Wick/shadow' part(above/blow line) HOT 9
- Bug Report: marketcolors display error when open=close HOT 1
- Bug Report: Typo HOT 1
- How do I create a buy indicator using mplfinance? HOT 1
- Using with `matplotlib.testing.decorators.image_comparison` HOT 6
- PNF ATR Boxsize HOT 4
- Hollow and Filled Candles HOT 1
- Feature Request: Add SubFigures to Mpf_Figure HOT 2
- The example image of price-movement_plots.ipynb is inconsistent with the displayed result. HOT 3
- Interactive plots for OHLC candles with mplfinance HOT 1
- What is the most elegant way to implement ribbons? HOT 4
- Bug Report: legends on panels overlaps
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mplfinance.