我如何将此逻辑转换为 pinescript v5?

How do i convert this logic to pinescript v5?

我需要一些帮助将此逻辑转换为 pinescript v4 或 v5,因为我在第 05 - 07 行不断收到以下错误,逻辑说未声明的标识符 TrendUpTrendDownTrendDef

01 Factor=input(1, minval=1,maxval = 000,)

02 Pd=input(1, minval=1,maxval = 100)

03 Up=hl2-(Factor*atr(Pd))

04 Dn=hl2+(Factor*atr(Pd))

05 TrendUp=close[1]>TrendUp[1]? max(Up,TrendUp[1]) : Up

06 TrendDown=close[1]<TrendDown[1]? min(Dn,TrendDown[1]) : Dn

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

08 plotarrow(Trend == 1 and Trend[1] == -1 ? Trend : na, title="Up Arrow", colorup=color.new(color.lime, 85), maxheight=200, minheight=50)

09 plotarrow(Trend == -1 and Trend[1] == 1 ? Trend : na, title="Down Arrow", colordown=color.new(color.red, 85), maxheight=200, minheight=50)

非常感谢! :)

查看修改后的代码...

//@version = 4
study("TREND")
Factor=input(1, minval=1,maxval = 000)

Pd=input(1, minval=1,maxval = 100)

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

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


float TrendUp = 0.0, float TrendDown = 0.0, float Trend = 0.0

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],0)

plotarrow(Trend == 1 and Trend[1] == -1 ? Trend : na, title="Up Arrow", colorup=color.new(color.lime, 85), maxheight=200, minheight=50)

plotarrow(Trend == -1 and Trend[1] == 1 ? Trend : na, title="Down Arrow", colordown=color.new(color.red, 85), maxheight=200, minheight=50)

你需要一个Assignment Operator