1

I have so far found two quite severe bugs in Pine Script v5. And here is another one.

This is not really a question, rather, I think people can benefit from this if they encounter such behavior too, hopefully I can save them some time.

So. Pine Script is supposed to accept float and int in place of bool, converting them to bool based on common programming language logic (0 = false, anything else = true). Any sane programming language is also supposed to store converted variables as their end product. Like, if I have assigned 2 to a bool variable, it should store "true", not "2".

Not so in Pine Script... Here is an example:

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © AVAndronov

// CONSTS

OVERLAY = false
BUG_CONST = 2.5

//@version=5
indicator("My script", overlay = OVERLAY)

bool bug_input = input.bool(BUG_CONST, "Display Close 1")
bool bug_free_input = input.bool(BUG_CONST ? true : false, "Display Close 2")
bool bug_var = BUG_CONST

//this one will bug out
plot(bug_input ? close : 0, color = color.red)
//these two will work
plot(bug_free_input ? -close : 0, color = color.green)
plot(BUG_CONST ? close : 0, color = color.purple)
if barstate.islast
    label.new(bar_index, 0, 
     str.tostring(bug_input)
     +"\n"+str.tostring(bug_input == true ? "true" : "not == true")
     +"\n"+str.tostring(bug_input == false ? "== false" : "not == false")
     +"\n"+str.tostring(bug_input ? "? true" : ": false") 
     +"\n"+str.tostring(bug_var)
     +"\n"+str.tostring(bug_var == true ? "true" : "not == true")
     +"\n"+str.tostring(bug_var == false ? "false" : "not == false")
     +"\n"+str.tostring(bug_var ? "? true" : ": false") 
     +"\n"+str.tostring(bug_free_input) )

The result produced will be:

1. In script inputs window, both checks will be checked.

2. Flat red line, price displayed on green and purple lines.

3. Label:
false 
not == true
== false
: false
2.5
not == true
not == false
? true
true

What we can observe here is this:

1. When you assign non-bool to a bool, it doesn't actually store a bool. Instead, it stores whatever you have assigned!

You can see I am using "str.tostring" on "bug_var", a bool variable of type const bool (can be verified by hovering over it in the editor). But it displays 2.5! So it actually stores the float inside. Not a bool.

2. When you assign non-bool to a bool, it behaves like that value sometimes, and sometimes it doesn't

You can see I call "bug_var == true" and it results in false, because bug_var is not equal to true, it's actually equal to 2.5. == false also results in false, it's not equal to false either! However, when I later do bug_var ? :, it results in true, because bug_var evaluates to true when put in place of a bool.

So it's a bool that isn't equal to true, isn't equal to false, but evaluates to true. What a unique bool....

3. When you assign a non-bool to an input bool, it misbehaves in a different manner.

The input interface of tradingview website thinks it is true, however, the code thinks it is false. So when you check this input, it will be false for all intents and purposes, it will be == false, it will evalutate to false in ?: conditionals.

4. At least if you do "FLOAT ? true : false" or "bool(FLOAT)" it will work properly

Note however that it will NOT work if you do FLOAT ? 1 : 0, as that will produce same result as above (it will be considered false everywhere if you assign this to an input bool, and it will be true in checks and false otherwise if you assign this to a variable bool).

Closing words.

Hopefully I'll save some time for other people as I've spend literally an hour thinking WTF is wrong with my code until I figured out its a language bug. Thing is, I don't understand, does TradingView even care?

So far as a novice programmer to Pine Script I've found three severe bugs, two of which can easilly cause dozens of programming hours lost debugging something that isn't even programmer's fault.

  1. This one
  2. I found out insane TradingView bug with timeframe.in_seconds()... what to do?
  3. Pine Script "script has too many local scopes, the limit is 500" - What is / counts as a local scope?

Once I have been offered to contact them via support, but they don't provide answers to non-paid members. Do they even care? Does anyone know how to get an answer from them without paying them money?...

  • Thank you very much for sharing! Pine script tends to have bugs. I had reported 3, 2 of which were fixed in a matter of weeks by the 3rd one I was let down without an explanation. Pine script is *mainly* used by traders that don't go that deep in programming so that such bugs would be revealed soon. So with a primary trader user base it can stay longer buggy that's unfortunate but must be accepted. Actually some programmers prefer other software solutions or extract data from tradingview and do everything in python though that has other drawbacks... You could also try their reddit page. – elod008 Oct 22 '22 at 08:14
  • @elod008 are you a paid member? Did they respond to you? With python, I assume, you can't draaw on top of charts, so you could only analyze data and produce some results, like, strategy backtest data or current data, historic data wouldn't be convenient to reference? – Alexei Andronov Oct 23 '22 at 07:09
  • Yes I am and they respond to my requests in a matter of hours and have confirmed and solved the reported bugs in just weeks so I cannot complain about it. After a couple of months in pine script I still often feel some pain scripting because of its serious limitations as a language, poor documentation concerning advanced methodology but I am a satisfied paid member. Yeah, those are the drawbacks of turning to python. Advantages: you can analyze data freely (NOT bound by pine script), automate your trading that TV cannot do. As for me I'd rather fight pine script. – elod008 Oct 23 '22 at 10:11
  • just wanna say.. It must be named painScript. – trickster77777 May 01 '23 at 17:41

2 Answers2

0

Definitely looks like a bug. I relayed it to the Pine team.

beeholder
  • 1,444
  • 1
  • 3
  • 6
  • beeholder thank you very much! Can you please commen when they reply? – Alexei Andronov Oct 24 '22 at 11:17
  • They created a task for further investigation and potential fix, but there's no ETA at the moment. I'll let you know if something changes regarding this. Note that due to the fact that this change might affect/break existing scripts, the fix is not guaranteed for the current version of Pine. It will depend on how drastic the changes are. – beeholder Oct 24 '22 at 12:22
0

I'm being told that the fix for this behavior has been released.

beeholder
  • 1,444
  • 1
  • 3
  • 6