I have a simple user input (string) where the 1st char is a number. Through substring and tonumber I convert this into a float. I plot the float on a chart to verify the user input changes the plotted number. I then make numbers part of a group (bool). The group(s) containing the number selected by the user should translate to true while other groups remain false. I plot a shape on the chart to verify the true/false outcome but every group seems to translate to true.
//@version=5
strategy("My strategy", overlay=true)
i1 = "1 - Option 1"
i2 = "2 - Option 2"
i3 = "3 - Option 3"
i4 = "4 - Option 4"
i5 = "5 - Option 5"
i6 = "6 - Option 6"
i7 = "7 - Option 7"
input = input.string(i3, title = "Make a choice", options = [i1, i2, i3, i4, i5, i6, i7])
// Get the number from the user input
inputNr = str.tonumber(str.substring(input, 0, 1))
// Test the input number and plot it on the chart
plot(inputNr * 1000, "Number") // The number plots correct (so far so good)
// Make the numbers part of a group.
// The group(s) containing the numbers should become true while other groups should become false, all based on the user input
group1 = inputNr == 5 or 6 or 7
group2 = inputNr == 1 or 2 or 3 or 4
group3 = inputNr == 3 or 4 or 5
group4 = inputNr == 6 or 7
// Test if a group is true by plotting a shape
// Here I get stuck... Every group, regardless of the user input gives a true
// My expected outcome was that if I sellect i4 from the list that only group2 & group3 would return true while others become false
plotshape(group1, location = location.top, style = shape.arrowdown)
I verified the data types (float & bool). The number plots correctly, the group while boolean does plot but the outcome is not what I expected. I expected when choosing input 4 that only the groups containing nr 4 (group 2 & group 3) would become true while others remain false.
You should try :
group1 = (inputNr == 5) or (inputNr == 6) or (inputNr == 7)
group2 = (inputNr == 1) or (inputNr == 2) or (inputNr == 3) or (inputNr == 4)
group3 = (inputNr == 3) or (inputNr == 4) or (inputNr == 5)
group4 = (inputNr == 6) or (inputNr == 7)