[英]Adding signals on the candle chart
I would like to plot signals on my chart is there is a way to do it on candle stick?我想在我的图表上显示 plot 信号,有没有办法在烛台上做到这一点? I did the following and got stuck:(
我做了以下并卡住了:(
!pip install yfinance
!pip install mplfinance
import yfinance as yf
import mplfinance as mpf
import numpy as np
import pandas as pd
df=yf.download('BTC-USD',start='2008-01-04',end='2021-06-3',interval='1d')
buy=np.where((df['Close'] > df['Open']) & (df['Close'].shift(1) < df['Open'].shift(1),1,0)
fig = plt.figure(figsize = (20,10))
mpf.plot(df,figsize=(20,12),type ='candle',volume=True);
# any idea how to add the signal?
import yfinance as yf
import mplfinance as mpf
import numpy as np
df = yf.download('BTC-USD', start='2008-01-04', end='2021-06-3', interval='1d').tail(50)
buy = np.where((df['Close'] > df['Open']) & (df['Close'].shift(1) < df['Open'].shift(1)), 1, np.nan) * 0.95 * df['Low']
apd = [mpf.make_addplot(buy, scatter=True, markersize=100, marker=r'$\Uparrow$', color='green')]
mpf.plot(df, type='candle', volume=True, addplot=apd)
I just added .tail()
for better visualization.我刚刚添加了
.tail()
以获得更好的可视化效果。
Output: Output:
You place signals on the plot using the "make additional plot" api: mpf.make_addplot(data,**kwargs)
.您使用“制作附加图” api:
mpf.make_addplot(data,**kwargs)
在 plot 上放置信号。 The data that you pass in to make_addplot
must be the same length as your original candlestick dataframe (so that mplfinance can line it up appropriately with the candlesticks).您传递给
make_addplot
的数据必须与原始烛台 dataframe 的长度相同(以便 mplfinance 可以将其与烛台适当对齐)。 If you do not want to plot a signal at every location you simply fill the data with nan
values except where you do want to plot a signal.如果您不想在每个位置都发送 plot 信号,您只需用
nan
值填充数据,但您确实想要发送 plot 信号的地方除外。
The return value from ap = mpf.make_addplot()
is then passed into mpf.plot(df,addplot=ap)
using the addplot
kwarg.然后使用
addplot
kwarg 将ap = mpf.make_addplot()
的返回值传递给mpf.plot(df,addplot=ap)
。
You can see many examples in this tutorial on adding your own technical studies to plots .您可以在本教程中看到许多关于将您自己的技术研究添加到图中的示例。
Take the time (maybe 10 minutes or so) to go carefully through the entire tutorial.花点时间(大概 10 分钟左右)到 go 仔细阅读整个教程。 It will be time well spent.
时间花得值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.