''tostring' function in pine-script
I'm trying to create plot name based on input value. However getting error (in line#6). Below is my code. Thank you so much for your time and reply.
//@version=4
study(title="EMA", shorttitle="ema", overlay=true)
ema_len = input(50, title='Period')
EMA = ema(close, ema_len)
plot_name = 'EMA' + tostring(ema_len)
plot(EMA, title=plot_name)
Error message:
Add to Chart operation failed, reason: line 6: Cannot call 'plot' with 'title'=string. The argument should be of type: const string
Solution 1:[1]
Const strong means we can’t dynamically change a title. The settings menu isn’t setup to change with user input infront if your eyes. So we just have to choose a name for our plot.
Cheers.
Solution 2:[2]
delete line 5 and just do
plot(EMA, title='EMA')
in line 6
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 | Bjorgum |
| Solution 2 | jmoerdyk |
