首页 > 解决方案 > TradingView {{close}} 不适用于警报、纯文本

问题描述

我想让https://www.tradingview.com/script/whJATyGU-UT-Bot/这个机器人更有用,但我遇到了一些问题,希望你能帮助我。

代码是用纯文本编写的。

我已经修改了如下代码,(只是添加了两行代码以创建警报)

study(title="VET Bot", overlay = true)

SOURCE = input(hlc3)
RSILENGTH = input(14, title = "RSI LENGTH")
RSICENTERLINE = input(52, title = "RSI CENTER LINE")
MACDFASTLENGTH = input(7, title = "MACD FAST LENGTH")
MACDSLOWLENGTH = input(12, title = "MACD SLOW LENGTH")
MACDSIGNALSMOOTHING = input(12, title = "MACD SIGNAL SMOOTHING")

a = input(1, title = "Key Vaule")
SmoothK = input(3)
SmoothD = input(3)
LengthRSI = input(14)
LengthStoch = input(14)
RSISource = input(close) 
c = input(9, title="ATR Period")

xATR = atr(c)
nLoss = a * xATR
xATRTrailingStop = iff(close > nz(xATRTrailingStop[1], 0) and close[1] > nz(xATRTrailingStop[1], 0), max(nz(xATRTrailingStop[1]), close - nLoss),
                    iff(close < nz(xATRTrailingStop[1], 0) and close[1] < nz(xATRTrailingStop[1], 0), min(nz(xATRTrailingStop[1]), close + nLoss), 
                        iff(close > nz(xATRTrailingStop[1], 0), close - nLoss, close + nLoss)))
pos =   iff(close[1] < nz(xATRTrailingStop[1], 0) and close > nz(xATRTrailingStop[1], 0), 1,
        iff(close[1] > nz(xATRTrailingStop[1], 0) and close < nz(xATRTrailingStop[1], 0), -1, nz(pos[1], 0))) 

color = pos == -1 ? red: pos == 1 ? green : blue 
ema= ema(close,1)
above = crossover(ema,xATRTrailingStop )
below = crossover(xATRTrailingStop,ema)
buy = close > xATRTrailingStop and above 
sell = close < xATRTrailingStop and below
barbuy = close > xATRTrailingStop 
barsell = close < xATRTrailingStop 

alertcondition(buy, title='Al', message = 'Al')
alertcondition(sell, title='Sat', message = 'Sat')
plotshape(buy, title = "Al", text = 'Al', style = shape.labelup, location = location.belowbar, color= green,textcolor = white, transp = 0, size = size.tiny)
plotshape(sell, title = "Sat", text = 'Sat', style = shape.labeldown, location = location.abovebar, color= red,textcolor = white, transp = 0, size = size.tiny)

barcolor(barbuy? green:na)
barcolor(barsell? red:na)

为了使用我创建的警报,我必须更改警报屏幕上的警报条件,如附加图像。

在此处输入图像描述

我的问题从这里开始,一般来说,当我在 TradingView 上使用默认警报时,我可以使用 {{close}} 变量来达到柱的收盘价但是,如果我使用我编辑过的脚本,我将无法使用它并且消息似乎是这样的;

(COINBASE:BTCUSD, m1), 价格 = {{close}}

m1 是警报的时间范围,在这种情况下为 1 分钟。

有谁知道如何使用 {{close}} 变量或任何想法来达到价格?

我还尝试在如下代码中更改警报的消息部分,但随后在警报屏幕上出现错误。

此致,

alertcondition(buy, title='Al', message = 'Al @' + tostring(close))

在此处输入图像描述

标签: pine-scriptplaintextalerts

解决方案


{{close}}仅适用于@version=4 但是,一旦你把@version=4代码放在顶部,你会得到很多错误,因为你的一些代码不能被@version=4. 您必须将它们转换为@version=4.


推荐阅读