Barssince Context TestThis is just published for visibility as a public service until the Pine devs are able to fix or document this behavior. The barssince() function returns different values when inside a conditional context. As long as it can be documented (and relied upon), this could be a pretty cool feature, but right now this is now how I read the help documentation to describe the function's intended behavior.
Anyway, in the script you'll see that test and test2 agree on red bars, but on green bars test gets a much lower value, which was pretty shocking to me until I traced down this particular cause within my larger script.
Bug
Function call bugThis is a code to showcase a function call bug in PineScript.
Problem description:
When a function is called from inside of if-then scope, this function may return an invalid result.
Code description:
Two identical code pieces are used to perform simple calculation. The only difference is that one piece has a part of its code wrapped into a function.
Expected result:
All green and red crosses should appear on the same candles. These crosses are calculated by identical code.
Actual result:
Some red crosses appear on the candles they should not appear on.
[RESEARCH] Percentrank BugI found a bug with built-in percentrank function. Sometimes it gives unexpected and incorrect results. You can see a one of them on the chart.
ALL scripts which use percentrank function are affected. No matter which version they use, no matter who is their author - ALL scripts which use this built-in function can work incorrectly.
If you want to avoid this bug use _percentrank function (the "shim" ) - you can find it in the script.
NOTE: Don't push on TradingView Support or Pine Core Team because they already know about this issue and work on the fix. I publish it to warn you.