Преобразовать код версии 2 для сценария Pine в версию 4 - PullRequest
0 голосов
/ 12 марта 2020

Я нашел 2 скрипта в tradingview и добавил их в свой скрипт, однако это не сработало. Я потерял много времени. Может кто-нибудь помочь мне конвертировать их в версию 4? Спасибо. Хорошего дня !!!

//@version=2
////////////////////////////////////////////////////////////
//  Copyright by HPotter v1.0 09/03/2018
// Linear Regression Intercept is one of the indicators calculated by using the 
// Linear Regression technique. Linear regression indicates the value of the Y 
// (generally the price) when the value of X (the time series) is 0. Linear 
// Regression Intercept is used along with the Linear Regression Slope to create 
// the Linear Regression Line. The Linear Regression Intercept along with the Slope 
// creates the Regression line.
////////////////////////////////////////////////////////////
study(title="Line Regression Intercept", overlay = true)
Length = input(14, minval=1)
xSeria = input(title="Source", type=source, defval=close)
xX = Length * (Length - 1) * 0.5
xDivisor = xX * xX - Length * Length * (Length - 1) * (2 * Length - 1) / 6
xXY = 0
for i = 0 to Length-1
	xXY := xXY + (i * xSeria[i])
xSlope = (Length * xXY - xX * sum(xSeria, Length)) / xDivisor
xLRI = (sum(xSeria, Length) - xSlope * xX) / Length
plot(xLRI, color=blue, title="LRI")
   //Author - Rajandran R
//www.marketcalls.in
study("Supertrend V1.0 - Buy or Sell Signal", overlay = true)

Factor=input(3, minval=1,maxval = 100)
Pd=input(7, minval=1,maxval = 100)


Up=hl2-(Factor*atr(Pd))
Dn=hl2+(Factor*atr(Pd))


TrendUp=close[1]>TrendUp[1]? max(Up,TrendUp[1]) : Up
TrendDown=close[1]<TrendDown[1]? min(Dn,TrendDown[1]) : Dn

Trend = close > TrendDown[1] ? 1: close< TrendUp[1]? -1: nz(Trend[1],1)
Tsl = Trend==1? TrendUp: TrendDown

linecolor = Trend == 1 ? green : red

plot(Tsl, color = linecolor , style = line , linewidth = 2,title = "SuperTrend")

plotshape(cross(close,Tsl) and close>Tsl , "Up Arrow", shape.triangleup,location.belowbar,green,0,0)
plotshape(cross(Tsl,close) and close<Tsl , "Down Arrow", shape.triangledown , location.abovebar, red,0,0)
//plot(Trend==1 and Trend[1]==-1,color = linecolor, style = circles, linewidth = 3,title="Trend")

plotarrow(Trend == 1 and Trend[1] == -1 ? Trend : na, title="Up Entry Arrow", colorup=lime, maxheight=60, minheight=50, transp=0)
plotarrow(Trend == -1 and Trend[1] == 1 ? Trend : na, title="Down Entry Arrow", colordown=red, maxheight=60, minheight=50, transp=0)

1 Ответ

1 голос
/ 12 марта 2020
//@version=4
////////////////////////////////////////////////////////////
//  Copyright by HPotter v1.0 09/03/2018
// Linear Regression Intercept is one of the indicators calculated by using the 
// Linear Regression technique. Linear regression indicates the value of the Y 
// (generally the price) when the value of X (the time series) is 0. Linear 
// Regression Intercept is used along with the Linear Regression Slope to create 
// the Linear Regression Line. The Linear Regression Intercept along with the Slope 
// creates the Regression line.
////////////////////////////////////////////////////////////
study(title="Line Regression Intercept", overlay=true)
Length = input(14, minval=1)
xSeria = input(title="Source", type=input.source, defval=close)
xX = Length * (Length - 1) * 0.5
xDivisor = xX * xX - Length * Length * (Length - 1) * (2 * Length - 1) / 6
xXY = 0.
for i = 0 to Length - 1 by 1
    xXY := xXY + i * xSeria[i]
    xXY
xSlope = (Length * xXY - xX * sum(xSeria, Length)) / xDivisor
xLRI = (sum(xSeria, Length) - xSlope * xX) / Length
plot(xLRI, color=color.blue, title="LRI")
//@version=4
//Author - Rajandran R
//www.marketcalls.in
study("Supertrend V1.0 - Buy or Sell Signal", overlay=true)

Factor = input(3, minval=1, maxval=100)
Pd = input(7, minval=1, maxval=100)


Up = hl2 - Factor * atr(Pd)
Dn = hl2 + Factor * atr(Pd)

TrendUp = Up
TrendUp := close[1] > TrendUp[1] ? max(Up, TrendUp[1]) : Up
TrendDown = Dn
TrendDown := close[1] < TrendDown[1] ? min(Dn, TrendDown[1]) : Dn

Trend = int(na)
Trend := close > TrendDown[1] ? 1 : close < TrendUp[1] ? -1 : nz(Trend[1], 1)
Tsl = Trend == 1 ? TrendUp : TrendDown

linecolor = Trend == 1 ? color.green : color.red

plot(Tsl, color=linecolor, style=plot.style_line, linewidth=2, title="SuperTrend")

plotshape(cross(close, Tsl) and close > Tsl, "Up Arrow", shape.triangleup, location.belowbar, color.green, 0, 0)
plotshape(cross(Tsl, close) and close < Tsl, "Down Arrow", shape.triangledown, location.abovebar, color.red, 0, 0)
//plot(Trend==1 and Trend[1]==-1,color = linecolor, style = circles, linewidth = 3,title="Trend")

plotarrow(Trend == 1 and Trend[1] == -1 ? Trend : na, title="Up Entry Arrow", colorup=color.lime, maxheight=60, minheight=50, transp=0)
plotarrow(Trend == -1 and Trend[1] == 1 ? Trend : na, title="Down Entry Arrow", colordown=color.red, maxheight=60, minheight=50, transp=0)

...