macd柱体与K线背离源码(macd柱子背离和线性背离)

macd柱体与K线背离源码(macd柱子背离和线性背离)

什么是MACD柱体与K线的背离?

MACD指标是一种常用的技术分析工具,由快速线(MACD线)、慢速线(信号线)和柱状线(柱体)组成。而K线则是股票或其他金融产品在一定时间内的开盘、最高、最低、收盘价数据所绘制的图形。MACD柱体与K线的背离是指当MACD柱体与K线形成反向的运动趋势时,可能预示着股价可能发生调整或逆转的信号。

什么是MACD柱子背离?

MACD柱子背离是指MACD柱体与K线形成相反方向的趋势。通常情况下,MACD柱子背离出现在股价的高点或低点,意味着市场上的买卖力量相对较弱,并可能预示着股价可能往相反的方向发生调整。

请提供一个MACD柱子背离源码的例子。

下面是一个示例代码:


//@version=4
study(title=\"MACD Divergence\", shorttitle=\"MACD Div\", overlay = true)
// MACD指标计算
[s1,s2,s3] = macd(close, 12, 26, 9)
// MACD柱状线计算
hline(0, \"Zero Line\", color.gray)
plot(s1-s2, \"Histogram\", color.blue, linewidth=2)
// 寻找背离的函数
findDivergence(source, side) =>
    var float value = na
    if side == \"up\"
        value := valuewhen(not na(source), source, 0)
        maxSource = highestbars(value, 5)
        maxPrice = highestbars(close, 5)
        if maxSource < maxPrice
            value := na
    else if side == \"down\"
        value := valuewhen(not na(source), source, 0)
        minSource = lowestbars(value, 5)
        minPrice = lowestbars(close, 5)
        if minSource < minPrice
            value := na
    value
// 检测MACD柱子背离
upDivergence = findDivergence(s1-s2, \"up\")
downDivergence = findDivergence(s1-s2, \"down\")
// 绘制背离箭头
plotshape(not na(upDivergence), color = color.green, style=shape.triangleup, title=\"Up Divergence\")
plotshape(not na(downDivergence), color = color.red, style=shape.triangledown, title=\"Down Divergence\")

什么是线性背离?

线性背离是指当股价的走势形成一个趋势线而指标走势形成与之相反的趋势线时。在MACD指标中,线性背离是指当股价形成上升趋势时,MACD指标形成下降趋势线;而当股价形成下降趋势时,MACD指标形成上升趋势线。线性背离可以视为股价与指标之间的背离信号。

请提供一个线性背离源码的例子。

以下是一个在线性背离的例子:


//@version=4
study(title=\"Linear Divergence\", shorttitle=\"Linear Div\", overlay = true)
// 线性背离判断函数
linearDivergence(source, side) =>
    var line trendLine = na
    var bool signal = na
    // 根据side参数判断上升或下降趋势
    if side == \"up\"
        trendLine := line.new(x1=bar_index[1], y1=low[1], x2=bar_index, y2=low, color=color.blue)
        // 判断股价是否下穿趋势线
        signal := crossover(close, line.get_y1(trendLine))
    else if side == \"down\"
        trendLine := line.new(x1=bar_index[1], y1=high[1], x2=bar_index, y2=high, color=color.red)
        // 判断股价是否上穿趋势线
        signal := crossunder(close, line.get_y1(trendLine))
    signal
// 检测线性背离
upLinearDivergence = linearDivergence(close, \"up\")
downLinearDivergence = linearDivergence(close, \"down\")
// 绘制线性背离箭头
plotshape(not na(upLinearDivergence), color = color.green, style=shape.triangleup, title=\"Up Linear Divergence\")
plotshape(not na(downLinearDivergence), color = color.red, style=shape.triangledown, title=\"Down Linear Divergence\")

如何应用MACD柱体与K线的背离进行交易决策?

MACD柱体与K线的背离可以作为交易决策的参考指标。当股票或其他金融产品的K线形成新高点或新低点时,如果MACD柱体没有相应的新高点或新低点,就形成了背离信号,此时可以考虑调整或逆转行情的发生。在实际交易中,可以结合其他技术分析工具和交易策略进行综合判断,以增加交易胜率。

相关推荐

  • 暂无文章