Reputation: 17
I'm trying to create an indicator that changes its hline value based on time frame. But I can't figure out why it's not working. Please help.
//@version=5
indicator(title="my indicator", precision=4)
obLvl1_Line = 0.02
obLvl2_Line = 0.04
if timeframe.period == "D"
obLvl1_Line = 0.02
obLvl2_Line = 0.04
if timeframe.period == "240"
obLvl1_Line = 0.006
obLvl2_Line = 0.010
if timeframe.period == "60"
obLvl1_Line = 0.0030
obLvl2_Line = 0.0040
obLvl1_fill = hline(obLvl1_Line, color=color.new(#00bcd4, 50), linestyle=hline.style_dotted, linewidth=1)
obLvl2_fill = hline(obLvl2_Line, color=color.new(color.green, 100), linestyle=hline.style_solid, linewidth=2)
fill(obLvl1_fill, obLvl2_fill, color=color.new(#00bcd4, 94), title="OverBought BG")
plot(obLvl1_Line)
Upvotes: 0
Views: 609
Reputation: 1094
The operator :=
must be used to give a new value to a variable. Hence, every variable reassignment under an if block should use :=
.
if timeframe.period == "D"
obLvl1_Line := 0.02
obLvl2_Line := 0.04
if timeframe.period == "240"
obLvl1_Line := 0.006
obLvl2_Line := 0.010
if timeframe.period == "60"
obLvl1_Line := 0.0030
obLvl2_Line := 0.0040
Upvotes: 1