pine-scriptpine-script-v5

Conditional string concatenation in Pinescript


I'm writing a message for the bot and ideally I'd like to use ternary operator to include or not a few commands in the message, which is a string. But Pinescript seems not to like that, like Javascrit for example. Is there any working syntax for this or shall I duplicate the message for the different conditions?

bool flag = true
mystring = 'alfa'+' bravo' flag ? + ' charlie' : + ' delta'

enter image description here

enter image description here


Solution

  • bool flag = true
    mystring = 'alfa'+' bravo' + (flag ? ' charlie' : ' delta')
    

    This will add 'charlie' if flag is true and 'delta' if flag is false