在 mplfinance 中更改支撑线和阻力线颜色
Change support and resistance line color in mplfinance
目前,我正在使用此代码。如果 hlines
是阻力位,我如何将其更改为红色,如果是支撑位,我该如何将其更改为蓝色?
mplfinance.plot(df,
type = 'candlestick',
style = 'binance',
hlines=dict(hlines= support_resistance,linestyle='-', linewidths = (1,1)),
volume = True)
我得到这样的结果:
hlines=dict(hlines= support_resistance,linestyle='-',linewidths = (1,1),colors=('b','r')
参见本教程中的示例单元格“In [6]
”:https://github.com/matplotlib/mplfinance/blob/master/examples/using_lines.ipynb
您可能需要包含与 support_resistance
行一样多的颜色。例如,可能是这样的:colors=['b','r','b','r','r','r']
关于动态处理支撑阻力颜色(根据您的评论),mplfinance 不适合提供用于确定支撑或阻力的算法,只是提供工具使您更容易将它们可视化。
此外,每个用户可能有自己确定支撑或阻力的特定方式。
大概在构建 support_resistance
列表时,在代码中向该列表添加特定价格时,您可能知道该价格代表支撑还是阻力。在您的代码中的同一点,您应该将颜色('b' 或 'r')添加到颜色列表中。这样你就可以动态构建两个列表:support_resistance
和 colors
,它们最终的长度相同。
根据Daniel的建议,我制作了如下颜色列表,效果很好。 support_resistance 这里的变量包括支撑位和阻力位。
colors = []
for lvl in support_resistance:
if lvl > df['Close'][-1]:
colors.append('r')
else:
colors.append('b')
目前,我正在使用此代码。如果 hlines
是阻力位,我如何将其更改为红色,如果是支撑位,我该如何将其更改为蓝色?
mplfinance.plot(df,
type = 'candlestick',
style = 'binance',
hlines=dict(hlines= support_resistance,linestyle='-', linewidths = (1,1)),
volume = True)
我得到这样的结果:
hlines=dict(hlines= support_resistance,linestyle='-',linewidths = (1,1),colors=('b','r')
参见本教程中的示例单元格“In [6]
”:https://github.com/matplotlib/mplfinance/blob/master/examples/using_lines.ipynb
您可能需要包含与 support_resistance
行一样多的颜色。例如,可能是这样的:colors=['b','r','b','r','r','r']
关于动态处理支撑阻力颜色(根据您的评论),mplfinance 不适合提供用于确定支撑或阻力的算法,只是提供工具使您更容易将它们可视化。 此外,每个用户可能有自己确定支撑或阻力的特定方式。
大概在构建 support_resistance
列表时,在代码中向该列表添加特定价格时,您可能知道该价格代表支撑还是阻力。在您的代码中的同一点,您应该将颜色('b' 或 'r')添加到颜色列表中。这样你就可以动态构建两个列表:support_resistance
和 colors
,它们最终的长度相同。
根据Daniel的建议,我制作了如下颜色列表,效果很好。 support_resistance 这里的变量包括支撑位和阻力位。
colors = []
for lvl in support_resistance:
if lvl > df['Close'][-1]:
colors.append('r')
else:
colors.append('b')