'Show input value in title

I would like to show input value in plot title, my codes as below but it does not work

ma1 = input.int(5, 'MA 1', minval=1)

plot(ta.sma(source_ma, ma1), linewidth=1, color=color.new(#d1d4dc, 0), title='MA 1' + str.tostring(ma1))

Thank you in advance



Solution 1:[1]

Not a perfect solution, but there is an alternative for accomplishing what you want - you'll have to draw your own lines.

For example:

//@version=5
indicator("My script", max_lines_count=500)

ma1 = input.int(5, 'MA 1', minval=1)
sma = ta.sma(close, ma1)

line.new(x1=bar_index[1], y1=sma[1], x2=bar_index, y2=sma)

if barstate.islastconfirmedhistory
    label.new(bar_index, na, text='MA 1' + str.tostring(ma1), color=color.new(#d1d4dc, 0), style=label.style_label_down, yloc=yloc.abovebar)

There are some limitations as mentioned in the documents.

Solution 2:[2]

You cannot do that.

The title argument of plot() expects a const string, which means its value must be known at compile time which is not the case here.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mr_statler
Solution 2 vitruvius