def ax_draw_macd(axes, kdata, n1=12, n2=26, n3=9): """绘制MACD :param axes: 指定的坐标轴 :param KData kdata: KData :param int n1: 指标 MACD 的参数1 :param int n2: 指标 MACD 的参数2 :param int n3: 指标 MACD 的参数3 """ macd = MACD(CLOSE(kdata), n1, n2, n3) bmacd, fmacd, smacd = macd.getResult(0), macd.getResult(1), macd.getResult(2) text = 'MACD(%s,%s,%s) DIF:%.2f, DEA:%.2f, BAR:%.2f'%(n1,n2,n3,fmacd[-1],smacd[-1],bmacd[-1]) #axes.text(0.01,0.97, text, horizontalalignment='left', verticalalignment='top', transform=axes.transAxes) total = len(kdata) x_list = [i for i in range(total)] y1_list = [round(x) if x > 0 else '-' for x in bmacd] y2_list = [round(x) if x <= 0 else '-' for x in bmacd] bar = Bar(subtitle=text, title_pos='10%', title_top='8%') bar.add('1', x_list, y1_list, is_stack=True, is_legend_show=False) bar.add('2', x_list, y2_list, is_stack=True, is_legend_show=False) axes.add(bar) iplot(fmacd, line_type='dotted') iplot(smacd) return axes
def ax_draw_macd(axes, kdata, n1=12, n2=26, n3=9): """绘制MACD :param axes: 指定的坐标轴 :param KData kdata: KData :param int n1: 指标 MACD 的参数1 :param int n2: 指标 MACD 的参数2 :param int n3: 指标 MACD 的参数3 """ macd = MACD(CLOSE(kdata), n1, n2, n3) bmacd, fmacd, smacd = macd.getResult(0), macd.getResult(1), macd.getResult(2) text = 'MACD(%s,%s,%s) DIF:%.2f, DEA:%.2f, BAR:%.2f'%(n1,n2,n3,fmacd[-1],smacd[-1],bmacd[-1]) axes.text(0.01,0.97, text, horizontalalignment='left', verticalalignment='top', transform=axes.transAxes) total = len(kdata) x = [i-0.2 for i in range(total)] x1 = [x[i] for i,d in enumerate(bmacd) if d>0] y1 = [i for i in bmacd if i>0] x2 = [x[i] for i,d in enumerate(bmacd) if d<=0] y2 = [i for i in bmacd if i<=0] axes.bar(x1,y1, width=0.4, color='r', edgecolor='r') axes.bar(x2,y2, width=0.4, color='g', edgecolor='g') axt = axes.twinx() axt.grid(False) axt.set_yticks([]) fmacd.plot(axes=axt, linestyle='--', legend_on=False, text_on=False) smacd.plot(axes=axt, legend_on=False, text_on=False) for label in axt.get_xticklabels(): label.set_visible(False)
def ax_draw_macd(axes, kdata, n1=12, n2=26, n3=9): """绘制MACD :param axes: 指定的坐标轴 :param KData kdata: KData :param int n1: 指标 MACD 的参数1 :param int n2: 指标 MACD 的参数2 :param int n3: 指标 MACD 的参数3 """ macd = MACD(CLOSE(kdata), n1, n2, n3) bmacd, fmacd, smacd = macd.getResult(0), macd.getResult(1), macd.getResult(2) text = 'MACD(%s,%s,%s) DIF:%.2f, DEA:%.2f, BAR:%.2f'%(n1,n2,n3,fmacd[-1],smacd[-1],bmacd[-1]) #axes.text(0.01,0.97, text, horizontalalignment='left', verticalalignment='top', transform=axes.transAxes) total = len(kdata) x_list = [i for i in range(total)] y1_list = [round(x) if x > 0 else '-' for x in bmacd] y2_list = [round(x) if x <= 0 else '-' for x in bmacd] style = gcf().get_style(axes) bar = Bar(subtitle=text, title_pos='10%', title_top='8%') bar.add('1', x_list, y1_list, is_stack=True, is_legend_show=False, **style) bar.add('2', x_list, y2_list, is_stack=True, is_legend_show=False, **style) axes.add(bar) fmacd.plot(axes=axes, line_type='dotted') smacd.plot(axes=axes) gcf().add_axis(axes) return gcf()
def ax_draw_macd2(axes, ref, kdata, n1=12, n2=26, n3=9): """绘制MACD。 当BAR值变化与参考序列ref变化不一致时,显示为灰色, 当BAR和参考序列ref同时上涨,显示红色 当BAR和参考序列ref同时下跌,显示绿色 :param axes: 指定的坐标轴 :param ref: 参考序列,EMA :param KData kdata: KData :param int n1: 指标 MACD 的参数1 :param int n2: 指标 MACD 的参数2 :param int n3: 指标 MACD 的参数3 """ macd = MACD(CLOSE(kdata), n1, n2, n3) bmacd, fmacd, smacd = macd.getResult(0), macd.getResult(1), macd.getResult( 2) text = 'MACD(%s,%s,%s) DIF:%.2f, DEA:%.2f, BAR:%.2f' % ( n1, n2, n3, fmacd[-1], smacd[-1], bmacd[-1]) axes.text(0.01, 0.97, text, horizontalalignment='left', verticalalignment='top', transform=axes.transAxes) total = len(kdata) x = [i - 0.2 for i in range(0, total)] y = bmacd x1, x2, x3 = [x[0]], [], [] y1, y2, y3 = [y[0]], [], [] for i in range(1, total): if ref[i] - ref[i - 1] > 0 and y[i] - y[i - 1] > 0: x2.append(x[i]) y2.append(y[i]) elif ref[i] - ref[i - 1] < 0 and y[i] - y[i - 1] < 0: x3.append(x[i]) y3.append(y[i]) else: x1.append(x[i]) y1.append(y[i]) axes.bar(x1, y1, width=0.4, color='#BFBFBF', edgecolor='#BFBFBF') axes.bar(x2, y2, width=0.4, color='r', edgecolor='r') axes.bar(x3, y3, width=0.4, color='g', edgecolor='g') axt = axes.twinx() axt.grid(False) axt.set_yticks([]) fmacd.plot(axes=axt, linestyle='--', legend_on=False, text_on=False) smacd.plot(axes=axt, legend_on=False, text_on=False) for label in axt.get_xticklabels(): label.set_visible(False)
def ax_draw_macd2(axes, ref, kdata, n1=12, n2=26, n3=9): """绘制MACD。 当BAR值变化与参考序列ref变化不一致时,显示为灰色, 当BAR和参考序列ref同时上涨,显示红色 当BAR和参考序列ref同时下跌,显示绿色 :param axes: 指定的坐标轴 :param ref: 参考序列,EMA :param KData kdata: KData :param int n1: 指标 MACD 的参数1 :param int n2: 指标 MACD 的参数2 :param int n3: 指标 MACD 的参数3 """ macd = MACD(CLOSE(kdata), n1, n2, n3) bmacd, fmacd, smacd = macd.getResult(0), macd.getResult(1), macd.getResult(2) text = 'MACD(%s,%s,%s) DIF:%.2f, DEA:%.2f, BAR:%.2f'%(n1,n2,n3,fmacd[-1],smacd[-1],bmacd[-1]) axes.text(0.01,0.97, text, horizontalalignment='left', verticalalignment='top', transform=axes.transAxes) total = len(kdata) x = [i-0.2 for i in range(0, total)] y = bmacd x1,x2,x3 = [x[0]],[],[] y1,y2,y3 = [y[0]],[],[] for i in range(1, total): if ref[i]-ref[i-1]>0 and y[i]-y[i-1]>0: x2.append(x[i]) y2.append(y[i]) elif ref[i]-ref[i-1]<0 and y[i]-y[i-1]<0: x3.append(x[i]) y3.append(y[i]) else: x1.append(x[i]) y1.append(y[i]) axes.bar(x1,y1, width=0.4, color='#BFBFBF', edgecolor='#BFBFBF') axes.bar(x2,y2, width=0.4, color='r', edgecolor='r') axes.bar(x3,y3, width=0.4, color='g', edgecolor='g') axt = axes.twinx() axt.grid(False) axt.set_yticks([]) fmacd.plot(axes=axt, linestyle='--', legend_on=False, text_on=False) smacd.plot(axes=axt, legend_on=False, text_on=False) for label in axt.get_xticklabels(): label.set_visible(False)
def ax_draw_macd2(axes, ref, kdata, n1=12, n2=26, n3=9): """绘制MACD :param axes: 指定的坐标轴 :param KData kdata: KData :param int n1: 指标 MACD 的参数1 :param int n2: 指标 MACD 的参数2 :param int n3: 指标 MACD 的参数3 """ macd = MACD(CLOSE(kdata), n1, n2, n3) bmacd, fmacd, smacd = macd.getResult(0), macd.getResult(1), macd.getResult( 2) text = 'MACD(%s,%s,%s) DIF:%.2f, DEA:%.2f, BAR:%.2f' % ( n1, n2, n3, fmacd[-1], smacd[-1], bmacd[-1]) #axes.text(0.01,0.97, text, horizontalalignment='left', verticalalignment='top', transform=axes.transAxes) total = len(kdata) x = [i for i in range(total)] y = bmacd y1, y2, y3 = [y[0]], [y[0]], [y[0]] for i in range(1, total): if ref[i] - ref[i - 1] > 0 and y[i] - y[i - 1] > 0: y2.append(y[i]) y1.append('-') y3.append('-') elif ref[i] - ref[i - 1] < 0 and y[i] - y[i - 1] < 0: y3.append(y[i]) y1.append('-') y2.append('-') else: y1.append(y[i]) y2.append('-') y3.append('-') style = gcf().get_style(axes) bar = Bar(subtitle=text, title_pos='10%', title_top='8%') bar.add('1', x, y1, is_stack=True, is_legend_show=False, **style) bar.add('2', x, y2, is_stack=True, is_legend_show=False, **style) bar.add('3', x, y3, is_stack=True, is_legend_show=False, **style) axes.add(bar) fmacd.plot(axes=axes, line_type='dotted') smacd.plot(axes=axes) gcf().add_axis(axes) return gcf()
def ax_draw_macd2(axes, ref, kdata, n1=12, n2=26, n3=9): """绘制MACD :param axes: 指定的坐标轴 :param KData kdata: KData :param int n1: 指标 MACD 的参数1 :param int n2: 指标 MACD 的参数2 :param int n3: 指标 MACD 的参数3 """ macd = MACD(CLOSE(kdata), n1, n2, n3) bmacd, fmacd, smacd = macd.getResult(0), macd.getResult(1), macd.getResult(2) text = 'MACD(%s,%s,%s) DIF:%.2f, DEA:%.2f, BAR:%.2f'%(n1,n2,n3,fmacd[-1],smacd[-1],bmacd[-1]) #axes.text(0.01,0.97, text, horizontalalignment='left', verticalalignment='top', transform=axes.transAxes) total = len(kdata) x = [i for i in range(total)] y = bmacd y1,y2,y3 = [y[0]],[y[0]],[y[0]] for i in range(1, total): if ref[i]-ref[i-1]>0 and y[i]-y[i-1]>0: y2.append(y[i]) y1.append('-') y3.append('-') elif ref[i]-ref[i-1]<0 and y[i]-y[i-1]<0: y3.append(y[i]) y1.append('-') y2.append('-') else: y1.append(y[i]) y2.append('-') y3.append('-') style = gcf().get_style(axes) bar = Bar(subtitle=text, title_pos='10%', title_top='8%') bar.add('1', x, y1, is_stack=True, is_legend_show=False, **style) bar.add('2', x, y2, is_stack=True, is_legend_show=False, **style) bar.add('3', x, y3, is_stack=True, is_legend_show=False, **style) axes.add(bar) fmacd.plot(axes=axes, line_type='dotted') smacd.plot(axes=axes) gcf().add_axis(axes) return gcf()
def ax_draw_macd(axes, kdata, n1=12, n2=26, n3=9): """绘制MACD :param axes: 指定的坐标轴 :param KData kdata: KData :param int n1: 指标 MACD 的参数1 :param int n2: 指标 MACD 的参数2 :param int n3: 指标 MACD 的参数3 """ macd = MACD(CLOSE(kdata), n1, n2, n3) bmacd, fmacd, smacd = macd.getResult(0), macd.getResult(1), macd.getResult( 2) text = 'MACD(%s,%s,%s) DIF:%.2f, DEA:%.2f, BAR:%.2f' % ( n1, n2, n3, fmacd[-1], smacd[-1], bmacd[-1]) axes.text(0.01, 0.97, text, horizontalalignment='left', verticalalignment='top', transform=axes.transAxes) total = len(kdata) x = [i - 0.2 for i in range(total)] x1 = [x[i] for i, d in enumerate(bmacd) if d > 0] y1 = [i for i in bmacd if i > 0] x2 = [x[i] for i, d in enumerate(bmacd) if d <= 0] y2 = [i for i in bmacd if i <= 0] axes.bar(x1, y1, width=0.4, color='r', edgecolor='r') axes.bar(x2, y2, width=0.4, color='g', edgecolor='g') axt = axes.twinx() axt.grid(False) axt.set_yticks([]) fmacd.plot(axes=axt, linestyle='--', legend_on=False, text_on=False) smacd.plot(axes=axt, legend_on=False, text_on=False) for label in axt.get_xticklabels(): label.set_visible(False)