pine-scriptpine-script-v5pine-script-v4pine-editor

How do I use an "array" as a Function variable?


We assume a generic function such as: [a,b,c] = Function (float Var1, float Var2)

I want "Var1" to be an array of type float. How do I write the function?

Regards

(writing it as: array_new.float(Array, size) obviously does not work)...but you get the idea


Solution

  • For the array declaration/ type definition you have 2 options:

    array<float> myArray = array.new_float(3,na)
    
    float[] myArray2 = array.new_float(3,na)
    

    The same applies to function definitions:

    myFn(array<float> arr) =>
        array.get(arr, 0)
    
    myFn2(float[] arr) =>
        array.get(arr, 0)