4

I have a label being plotted on an ema cross. Is it possible to show the close price in the text of the label? The code below doesn't like the builtin 'close' variable I'm trying to use.

plotshape(crossover(ema1, ema2), title="Cross Over", style=shape.labelup, location=location.belowbar, color=green, size=size.normal, text=close, textcolor=white, transp=40)
PineCoders-LucF
  • 8,288
  • 2
  • 12
  • 21
user1444534
  • 41
  • 1
  • 3
  • I think it's not possible. My solution would be to cast the float to a string. https://www.tradingview.com/study-script-reference/#fun_tostring but the pine interpreter accepts only constant string values. – Clueless Apr 15 '18 at 11:39
  • @Clueless I tried it, but looks like it doesn't work xx = tostring(close, '#.####') or xx = tostring(close). Do you know how to use it? Thank you. – whitesiroi May 27 '18 at 05:14
  • @Clueless Looks like it impossible at current moment plotchar(data, char=xx, text=xx). Getting the same error "argument "text" accepts only literal string values" – whitesiroi May 27 '18 at 05:32

1 Answers1

3
// mrtuanvn
//@version=4
study("Label at crossed",overlay=true)
crossed =crossover(ema(close,10), ema(close,50))
if crossed
    l = label.new(bar_index, na, tostring(close), 
         color=color.green, 
         textcolor=color.white,
         style=label.style_labeldown, yloc=yloc.abovebar)
Tuan Tran
  • 114
  • 4