Add snippets/label_demo.pine
This commit is contained in:
24
snippets/label_demo.pine
Normal file
24
snippets/label_demo.pine
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
//@version=6
|
||||||
|
indicator("Label Example", overlay=true)
|
||||||
|
|
||||||
|
// Calculate a condition for when to create a label
|
||||||
|
condition = close > math.avg(close, 20)
|
||||||
|
|
||||||
|
// Create a new label if the condition is true, update the label's text with the current close price
|
||||||
|
//label_id = label.new(title="Price Label", x=bar_index, y=close, text=str.tostring(close), color=color.green, style=label.style.plain)
|
||||||
|
|
||||||
|
// Create an array to store labels
|
||||||
|
var label[] labelArray = array.new_label()
|
||||||
|
|
||||||
|
labelDemo() =>
|
||||||
|
// Remove a specific label by index
|
||||||
|
if (array.size(labelArray) > 0)
|
||||||
|
label.delete(array.get(labelArray, 0))
|
||||||
|
array.remove(labelArray, 0)
|
||||||
|
|
||||||
|
label newLabel = label.new(x=bar_index, y=close, text='H:' + str.tostring(high, '#.##') + '\nL:' + str.tostring(low, '#.##'), xloc=xloc.bar_index, yloc=yloc.price, color=color.blue, style=label.style_label_down, textcolor=color.white, size=size.normal, textalign=text.align_center, tooltip='SIZE: ' + str.tostring(high-low, '#.##'))
|
||||||
|
|
||||||
|
// Add new labels to array
|
||||||
|
array.push(labelArray, newLabel)
|
||||||
|
|
||||||
|
labelDemo()
|
||||||
Reference in New Issue
Block a user