简体   繁体   中英

Why is barssince not working in pine script v5?

I'm trying to check the last time rsi was over sold, but when i put in barssince(rsi < 30) the code is not blue, it's just white. Then when i save it comes back as

"Could not find function or function reference 'barssince'."

I read the language manual for v5 and i'm doing exactly what it says, i'm not sure what's going on here. Any ideas?

code example: ''' BarsSinceRsiOverSold = barssince(rsi < 30) '''

In Pine version 5, the namespace concept has been introduced as there existed too many functions in the Pinescript language library. Every built-in function has been grouped into different namespaces.

barssince is in the Technical Analysis category, so it is in the ta namespace. When you use a function in v5, you have to specify the namespace, the function name and these 2 are separated by a dot.

The proper use of barssince() in v5 is: ta.barssince() .

Anytime you have doubts about a function definition, start the on-screen help where you can search for either v4 or v5 function definitions. You can start the on-screen help by looking for a keyword which is usually displayed in blue color, hover your mouse over it and press Ctrl+click. If you just hover your mouse over a keyword, a pop-up help will appear but you cannot interact with that popup window.

Your use of RSI function has issues as that function requires two arguments. The RSI function is also in the Technical Analysis group so it also has the ta. namespace prefix.

Your example code should look like this:

BarsSinceRsiOverSold = ta.barssince(ta.rsi(close, 14) < 30)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM