Pine Script code fix
Budget: €8 – €30 EUR
I need to fix variables xxOpen1 and xxOpen2 where I need to get for these two variables open prices of candles which have met condition wt101Condition. Variable xxPrice is working fine because it is printing exact price of candle where label is printed but when I want historical prices for xxOpen1 and xxOpen2 I am not able to get it correctly.
Here is my main part of the code:
lowerPrice() => math.min(open, close)
// Function to get higher of open or close price
higherPrice() => math.max(open, close)
barColor := na
var label[] xxLabels = array.new_label(na)
var float xxOpen1 = na
var float xxOpen2 = na
var int[] conditionIndexes = array.new_int(na)
openHistory = request.security(syminfo.tickerid, "", open, lookahead=barmerge.lookahead_on)
for i = 0 to 30
wt101Condition = wt101[i] > wt201[i] and wtDot[i] == 1 and (wt101[i] < 0 or wt201[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))
Here is my main part of the code:
lowerPrice() => math.min(open, close)
// Function to get higher of open or close price
higherPrice() => math.max(open, close)
barColor := na
var label[] xxLabels = array.new_label(na)
var float xxOpen1 = na
var float xxOpen2 = na
var int[] conditionIndexes = array.new_int(na)
openHistory = request.security(syminfo.tickerid, "", open, lookahead=barmerge.lookahead_on)
for i = 0 to 30
wt101Condition = wt101[i] > wt201[i] and wtDot[i] == 1 and (wt101[i] < 0 or wt201[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))