这个Pinescript输出的数学是什么

时间:2018-01-19 07:38:10

标签: tradingview-api pine-script

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

我有一个脚本计算10,20,5 MACD的MACD柱状图,并且还评估当前价格高/低平均值。如果今天的高/低平均值>昨天的AND和今天的高/低平均值>昨天,创造买入信号。卖出信号是从相反的方向产生的。 这是正常运作。

我试图产生的是两条线,一条线表示产生相反信号的阈值。目的是有人可以很容易地看到产生相反信号的接近程度。

我的代码目前正在

//@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)

我做了很多试验和错误。这是最新版本,我正在尝试单独生成线条,看它们是否根据箭头准确显示结果。一旦我把它整理好并且正常工作,我将把它们组合成一对线。

现在,他们正在展示,但我认为我的某些数学错误。有时它们表示正确,有时则表示不正确。它们应该显示当前状态,以及它将反转的阈值。

0 个答案:

没有答案