I would like to plot around 20 labels on a chart. I'll get the data in a CSV format. It will contain price, date and an id.
So far I figured out how to plot a single label containing data from three arrays but I'm not sure how to loop through an array. Also, I couldn't figure out how to have cleaner looking arrays with the data.
Here is what I have so far.
//@version=4
study(title="My study", overlay=true)
// Make a label once (as preparation)
var float[] prices = array.new_float(2)
var string[] ids = array.new_string(2)
var int[] date = array.new_int(2)
array.set(prices, 0, 8)
array.set(prices, 1, 6)
array.set(ids, 0, "CF442W")
array.set(ids, 1, "WI211KK")
array.set(date, 0, 1641774575000)
array.set(date, 1, 1621772575000)
var monthLabel = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.black, textcolor=color.white)
var monthLabel1 = label.new(x=na, y=na, xloc=xloc.bar_time, color=color.black, textcolor=color.white)
// // Update the label on the chart's last bar
if (barstate.islast)
labelText = "TRADE: " + array.get(ids, 0) + "\n\n BUY: " + tostring(array.get(prices, 0))
label.set_y(id=monthLabel, y=array.get(prices, 0))
label.set_x(id=monthLabel, x=array.get(date, 0))
label.set_text(id=monthLabel, text=labelText)
if (barstate.islast)
labelText1 = "TRADE: " + array.get(ids, 1) + "\n\n BUY: " + tostring(array.get(prices, 1))
label.set_y(id=monthLabel1, y=array.get(prices, 1))
label.set_x(id=monthLabel1, x=array.get(date, 1))
label.set_text(id=monthLabel1, text=labelText1)