How to declare a multi line string on pine script

169 Views Asked by At

I need to provide a default value for an input.textarea() which is a long multi line string containing code.

I'm aware that I can use this approach to break lines

text = "line 1\nline2\n..."

And even combine it with this to do line wrapping for better readability

text = 'line 1\
       line2...'

Using the \ character.

But it'd be much better if there was a "start and end multi line escape codes".

For example if that was ''' then it would only be a matter of doing:

text = '''line 1
       line 2
       line 3'''

Many languages offer this and it makes it much easier when the text requires to be copy pasted from/to the code for further editing externally.

1

There are 1 best solutions below

3
e2e4 On

There is no such function, unfortunately. In the code you have to explicitly declare a new line with escape+n - \n.

//@version=5
indicator("My script")
mystring = "line1 
           \nline2 
           \nline3"
i = input.text_area(mystring, "")
plot(close, display = display.none)

enter image description here However, if you manually type the multi-line string in the input field, script will recognize any new line automatically.

Multiple lines will still be combined into one line if you don't put \n. In case you put a breaker and then use a space before the character, it will be included in the result:

mystring = "line1\n
         line2\n
         line3"

enter image description here

You can also use a oneliner which will result in a multi-line string because of the breakers.

mystring = "line1\nline2\nline3"