需要帮助?

试试AI小助手吧

获得股票K线BAR状态

用户头像mx_***307okn
2023-10-30 发布

股票K线的bar

股票K线图中的"bar"指的是K线柱状图。K线图是一种用于显示股票价格走势的图表,它由一系列的K线组成,每根K线代表一段时间内的股票价格信息。

每根K线包含四个价格数据:开盘价(Open)、最高价(High)、最低价(Low)和收盘价(Close)。

K线柱状图通过绘制这四个价格数据来展示股票价格的波动情况。

在K线柱状图中,每根柱子的长度表示股票在该时间段的价格波动范围。

柱子的上下端分别表示最高价和最低价,柱子的左右端表示开盘价和收盘价。

如果收盘价高于开盘价,柱子通常用实心或绿色表示;如果收盘价低于开盘价,柱子通常用空心或红色表示。

通过观察K线柱状图,可以直观地了解股票在不同时间段内的价格走势,判断买入和卖出时机,以及分析市场的买卖力量和趋势。

代码

# 获取股票K线的bar
def get_day_bar_shape(stock):
    bar_shape=''
    bar_color=""
    end_date = get_datetime().strftime("%Y%m%d")
    df_stock_data=get_price(securities=stock,end_date=end_date, fre_step='1d', fields=['open', 'close', 'low', 'high', 'volume','high_limit','low_limit','prev_close'], skip_paused=False, fq='pre', bar_count=1, is_panel = 0)
    log.info(df_stock_data)
    stock_open_price=df_stock_data['open'][0]
    stock_close_price=df_stock_data['close'][0]
    stock_low_price=df_stock_data['low'][0]
    stock_high_price=df_stock_data['high'][0]
    stock_low_limit_price=df_stock_data['low_limit'][0]
    stock_high_limit_price=df_stock_data['high_limit'][0]
    stock_volume=df_stock_data['volume'][0]
    stock_pre_close=df_stock_data['prev_close'][0]
    low_shadow_line_lenth = 0
    up_shadow_line_lenth = 0 
    if (stock_close_price - stock_open_price) > 0 :
        bar_color='红色'
        low_shadow_line_lenth=stock_open_price-stock_low_price
        up_shadow_line_lenth=stock_high_price-stock_close_price
    elif (stock_close_price - stock_open_price) < 0 :
        bar_color='绿色'
        low_shadow_line_lenth=stock_close_price-stock_low_price
        up_shadow_line_lenth=stock_high_price-stock_open_price
      
    if (low_shadow_line_lenth == 0) and (up_shadow_line_lenth == 0) and (bar_color == "红色"):
        bar_shape='大阳线'
        return bar_shape
    elif (low_shadow_line_lenth == 0) and (up_shadow_line_lenth == 0) and (bar_color == "绿色"):
        bar_shape='大阴线'
        return bar_shape
    elif (low_shadow_line_lenth == 0) and (up_shadow_line_lenth == 0) and (stock_open_price>stock_pre_close):
        bar_shape='红色一字线'
        return bar_shape
    elif (low_shadow_line_lenth == 0) and (up_shadow_line_lenth == 0) and (stock_open_price<stock_pre_close):
        bar_shape='绿色一字线' 
        return bar_shape

评论