pine-scriptpine-script-v5

PineScript Error: An argument of 'series string' was used but 'const string' was expected


I tried to make a script to add text underneath a Japanese trading candle.

There are 3 possibilities, but the plot shape is giving me trouble.

Can you help me optimise this script so I can learn a bit more?

I searched and read that IF statements aren't the most simple/obvious parts in Pine Script.

//@version=5
indicator("AH", overlay=true)

string textarrow = "" bool compile = false

Avalement = open[1] > close[1] and open < close and open <= close[1] and close > open[1] Avalementplus = Avalement and high[1] < close and low[1] > open Baisse2 = open[2] > close[2] and open[2] > open[1] and close[1] < close[2]

if Avalement and not Avalementplus and not Baisse2
textarrow := "AH*" 
compile := Avalement 
else if Avalement and Baisse2 and not Avalementplus 
textarrow := "AH**" 
compile := Avalement and Baisse2 
else if Avalementplus and not Baisse2 
textarrow := "AH***" 
compile := Avalementplus

plotshape(compile, title="Long", location=location.belowbar, style=shape.arrowup, color=color.green, textcolor=color.green, text=textarrow)


I tried to find a solution by going through the web, but without success. The code keeps on giving an error:

Cannot call 'plotshape' with argument 'text'='call 'str.tostring' (series string)'. An argument of 'series string' type was used but a 'const string' is expected.


Solution

  • You cannot use dynamic strings with plot*() functions. As the error message tells you, they expect a const.

    You can use labels instead.

    if (compile)
        label.new(bar_index, high, textarrow, yloc=yloc.belowbar, style=label.style_arrowup, color=color.green, textcolor=color.black)