I would please like some help to translate this logic to pinescript v4 or v5 as i keep on getting the following errors on line 05 - 07 with the logic saying undeclared identifiers TrendUp
, TrendDown
and TrendDef
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)
Much Thanks in advance! :)
Check out this modified code...
//@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)