Search code examples
pine-scriptpine-script-v5

How to add .(dot) or space or shorten volume label into 1K/1M/1B/1T in pine-script?


When I got a basic number of volume output 1000000000 in label.

  • How to convert it into 1.000.000.000 or 1 000 000 000 or 1.000M
  • What function() can I use to convert volume output?

Solution

  • You can use the format.volume formatting option with the str.tostring() function.

    //@version=5
    indicator("My script", overlay=true)
    
    if barstate.islast
        label.new(bar_index, high, str.tostring(1500000, format.volume))
    

    enter image description here