gpt4 book ai didi

python - 在蜡烛图上添加信号

转载 作者:行者123 更新时间:2023-12-01 23:21:37 31 4
gpt4 key购买 nike

我想在我的图表上绘制信号,有没有办法在烛台上绘制信号?我做了以下并卡住了:(

!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)

为了更好的可视化,我刚刚添加了 .tail()

输出:

enter image description here

关于python - 在蜡烛图上添加信号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68035192/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com