Search code examples
pine-scriptpine-script-v5

Pine Script v5 - How to format indicator's Status Line


I have built an indicator that renders a status line without any formatting. For example, 100M is displayed as "100000000". How can I format the status line so it is displayed as "100.0M"?

I tried entering it into ChatGPT and the answers caused more errors. Here's some of the output it provided ... nonsense:

indicator("Test Indicator", overlay=false)

annualRevenue = input(100000000, "Annual Revenue")
formattedRevenue = str.format("{0:.1f}M", annualRevenue / 1000000)

// Set indicator's title and subtitle
indicator_title = "Test Indicator"
indicator_subtitle = "Annual Revenue: " + formattedRevenue
study(title = indicator_title, shorttitle = indicator_title, overlay = false)
label.new(x=bar_index, y=na, text=indicator_subtitle, style=label.style_none)

Thanks for your help!


Solution

  • The status line has three sections (if all enabled). The first one is the indicator name, the second one is the inputs and the third one is the output values.

    You cannot format how the input values are displayed.

    For the output values, you can set your format to format.volume.

    //@version=5
    indicator("Test", overlay=true, format=format.volume)
    
    annualRevenue = input(100000000, "Annual Revenue")
    plot(annualRevenue)
    

    enter image description here