当 2 条移动平均线相互交叉时绘制标签 — Pinescript v4 (TradingView)

问题描述

LonesomeTheBlue 编写了一个非常漂亮的脚本,用于绘制不同时间范围内的移动平均线。在此处详细了解他的脚本:Moving Average MTF Live [Experimental] by LonesomeTheBlue

我正在尝试绘制“买入”和“卖出”标签,以便在这两个 MA 相互交叉时绘制“买入”和“卖出”标签,但在这样做时遇到了问题。

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © LonesomeTheBlue

//@version=4
study("[CS] Moving Average MTF Live [Experimental]",overlay = true)

tf = input('5',type = input.resolution)
fastlen = input(7)
slowlen = input(200)

// get HTF moving averages
emafast = security(syminfo.tickerid,tf,ema(close,fastlen),lookahead = true)
emafastcur = security(syminfo.tickerid,lookahead = false)
emaslow = security(syminfo.tickerid,slowlen),lookahead = true)
emaslowcur = security(syminfo.tickerid,lookahead = false)

// is this last bar?
islast = security(syminfo.tickerid,barstate.islast,lookahead = true)

//if not last bar then draw non-repaint historical moving average
plot(islast ? na : emafast,color = islast ? na : color.lime,linewidth = 2)
plot(islast ? na : emaslow,color = islast ? na : color.red,linewidth = 2)

//calculate and keep the beginning of line
lastbar_index = 0
lastbar_index := change(time(tf)) != 0 ? 0 : nz(lastbar_index[1]) + 1

// draw real time higher time frame moving averare
line emahtffast = line.new(bar_index,emafastcur,bar_index - lastbar_index,color = color.blue,width = 0)
line emahtfslow = line.new(bar_index,emaslowcur,color = color.red,width = 0)

// delete old lines if it's not the last one in htf periof
if change(time(tf)) == 0
    line.delete(emahtffast[1])
    line.delete(emahtfslow[1])

我尝试了以下方法但没有成功。不知道我做错了什么,但会感谢你们中的一位有才华的窥视者的任何帮助!提前致谢。

    // buy+sell conditions / styling
    buyCond = crossover(emahtffast,emahtfslow)
    sellCond = crossunder(emahtfslow,emahtffast)

    plotshape(buyCond,style=shape.triangleup,size=size.normal,location=location.belowbar,color=color.lime)
    plotshape(sellCond,style=shape.triangledown,location=location.abovebar,color=color.red)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)