0

I was wondering if it is possible to have more that one outputs in the pinescript library? For example is the following code valid?

export sorting_float(float[] Value, int[] BarIndex) => //{
    var NewBarInd = array.new_int()
    ValueSorted = array.copy(Value)
    sortedLowsIndices = array.sort_indices(Value) 
    array.sort(ValueSorted, order.ascending)
    Size = array.size(BarIndex)
    if Size>0
        for i = 0 to Size-1
            array.push(NewBarInd,array.get(BarIndex,array.get(sortedLowsIndices,i)))
    ValueSorted, NewBarInd
    

where ValueSorted, NewBarInd are supposed to be outputs...

Also if the above situation is resolved, how should I get the outputs in the main code? I see that the following code gives me error:

float[] output_1, int[] ouput_2 = mylib.sorting_float(Input_1, Input_2)

sey eeet
  • 229
  • 2
  • 8

1 Answers1

0

Functions can return a tuple by using []:

export sorting_float(float[] Value, int[] BarIndex) => //{
    var NewBarInd = array.new_int()
    ValueSorted = array.copy(Value)
    sortedLowsIndices = array.sort_indices(Value) 
    array.sort(ValueSorted, order.ascending)
    Size = array.size(BarIndex)
    if Size>0
        for i = 0 to Size-1
            array.push(NewBarInd,array.get(BarIndex,array.get(sortedLowsIndices,i)))
    [ValueSorted, NewBarInd]
    

Then you can call the function and receive a tuple using the same method:

[output_1, ouput_2] = mylib.sorting_float(Input_1, Input_2)
mr_statler
  • 1,913
  • 2
  • 3
  • 14