Rodrigo
Rodrigo

Reputation: 15

How do I fix "Cannot call plot with argument" error

I'm new to pinescript coding and I'm writing a script on the ssl channel and I want to plot a green line at the top of the bars whenever the uptrend ssl is above the downtrend ssl and vice versa but I keep getting some errors.

Here is the code:

1. period = input(title="Period", defval=10)
2. len = input(title="Period", defval=10)
3. smaHigh=sma(high, len) 
4. smaLow=sma(low, len) 
5. Hlv = 0
6. Hlv := close > smaHigh ? 1 : close < smaLow ? -1 : Hlv[1] 
7. sslDown = Hlv < 0 ? smaHigh : smaLow 
8. sslUp = Hlv < 0 ? smaLow : smaHigh  
9.
10. uptrend = sslUp > sslDown
11. downtrend = sslUp < sslDown
12.
13. plot(uptrend, color=color.green, linestyle=hline.style_dashed, linewidth = 1)
14. plot(downtrend, color=color.red, linestyle=hline.style_dashed, linewidth = 1)

And this is the error message I'm getting.

Line 13: Type mismatch at argument 'series': expected series[float] but got series[bool] 
Line 13: Cannot call 'plot' with arguments (series[bool], color = const color, linestyle = const integer, linewidth = literal integer)

Help me please guys. Thanks a lot.

Upvotes: 1

Views: 1728

Answers (1)

AnyDozer
AnyDozer

Reputation: 2568

Fixed errors in the function plot

//@version=4
study("Help (SSL)", overlay=true)
period = input(title="Period", defval=10)
len = input(title="Period", defval=10)
smaHigh=sma(high, len) 
smaLow=sma(low, len) 
Hlv = 0
Hlv := close > smaHigh ? 1 : close < smaLow ? -1 : Hlv[1] 
sslDown = Hlv < 0 ? smaHigh : smaLow 
sslUp = Hlv < 0 ? smaLow : smaHigh  

uptrend = sslUp > sslDown
downtrend = sslUp < sslDown

plot(uptrend ? sslDown : na, color=color.green, style=plot.style_linebr, linewidth = 1)
plot(downtrend ? sslDown : na, color=color.red, style=plot.style_linebr, linewidth = 1)

// plot(sslUp, color=color.green, style=plot.style_linebr, linewidth = 1)
// plot(sslDown, color=color.red, style=plot.style_linebr, linewidth = 1)

enter image description here

Upvotes: 1

Related Questions