Fix pine script code where I need to compare previous two prices with actual price

Job ID: 37600078

Budget: €8 – €30 EUR

I need to fix my code where I want compare two previous open prices with specific condition and actual open price candle with same condition. I am showing only part of the code which is not working. All variables are set correctly but I am not able to get open price information for xxOpen1 and xxOpen2 and then plot in label. I am getting study error. Compiling is without any error but overall study is not working on chart.

Here is my code:

openHistory = request.security(syminfo.tickerid, "15S", open, lookahead=barmerge.lookahead_on)
for i = 0 to 30
wt101Condition = wt101[i] > wt201[i] and wtDot[i] == 1 and (wt102[i] < 0 or wt202[i] < 0)

if (wt101Condition)
// Calculate historical xxPrice, xxOpen1, and xxOpen2 using an offset
xxPrice := open[i]
xxWT101 := wt101[i]
xxWT201 := wt201[i]
// Extract historical open prices using array indexing
xxOpen1 := openHistory[i - 1]
xxOpen2 := openHistory[i - 2]

// Set the flag to color the next XX
shouldColorNextXX := true

// Create or update the label for each bar
if (array.size(xxLabels) <= i)
array.push(xxLabels, label.new(x=bar_index - i, y=xxPrice, text="XPrice: " + str.tostring(xxPrice) + " Open1: " + str.tostring(xxOpen1) + " Open2: " + str.tostring(xxOpen2) + " WAVE" + str.tostring(xxWT101) + " WAVE" + str.tostring(xxWT201), style=label.style_label_lower_left, color=color.lime, textcolor=color.black, size=size.large))
else
label.set_xy(array.get(xxLabels, i), x=bar_index - i, y=xxPrice)
label.set_text(array.get(xxLabels, i), "XPrice: " + str.tostring(xxPrice) + " Open1: " + str.tostring(xxOpen1) + " Open2: " + str.tostring(xxOpen2) + " WAVE" + str.tostring(xxWT101) + " WAVE" + str.tostring(xxWT201))
Related categories: Pine Script Trading