PineScript v6: Conditional Expressions from Libraries
I thought it appropriate to make some quick notes on calling conditional expressions from PineScript v6 libraries, seeing as I have recently updated all of my libraries to v6 and most of my function exports output booleans or values that are ultimately derived from other functions that output booleans.
When calling functions in v6 that output booleans or values derived from other functions that output booleans, it is best practice to first declare the function return globally before you use said output as input for anything else.
For example, instead of calling my swing low and uptrend functions (which both return booleans) as part of a broader conditional expression:
//@version=6
indicator('Example Conditional Expression 1')
import theEccentricTrader/PubLibSwing/3 as sw
import theEccentricTrader/PubLibTrend/2 as tr
uptrend = sw.sl() and tr.ut()
plotshape(uptrend)
I would first declare the function returns as global variables and then call the broader conditional expression using said variables:
//@version=6
indicator('Example Conditional Expression 2')
import theEccentricTrader/PubLibSwing/3 as sw
import theEccentricTrader/PubLibTrend/2 as tr
sl = sw.sl()
ut = tr.ut()
uptrend = sl and ut
plotshape(uptrend)
This demonstrates different behaviour from v5, where you could combine functions that output booleans in conditional expressions without error or warning.
The same also applies to functions that output values derived from other functions that output booleans. In the example below, my swing low price and bar index functions output float and integer values, respectively, but these values are derived from the swing low function, which is a function that returns a boolean. So these return values should also be first declared globally for later use, just like the swing low and uptrend functions:
//@version=6
indicator('Example Conditional Expression 3', overlay = true)
import theEccentricTrader/PubLibSwing/3 as sw
import theEccentricTrader/PubLibTrend/2 as tr
sl = sw.sl()
ut = tr.ut()
slp_0 = sw.slp(0)
slpbi_0 = sw.slpbi(0)
slp_1 = sw.slp(1)
slpbi_1 = sw.slpbi(1)
if sl and ut
line.new(slpbi_1, slp_1, slpbi_0, slp_0, color = color.green)
Libraries
$REALM best integrated metaverse. Boutta to Big Papi PUMPTalk about a mobile first metaverse that ppl everywhere can onboard plus being one of the top 5 apps (category-wide) with high user RETENTION. No pump and dump here, only GROWTH. This will be huge, with already in place $SAND and $MANA integrations (only I know but trust me bro). It WILL be $1 maybe even $5. This is ranked HOT across the board. Constant constant constant CONSTANT development makes this attractive for everybody who takes a look. Let alone the fact that the metropolis is SOLD OUT. Imagine.