Edgoro
Compile error · Types and qualifiers

Pine Script: Cannot call operator + with string and float

Pine Script won't join text and numbers with +. Convert the number with str.tostring() to build label and alert text without the "operator +" error.

Pine Editor console · line 4
Cannot call "operator +" with argument "expr0"="Close: ". An argument of "literal string" type was used but a "series float" is expected.

Cause

+ can add two numbers or join two strings, but not mix them. "Close: " + close joins a string with a float.

Broken code

TradingView reports the error on line 4.

Pine Script v6
//@version=6
indicator("Close label", overlay = true)
if barstate.islast
    label.new(bar_index, high, "Close: " + close)

Fixed code

The same script, corrected for Pine Script v6. Paste it into the Pine Editor and save.

Pine Script v6
//@version=6
indicator("Close label", overlay = true)
if barstate.islast
    label.new(bar_index, high, "Close: " + str.tostring(close, format.mintick))

Why it works

str.tostring() converts the number to a string first, so both sides of + are strings and Pine joins them. format.mintick rounds to the symbol's tick size; a pattern such as "#.##" keeps two decimals, and format.percent and format.volume are also available.

Alert messages

The same applies to alert() messages built at runtime:

rsi = ta.rsi(close, 14)
if ta.crossover(rsi, 70)
    alert("RSI crossed 70: " + str.tostring(rsi, "#.0"), alert.freq_once_per_bar_close)

alertcondition() messages must be fixed strings; use placeholders such as {{ticker}} and {{close}} there instead of concatenation.

Questions

How do I concatenate a string and a number in Pine Script?

Convert the number first: "Close: " + str.tostring(close). Add a format as the second argument, such as format.mintick or "#.##", to control the decimals.

Why does the message say a "series float" is expected?

Because one side of + is a number, the compiler tries numeric addition and then reports the string as the argument that doesn't fit. The fix is the same either way: make both sides strings.

The scripts on this page are minimal examples written to show the error and its fix, not trading systems. Trading involves substantial risk of loss and is not suitable for every investor. Edgoro is a software tool, not a broker or financial adviser: nothing it produces is investment advice, and past or backtested performance does not guarantee future results.

Still getting an error?

Paste your script and the message into the free Pine Script error fixer: it explains what went wrong and returns a corrected v6 version. Or describe the indicator in plain English and let Edgoro write the code.