error-handlingcompiler-errorspine-scriptpine-script-v5indicator

How do I solve this error "An argument of 'series float' type was used but a 'input float' is expected" in Pine Script Version 5


I'm writing a Pine Script Indicator and I'm getting 4 errors and one warning after compiling:

  1. Cannot call 'hline' with argument 'price'='upperBound'. An argument of 'series float' type was used but a 'input float' is expected
  2. Cannot call 'hline' with argument 'price'='lowerBound'. An argument of 'series float' type was used but a 'input float' is expected
  3. Cannot call 'fill' with argument 'hline1'='upperBound'. An argument of 'series float' type was used but a 'hline' is expected
  4. Cannot call 'fill' with argument 'hline2'='lowerBound'. An argument of 'series float' type was used but a 'hline' is expected

(1) warning: The transp argument is deprecated. We recommend using color.new() or color.rgb() functions to specify the transparency of the plots instead. Additionally, note that transp has no effect in plots where the color is calculated at runtime

This is my Pine Script Code:

'''
//@version=5

// Define the number of bars to be analyzed for finding clusters
clusterLength = input(title="Cluster Length", defval=100)

// Define the number of standard deviations from the mean to determine the cluster
stdDev = input(title="Number of Standard Deviations", defval=2.0)

// Calculate the mean and standard deviation for the defined number of bars
mean = ta.sma(close, clusterLength)
stddev = ta.stdev(close, clusterLength)

// Plot the upper and lower bounds of the clusters as horizontal lines
upperBound = mean + stddev * stdDev
lowerBound = mean - stddev * stdDev
hline(upperBound, color=color.red, linewidth=2, title="Upper Bound")
hline(lowerBound, color=color.blue, linewidth=2, title="Lower Bound")

// Fill the area between the bounds to visually represent the cluster
fill(upperBound, lowerBound, color=color.gray, transp=70)
'''

I would appreciate if you provide a solution. Thanks in advance


Solution

  • You cannot use dynamic values in hline().

    You can try using plot() or line instead.

    And you should be calling the fill() function with plots or hlines. upperBound and lowerBound are just variables.

    See the signature below:

    fill(hline1, hline2, color, title, editable, fillgaps, display) → void
    fill(plot1, plot2, color, title, editable, show_last, fillgaps, display) → void