Search code examples
pine-scriptpine-script-v5

How to plot a value in the indicator status line when a condition is met and don't plot anything when the condition is not met?


I'd like to plot the value of RSW_band_cross_final variable in the indicator status line if it equals to 1 and don't plot anything if it equals to 0, instead of seeing the value 0.00 in the status line. Is it even possible? Or is there any workaround? Thank you.

RSW_positive_band_cross = RSW >= band
RSW_negative_band_cross = RSW <= -band

Conversion from bool to int:

int RSW_band_cross_final = na 
if RSW_positive_band_cross == true or RSW_negative_band_cross == true
    RSW_band_cross_final := 1
else
    RSW_band_cross_final := 0

The following plot line returns an error: "Cannot call 'operator ?:' with argument 'expr0'='call 'operator ==' (series bool)'. An argument of 'series bool' type was used but a 'const bool' is expected." in the "display = RSW_band_cross_final == 1" part of the line.

plot(RSW_band_cross_final, title = "Relative Strength / Weakness Status Line Value", color = RSW_positive_band_cross == true ? color.new(#00d99f, 0) : RSW_negative_band_cross == true ? color.new(#ff004d, 0) : na, editable = false, display = RSW_band_cross_final == 1 ? display.status_line : display.none)

EDIT: Based on the provided answer it seems that it's not possible to do.

Possible "workarounds" are:

  1. Return na if the condition is false, instead of a 0, as Mario pointed out. This way there would be a Ø character in the indicator status line which takes less space than 0.00 (or whatever precision does the script use).
  2. Keep returning 0 if the condition is false. This way there would be 0.00 in the indicator status line, but it's possible to change the text color to match the chart background, so that it would be almost invisible (the color of the Ø character (na value) cannot be changed).

Solution

  • You can't change status line to on or off while the script is running.
    That is the reason of the error message and it is asking for a const bool instead.

    In the case you want to know what a const value is, look at this link.

    Instead of using the value zero you could use na,
    but it still would show something in the status line.