Trouble with Label Plotting in Pine Script: Labels Not Appearing Despite Correct Code Logic

28 Views Asked by At

In Pine Script, there's a problem with plotting labels based on certain conditions despite seemingly correct logic in the code. Here's a breakdown of the code and the issue:

Code Explanation:

The script calculates the highest high (highestHigh) and lowest low (lowestLow) within a specified time period using the getHighestHighLowestLow function. It then plots lines representing these extremes on the chart. The script checks if the current closing price (close) is outside the Bollinger Bands (upper and lower) and beyond the calculated extremes (highestHigh and lowestLow). Based on these conditions, it attempts to plot labels indicating whether the price is accepted or rejected. Problem Description:

Despite the logical structure of the code, the labels indicating acceptance or rejection of the price position are not correctly appearing on the chart as expected. This discrepancy between the expected behavior and the actual outcome suggests an issue with either the conditions used for plotting the labels or with the label plotting mechanism itself.

But rather the labels are not reflecting the expected acceptance status.

i tried chat gbt as am not a coder. `f barstate.islast [indexHighestHighRes, highestHighRes, indexLowestLowRes, lowestLowRes] = getHighestHighLowestLow(timePeriodInput) highestHigh := highestHighRes lowestLow := lowestLowRes

var lineHighestHigh = line.new(last_bar_index - indexHighestHighRes, highestHighRes, last_bar_index, highestHighRes, xloc = xloc.bar_index, extend = highestHighLineExtendRight, color = highestHighLineColorInput, style = line.style_solid, width = highestHighLineWidthInput)
line.set_x1(lineHighestHigh, last_bar_index - indexHighestHighRes)
line.set_x2(lineHighestHigh, last_bar_index)
line.set_y1(lineHighestHigh, highestHighRes)
line.set_y2(lineHighestHigh, highestHighRes)

var lineLowestLow = line.new(last_bar_index - indexLowestLowRes, lowestLowRes, last_bar_index, lowestLowRes, xloc = xloc.bar_index, extend = lowestLowLineExtendRight, color = lowestLowLineColorInput, style = line.style_solid, width = lowestLowLineWidthInput)
line.set_x1(lineLowestLow, last_bar_index - indexLowestLowRes)
line.set_x2(lineLowestLow, last_bar_index)
line.set_y1(lineLowestLow, lowestLowRes)
line.set_y2(lineLowestLow, lowestLowRes)

int indexLatestExtreme = math.min(indexHighestHighRes, indexLowestLowRes)
bool latestExtremeAcceptance = close >= lowestLowRes and close <= highestHighRes

// Check if any part of the candle is outside Bollinger Bands using the function
breaks_BB = isCandleOutsideBB(high, low, upper, lower)

// Plotting the labels for candles that surpassed the extreme and are outside BB
if (close > highestHigh or close < lowestLow) and breaks_BB
    label.new(x = last_bar_index - indexLatestExtreme, y = (indexLatestExtreme == indexHighestHighRes) ? highestHighRes : lowestLowRes, text = "Rejected", style = label.style_label_down, color = color.red, textcolor = color.white, size = size.small)
else if (close > highestHigh or close < lowestLow) and not breaks_BB
    label.new(x = last_bar_index - indexLatestExtreme, y = (indexLatestExtreme == indexHighestHighRes) ? highestHighRes : lowestLowRes, text = "Accepted", style = label.style_label_down, color = color.green, textcolor = color.white, size = size.small)


var latestExtremeAcceptanceLabel = label.new(last_bar_index - indexLatestExtreme, (indexLatestExtreme == indexHighestHighRes) ? highestHighRes : lowestLowRes, "")
label.set_text(latestExtremeAcceptanceLabel, latestExtremeAcceptance ? 'Accepted' : 'Rejected')
label.set_x(latestExtremeAcceptanceLabel, last_bar_index - indexLatestExtreme)
label.set_yloc(latestExtremeAcceptanceLabel, (indexLatestExtreme == indexHighestHighRes) ? yloc.abovebar : yloc.belowbar)
label.set_color(latestExtremeAcceptanceLabel, latestExtremeAcceptance ? color.green : color.red)
label.set_style(latestExtremeAcceptanceLabel, (indexLatestExtreme == indexHighestHighRes) ? label.style_label_down : label.style_label_up)`
0

There are 0 best solutions below