is this User Defined Function using more memory/computing in PineScript v5?

21 Views Asked by At

I would like to understand if the Function as per the example below results in greater usage of memory/computing in Pine Script v5.

BASE CASE:

s_15 = ta.sma(close,15)
s_20 = ta.sma(close,20)
X1a =  s_15>s_20

s_100 = ta.sma(close,100)
s_120 = ta.sma(close,120)
X2a =   s_100>s_120

USING FUNCTION:

checkMas(i,j) =>
    s_i = ta.sma(close,i)
    s_j = ta.sma(close,j)
    X = s_i>s_j
    X

X1b = checkMas(15,20)
X2b = checkMas(100,120)

My question is whether Pine Script will update the object "s_i" every bar similarly to how it does with the object "s_15", or instead it is recalculating "s_i" entirely, from bar_index 0, on every bar.

The User Manual states that "Each instance of a function call in a script maintains its own, independent history" ... and that's where I get concerned that "s-i" and "s_j" are being completely recalculated from scratch on every bar.

0

There are 0 best solutions below