1

(Tradingview 的 Pinescript)这可能与数学有关,但我无法弄清楚我在这里做错了什么。

我有一个脚本,用于计算 10、20、5 MACD 的 MACD 直方图,并评估当前价格的高/低平均值。如果今天的高/低平均 > 昨天和今天的高/低平均 > 昨天,则创建买入信号。从相反的方向产生卖出信号。这是正常运行的。

我试图产生的是两侧的两条线,其中一条表示何时产生相反信号的阈值。目的是人们可以很容易地看到事物与产生相反信号的距离有多近。

我的代码目前是

//@version=3
//Bollinger Bands with Buy and Sell Signaling
study(shorttitle="BB With Buy & Sell Signaling", title="BB With Buy & Sell Signaling", overlay=true)    

//Define MACD Variables
fast = 10, slow = 20
fastMACD = ema(hlc3, fast)
slowMACD = ema(hlc3, slow)
macd = fastMACD - slowMACD
signal = sma(macd, 5)
hist = macd - signal
currMacd = hist[0]
prevMacd = hist[1]
currPrice = hl2[0]
prevPrice = hl2[1]

buy = currPrice > prevPrice and currMacd > prevMacd
sell = currPrice < prevPrice and currMacd < prevMacd
neutral = (currPrice < prevPrice and currMacd > prevMacd) or (currPrice > prevPrice and currMacd < prevMacd)
//Plot Arrows

timetobuy = buy==1 and (sell[1]==1 or (neutral[1]==1 and sell[2]==1) or (neutral[1]==1 and neutral[2]==1 and sell[3]==1) or (neutral[1]==1 and neutral[2]==1 and neutral[3]==1 and sell[4]==1) or (neutral[1]==1 and neutral[2]==1 and neutral[3]==1 and neutral[4]==1 and sell[5]==1) or (neutral[1]==1 and neutral[2]==1 and neutral[3]==1 and neutral[4]==1 and neutral[5]==1 and sell[6]==1))



timetosell = sell==1 and (buy[1]==1 or (neutral[1]==1 and buy[2]==1) or (neutral[1]==1 and neutral[2]==1 and buy[3]==1) or (neutral[1]==1 and neutral[2]==1 and neutral[3]==1 and buy[4]==1) or (neutral[1]==1 and neutral[2]==1 and neutral[3]==1 and neutral[4]==1 and buy[5]==1) or (neutral[1]==1 and neutral[2]==1 and neutral[3]==1 and neutral[4]==1 and neutral[5]==1 and buy[6]==1))
plotshape(timetobuy, color=blue, location=location.belowbar, style=shape.arrowup)
plotshape(timetosell, color=red, location=location.abovebar, style=shape.arrowdown)
//plotshape(neutral, color=black, location=location.belowbar, style=shape.circle)

//THE CODE BELOW IS WHAT I NEED STACK EXCHANGE HELP WITH



linenow = currPrice + (currMacd - prevMacd)
limitline = prevPrice + (currMacd - prevMacd)

plot(linenow, color = blue, offset = 2, show_last = 1, linewidth = 2)
plot(limitline, color = red, offset = 2, show_last = 1, linewidth = 2)

plot(currPrice, color = blue, offset = 2, show_last = 1, linewidth = 2)
plot(prevPrice, color = red, offset = 2, show_last = 1, linewidth = 2)
plot(linenow, color = blue, offset = 3, show_last = 1, linewidth = 2)
plot(limitline, color = red, offset = 3, show_last = 1, linewidth = 2)

我已经做了很多试验和错误。在这个最新版本中,我正在尝试单独制作这些线条,以查看它们是否根据箭头准确显示结果。一旦我把它整理好并开始工作,我会将它们组合成一对线。

现在,它们正在显示,但我认为我在某个地方有一些数学错误。有时他们指示正确,有时他们没有。他们应该显示当前状态,以及它将反转的阈值。

4

0 回答 0