1

I want to compare an array like this:

string_array = array.from("A", "B", "C", ...)
float_1_array = array.from(1.5, 2.5, 3.5, ...)
float_2_array = array.from(4.5, 5.5, 6.5, ...)

For a result meaning like this (following is not an actual code):

if array.get(float_1_array, 0) > 1 and
array.get(float_2_array, 0) > 4 ?
array.get(string_array, 0) : ""

string_result = "A"

How to achieve such a result using loop to display the string in a Table? Or is it possible in Pinescript?

1 Answer 1

2

Find the smallest array and set your loop based on that.

string_array = array.from("A", "B", "C")
float_1_array = array.from(1.5, 2.5, 3.5)
float_2_array = array.from(4.5, 5.5, 6.5)

len_string = array.size(string_array)
len_float_1 = array.size(float_1_array)
len_float_2 = array.size(float_2_array)

min_len = math.min(len_string, len_float_1, len_float_2)

if (barstate.islast)
    if (min_len > 0)
        for i = 0 to min_len - 1
            obj_string = array.get(string_array, i)
            obj_float_1 = array.get(float_1_array, i)
            obj_float_2 = array.get(float_2_array, i)
            
            if ((obj_float_1 > 1) and (obj_float_2 > 4) and (obj_string == "A"))
                label.new(bar_index, high, "Found")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.