0

I am using version 5

I check whether indicator conditions are met, and if they are, I get a specific number - 1, 2 or 3.

I want to display these numbers under the candles.

I have this code, where I try to convert my numeric value to string with str.tostring().

finalCountText = str.tostring(finalCount)
plotchar(finalCount,title="",text=finalCountText,location=location.belowbar)

However, I am getting this error in console:

Cannot call 'plotchar' with argument 'text'='finalCountText'. An argument of 'series string' type was used but a 'const string' is expected

vitruvius
  • 15,740
  • 3
  • 16
  • 26
Emka
  • 1

2 Answers2

0

You cannot do that with the plot*() functions because your finalCountText won't be a constant, hence the error message.

You should use labels instead.

label.new(bar_index, low, finalCountText, yloc=yloc.belowbar)

I would also suggest you add max_labels_count=500 to your study/indicator/strategy call.

vitruvius
  • 15,740
  • 3
  • 16
  • 26
0

@vitruvius answer is the the preferred method IMHO, and I personally prefer it to the below solution, but if for some reason you prefer using plotshape() method instead of label you can set a condition inside the function. For example:

plotchar(finalCountText == "-1",title="",text="-1",location=location.belowbar)
plotchar(finalCountText ==  "1",title="",text="1" ,location=location.belowbar)
plotchar(finalCountText ==  "2",title="",text="2" ,location=location.belowbar)
plotchar(finalCountText ==  "3",title="",text="3" ,location=location.belowbar)

Again - label is much more flexible, and in most cases you won't need more than 500 of them, but if you need the plotshape() for any reason, that's the solution.

mr_statler
  • 1,913
  • 2
  • 3
  • 14