Почему этот код не запускается в скрипте Pine? Ошибка “Необъявленный идентификатор”

#pine-script #algorithmic-trading #tradingview-api

#pine-script #алгоритмическая торговля #tradingview-api

Вопрос:

Итак, я получаю следующую ошибку необъявленного идентификатора в редакторе Pine, касающуюся цветов..

 line 23: Undeclared identifier 'red';
line 24: Undeclared identifier 'blue';
line 25: Undeclared identifier 'white';
line 36: Undeclared identifier 'blue';
line 36: Undeclared identifier 'white';
line 50: Undeclared identifier 'red';
line 50: Undeclared identifier 'black'
  

И вот код, который я запускаю. Как вы можете видеть, я использую версию 4.

 //@version=4
    study("Simple Trading", overlay = true)
 
ma5 = sma(close, 5)
ma10 = sma(close, 10)
ma30 = sma(close, 30)
 
src1 = input(close, title = "RSI Source")
rsil = input(14, minval = 1, title = "RSI Length")
rsi30 = input(30, minval = 1, title = "Buy w/RSI < ")
rsi70 = input(70, minval = 1, title = "Sell w/RSI > ")
 
src2 = input(close, title = "Stoch Source")
kdk = input(9, minval = 1, title = "Stoch K")
kdd = input(3, minval = 1, title = "Stoch D")
kds = input(3, minval = 1, title = "Stoch Smooth")
kd20 = input(20, minval = 1, title = "Buy w/STOCH <")
kd80 = input(80, minval = 1, title = "Sell w/STOCH >")
 
plot(ma5, color = red)
plot(ma10, color = blue)
plot(ma30, color = white)
 
//main------------------------------------
_falling = falling(ma30, 20)
fiveless = ma5 < ma30
tenless = ma10 < ma30
armbuy = fiveless and tenless and _falling
rsi = rsi(src1, rsil) < rsi30
greencandle = close > open and close[1] <= open[1] and close>close[1]
strongbuyhere = armbuy and rsi and greencandle
 
plotshape(strongbuyhere, style = shape.labelup, color = blue, location = location.belowbar, size = size.small, text = "Buy", textcolor = white)
alertcondition(strongbuyhere, title = "Strong Buy Position", message = "Buy")
plot(valuewhen(strongbuyhere, close, 0))
 
 
//reverse---------------------------------
r_falling = rising(ma30, 20)
rfiveless = ma5 > ma30
rtenless = ma10 > ma30
rarmbuy = rfiveless and rtenless and r_falling
rrsi = rsi(src1, rsil) > rsi70
rgreencandle = close < open and close[1] > open[1]
rstrongbuyhere = rarmbuy and rrsi and rgreencandle
 
plotshape(rstrongbuyhere, style = shape.labeldown, color = red, location = location.abovebar, size = size.small, text = "Sell", textcolor = black)
alertcondition(rstrongbuyhere, title = "Strong Sell Position", message = "Sell")
plot(valuewhen(rstrongbuyhere, close, 0))''' 
  

Кто-нибудь знает, как я могу это исправить и что я сделал не так?

Спасибо

Ответ №1:

Вы используете pinescript версии 4 (строка 1: //@version=4 ). В версии 4 цвета называются с color. префиксом:

пример https://www.tradingview.com/pine-script-reference/#var_color {точка}красный :

 color.red
color.blue
color.black
  

или color.new функция https://www.tradingview.com/pine-script-reference/#fun_color {точка}новый