Я пытаюсь с помощью функции tradingview перевести хороший publi c Сценарий RSI с v3 на v4, но переводчик выдает мне ошибку. решить, но я не смог.
//@version=3
study("RSI Shaded - MTF", "RSI MTF", overlay = false)
intval = input("H01", "Interval", options=["M01", "M03", "M05", "M15", "M30", "M45", "H01", "H02", "H03", "H04", "H08", "H12", "Day", "Week", "Month", "Year"])
useChartIntval = input(true, "Use Chart Interval")
length = input(2, title = "Length", minval = 1)
cLength = input(3, title = "Cumulative Length", minval = 1)
emaLength = input(5, title = "EMA of RSI Length", minval = 1, defval = 5)
ob = input(85, title="Over Bought")
os = input(15, title="Over Sold")
showCum = input(true, title = "Show Cumulative RSI?")
histBased = input(false, title = "Histogram Style?")
cBars = input(false, title = "Color Extreme Bars?")
showDiv = input(true, title = "Show Divergences?")
int = iff(intval == "M01", "1", iff(intval == "M03", "3", iff(intval == "M05", "5", iff(intval == "M15", "15", iff(intval == "M30", "30", iff(intval == "M45", "45", iff(intval == "H01", "60", iff(intval == "H02", "120", iff(intval == "H03", "180", iff(intval == "H04", "240", iff(intval == "H08", "480", iff(intval == "H12", "720", iff(intval == "Day", "D", iff(intval == "Week", "W", iff(intval == "Month", "M", iff(intval == "Year", "12M", "60"))))))))))))))))
bar = -1
bar := nz(bar[1]) + 1
start = security(tickerid, int, time, lookahead = true)
newSession = iff(change(start), 1, 0)
barsInInterval() =>
sinceNewSession = 0
offset = useChartIntval ? 0 : barssince(newSession)
sinceNewSession := na(sinceNewSession[1]) or offset > nz(sinceNewSession[1]) ? offset : nz(sinceNewSession[1])
barsInInt = barsInInterval()
isChartIntVal = useChartIntval or barsInInt == 0
src = close
getRSI() =>
srcPrev = src
srcPrev := newSession or isChartIntVal ? src[1] : nz(srcPrev[1])
gain = max(src - srcPrev, 0)
loss = max(srcPrev - src, 0)
ag = 50.0
al = 50.0
agPrev = 50.0
agPrev := newSession or isChartIntVal ? nz(ag[1]) : nz(agPrev[1])
alPrev = 50.0
alPrev := newSession or isChartIntVal ? nz(al[1]) : nz(alPrev[1])
// MMA formula for Average Gain & Average Loss
ag := (agPrev * (length - 1) + gain) / length
al := (alPrev * (length - 1) + loss) / length
rsi1 = 100 - 100 / (1 + ag / al)
rsi = if showCum
rsi = if not isChartIntVal and cLength > 1
rsi = if bar > 0 and bar > barsInInt + 1
step = (barsInInt + 1)
start = min(bar, barssince(newSession))
end = max(0, min(bar - 1, start + step * (cLength - 2)))
sum = rsi1
for i = start to end by step
sum := sum + rsi1[i + 1]
rsi = sum / cLength
else
rsi1
else
rsi = sma(rsi1, cLength)
else
rsi1
a = 2 / (emaLength + 1)
ema = close
emaPrev = close
emaPrev := newSession or isChartIntVal ? nz(ema[1]) : nz(emaPrev[1])
ema := emaPrev + a * (rsi - emaPrev)
[rsi, ema]
[rsi, ema] = getRSI()
// Plots
hline(ob, title = "Over Bought", linestyle = solid, color = #4444B0CC)
hline(os, title = "Over Sold", linestyle = solid, color = #4444B0CC)
hline(50, title = "Mid", linestyle = dashed, color = #666666CC)
color1 = rsi < os or rsi[1] < os ? #33FF33FF : rsi > ob or rsi[1] > ob ? #FF3333FF : #FFFFFFFF
color2 = rsi < os ? #33FF33FF : rsi > ob ? #FF3333FF : #88888855
p1 = plot(not histBased ? rsi : na, title = "RSI", histbase = 50, color = color1)
p2 = plot(histBased ? rsi : na, title = "RSI Histogram", histbase = 50, style = histogram, linewidth = 3, color = color2)
rsiClamp = plot(max(os, min(ob, rsi)), title = "RSI Clamped (Not Used)", color = #00000000, editable = false)
fill(p1, rsiClamp, title = "OS/OB Fill", color = rsi < 50 ? #00FF00FF : #FF0000FF)
e = plot(ema, title = "EMA", color = rsi > ema ? #00A2FFFF : #FF00FFFF)
fill(p1, e, title = "RSI - EMA fill", color = rsi > ema ? #00C2FF20 : #FF00FF20)
barcolor(title = "Bar Color", color = cBars ? (rsi < os ? #33FF33FF : rsi > ob ? #FF3333FF : #00000000) : na)
//end[enter image description here][1]
Это оригинальный скрипт из @mortdiggiddy https://www.tradingview.com/script/HINc7bmi-RSI-Shaded-MTF/