Reputation: 118271
I am writing a pine script code to plot some lines conditionally. I see pine script v5, plot() function has display argument, still I am getting an weird error. Any idea what it could be?
Code:
//@version=5
indicator(title="Gann Levels", shorttitle="GIL", overlay=false, timeframe="", timeframe_gaps=true)
from_previous_day_low = input.bool(title="Previous day low", defval=true)
from_previous_day_high = input.bool(title="Previous day high", defval=true)
[previous_day_high, previous_day_low] = request.security(syminfo.tickerid, "D", [high[1], low[1]])
sqrt_previous_day_low = math.round(math.sqrt(previous_day_low))
sqrt_previous_day_high = math.round(math.sqrt(previous_day_high))
display_supports() => from_previous_day_low ? display.none : display.all
display_resistances() => from_previous_day_high ? display.none : display.all
s1 = math.round(math.pow(sqrt_previous_day_high - 0.250, 2))
s2 = math.round(math.pow(sqrt_previous_day_high - 0.500, 2))
s3 = math.round(math.pow(sqrt_previous_day_high - 0.750, 2))
r1 = math.round(math.pow(sqrt_previous_day_low - 0.250, 2))
r2 = math.round(math.pow(sqrt_previous_day_low - 0.500, 2))
r3 = math.round(math.pow(sqrt_previous_day_low - 0.750, 2))
plot(series=s1, linewidth=2, color=color.new(#16F6DE, 10), display=display_supports())
plot(series=s2, linewidth=2, color=color.new(#16F6DE, 10), display=display_supports())
plot(series=s3, linewidth=2, color=color.new(#16F6DE, 10), display=display_supports())
plot(series=r1, linewidth=2, color=color.new(#16F6DE, 10), display=display_resistances())
plot(series=r2, linewidth=2, color=color.new(#16F6DE, 10), display=display_resistances())
plot(series=r3, linewidth=2, color=color.new(#16F6DE, 10), display=display_resistances())
Errors:
line 26: Invalid argument 'display' in 'plot' call. Possible values: [display.none, display.all];
line 27: Invalid argument 'display' in 'plot' call. Possible values: [display.none, display.all];
line 28: Invalid argument 'display' in 'plot' call. Possible values: [display.none, display.all];
line 31: Invalid argument 'display' in 'plot' call. Possible values: [display.none, display.all];
line 32: Invalid argument 'display' in 'plot' call. Possible values: [display.none, display.all];
line 33: Invalid argument 'display' in 'plot' call. Possible values: [display.none, display.all]
Upvotes: 2
Views: 459
Reputation: 21179
You should apply your condition to the series
argument of plot()
. The display
argument is whether to enable or disable the plot by default and I believe it must be a constant.
And you probably want to change the style to something like plot.style_circles
so your line won't be connected.
plot(from_previous_day_low ? s1 : na, linewidth=2, color=color.new(#16F6DE, 10), style=plot.style_circles)
plot(from_previous_day_low ? s2 : na, linewidth=2, color=color.new(#16F6DE, 10), style=plot.style_circles)
plot(from_previous_day_low ? s3 : na, linewidth=2, color=color.new(#16F6DE, 10), style=plot.style_circles)
plot(from_previous_day_high ? r1 : na, linewidth=2, color=color.new(#16F6DE, 10), style=plot.style_circles)
plot(from_previous_day_high ? r2 : na, linewidth=2, color=color.new(#16F6DE, 10), style=plot.style_circles)
plot(from_previous_day_high ? r3 : na, linewidth=2, color=color.new(#16F6DE, 10), style=plot.style_circles)
Upvotes: 2