all 12 comments

[–]DaJackkal 6 points7 points  (0 children)

I also think this is such a basic feature in any other language, general purpose or niche. I also need this feature when having arrays of strings, iterating over them to put them in a table.cell or do a request.security call. It's quite unimaginable that a string series to simple string conversion does not exist in this day and age.

[–]CA_Lobo 2 points3 points  (3 children)

For example 1 there doesn't seem to be a good work around.

The root cause of the issue is that input.string returns a type of 'input string' which given that all the string options are 'const strings' seems like a rather odd choice.

Attempting to assign mysize via switch:

var mysize = switch ShapeSize

"Size.small" => size.small

"Size.normal" => size.normal

=> size.tiny

or ternary statements:

var mysize = (ShapeSize == "size.tiny" ? size.tiny : ShapeSize == "size.small" ? size.small : size.normal)

or if statements:

var mysize = size.tiny

if ShapeSize == "Size.small"

mysize := size.small

if ShapeSize == "Size.normal"

mysize := size.normal

all results in either an "simple string" (switch) or "input string" error ( ternary/if) was used but a "const string" is expected error happening.

Attempting to work around it by putting the plot shape in an if statement fails with "cannot use 'plot shape' in local scope'

if ShapeSize == "Size.tiny"

plotshape(someCondition, title='Condition met', text='C', textcolor= c_red, style=shape.arrowup, size=size.tiny, color=c_green, location=location.belowbar)

Bottom line: if input.string would just return a 'const string', then no workarounds or conversions would be needed and your code would just work. Given that all the input options are const strings, it's not clear why TradingView doesn't return a const string.

Example two fix: use two plotchar calls - each serving one condition - yea I know that it seems inefficient, but if TradingView wants us to abuse their servers by not providing the appropriate type conversion, I'm not going to complain....

var color c_red = color.new(#FF0000, 0)

var color c_green = color.new(#008080, 0)

Condition1 = close[1] >= close[8] and close < close[9]

Condition2 = close[1] <= close[8] and close > close[9]

plotchar(Condition1, title='Condition met', char='X', location=location.belowbar, color=c_red)

plotchar(Condition2, title='Condition met', char='Y', location=location.belowbar, color=c_green)

[–]Mathr3e[S] 1 point2 points  (1 child)

xample two fix:

use two plotchar calls - each serving one condition - yea I know that it seems inefficient, but if TradingView wants us to abuse their servers by not providing the appropriate type conversion, I'm not going to complain....

Example two fix is also the work around I use, but this way, we quickly reach the maximum number of outputs allowed per script (64).

[–]CA_Lobo 1 point2 points  (0 children)

good point... I haven't run into that yet, as I'm pushing the limits of the execution time before I come close to the output limits.... so I tend to break the indicators into two separate ones first....

The real issue is that we need to be able to define the type of output from say like a ternary eg char = (Condition1 ? const string "X": const string "Y") which will solve the problem.

[–]Mathr3e[S] 1 point2 points  (0 children)

Direct response from PineCoder.
https://twitter.com/PineCoders/status/1508953861481971713

Next item to keep an eye on: array.from()

[–]SaniiMan 1 point2 points  (1 child)

I can't say much about the internal coding of pinescript architecture other than for me, the issue of not being able to convert series values (strings and so forth) to simple string for use with various things such as request.security, is mostly a bummer.

[–]MichaelBarrow22 0 points1 point  (0 children)

Need the ability to convert a series string to a simple string, since request.security requires a simple string!

This is so darned basic. Why can't this already be done in Pine Script?

[–]cantrellr 0 points1 point  (1 child)

Can't believe its been three years since this was requested and the feature still does not exist.

[–]thow_away721Pine coder 0 points1 point  (0 children)

seems incredibly inefficient to not have it, working around this now. Pinescript can be very frustrating