TradingView
Lemrin
7 de May. de 2020 3:30

Barssince Context Test 

Bitcoin / US Dollar Perpetual Inverse Swap ContractBitMEX

Descripción

This 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.
Comentarios
PineCoders
This is due to a change introduced in Pine v4. The change and how to avoid its pitfalls are explained here in our FAQ. The FAQ entry also links to the relevant User Manual section:
pinecoders.com/faq_and_code/
Lemrin
@PineCoders, Thank you. Agreed, this can be worked around, but I hope there are plans to update the help documentation to reflect this new behavior for all affected functions. Like I said, it could be a very cool feature if it is intended, but as an easter egg I think it tends to go against the principle of least astonishment.

Edit referring to this one: tradingview.com/pine-script-reference/v4/ , specifically the description:

RETURNS
Number of bars since condition was true.

Perhaps rewrite to say something like it returns the number of bars since condition was true, ignoring those bars for which the function was not in context to execute.
Más