Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
712 views
in Technique[技术] by (71.8m points)

pine script - Duplicate values - Stateless Valuewhen attempt

I'm trying to accomplish a stateless Valuewhen function. However, I'm getting duplicate values and I can't seem to figure out why. I only need the unique values to use with line.new later

Obviously, the plot chars are only for Troubleshooting & debugging

SupPerf = (hlc3[2] <= hlc3[1] and hlc3[2] <= hlc3[3]) ? low[2] : na

float SupVal = na
float SupVal1 = na
for i = 1 to 200
    if (SupPerf[i])
        SupVal1 := SupPerf[i]
        break 

plotchar(SupPerf[0], "SupPerf0", "", location.top, size = size.tiny)
plotchar(SupPerf[1], "SupPerf1", "", location.top, size = size.tiny)
plotchar(SupPerf[2], "SupPerf2", "", location.top, size = size.tiny)
plotchar(SupPerf[3], "SupPerf3", "", location.top, size = size.tiny)
plotchar(SupPerf[5], "SupPerf4", "", location.top, size = size.tiny)
plotchar(SupPerf[6], "SupPerf5", "", location.top, size = size.tiny)
plotchar(SupPerf[7], "SupPerf6", "", location.top, size = size.tiny)
plotchar(SupPerf[8], "SupPerf7", "", location.top, size = size.tiny)

plotchar(SupVal1[0], "SupVal0", "", location.top, size = size.tiny)
plotchar(SupVal1[1], "SupVal1", "", location.top, size = size.tiny)
plotchar(SupVal1[2], "SupVal2", "", location.top, size = size.tiny)
plotchar(SupVal1[3], "SupVal3", "", location.top, size = size.tiny)
plotchar(SupVal1[4], "SupVal4", "", location.top, size = size.tiny)
plotchar(SupVal1[5], "SupVal5", "", location.top, size = size.tiny)
plotchar(SupVal1[6], "SupVal6", "", location.top, size = size.tiny)
plotchar(SupVal1[7], "SupVal7", "", location.top, size = size.tiny)
plotchar(SupVal1[8], "SupVal8", "", location.top, size = size.tiny)
plotchar(SupVal1[9], "SupVal9", "", location.top, size = size.tiny)
plotchar(SupVal1[10], "SupVal10", "", location.top, size = size.tiny)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Not sure exactly what your objective is, but no need for a for loop to reproduce your current logic. See method 2 in here:

//@version=4
study("", "", true)

// Method 1.
SupPerf = (hlc3[2] <= hlc3[1] and hlc3[2] <= hlc3[3]) ? low[2] : na
float SupVal = na
float SupVal1 = na
for i = 1 to 200
    if (SupPerf[i])
        SupVal1 := SupPerf[i]
        break 
plot(SupVal1)

// Method 2.
var float SupPerf2 = na
if (hlc3[2] <= hlc3[1] and hlc3[2] <= hlc3[3])
    SupPerf2 := low[2]
plot(SupPerf2[1], "SupPerf2", color.blue, 6, transp = 80)

// For validation
plotchar((hlc3[2] <= hlc3[1] and hlc3[2] <= hlc3[3]), "(hlc3[2] <= hlc3[1] and hlc3[2] <= hlc3[3])", "?", location.top, size = size.tiny)

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...