There are a few ways to avoid labels overlapping in Pinescript:
Use the input parameters overlay=true
and yloc=yloc.abovebar
in the label.new()
function to automatically position labels above the bars without overlapping.
Calculate the distance between labels and adjust the yloc
parameter accordingly to create more space between labels. For example:
dist = abs(close - close[1])
label_yloc = close > close[1] ? yloc.belowbar : yloc.abovebar
label.new(bar_index, close, tostring(dist), yloc=label_yloc)
security()
function to plot labels on a separate indicator pane, rather than directly on the price chart, to avoid overlapping with other price-related indicators. For example:study("My Indicator")
upperBand = sma(close, 20) + stdev(close, 20)
lowerBand = sma(close, 20) - stdev(close, 20)
plot(upperBand, "Upper Band")
plot(lowerBand, "Lower Band")
myLabel = label.new(bar_index, upperBand, "My Label", color.white)
security(symbol, "D", myLabel)
This code plots the label "My Label" on a separate "D" indicator pane, avoiding overlap with the upper and lower bands plotted on the price chart.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2022-04-10 11:00:00 +0000
Seen: 19 times
Last updated: Dec 25 '22
What is the solution for making the carousel indicator buttons react to mouse-clicks?
How to create a bar chart with two sets of x-axis labels?
How can axis labels be retained while hiding the values of the tick labels?
Whenever I code the data labels for my boxplot, the y axis keeps changing.
How can the legend of a Seaborn scatterplot be updated within a loop?
Why is ggplot displaying decimal values in the legend when the column contains numerical values?
What is the method for creating a pie chart with three layers in R?
How can checkboxes be aligned with their corresponding labels?
How can labels be created and concealed in Excel with respect to a shipment memo?
How can the size of a ggplot2 plot be adjusted without altering the size of its axis labels?