Reputation: 5
I'm trying extract the difference of current value of two moving averages and put it in a label on the chart. I see the values displayed at the top left corner in the status line of the indicators, so I assume that they are available. Is there a way to extract those values from the calculaton? I tried:
valueEMA100=sma(close, 100)
valueEMA50=sma(close, 50)
deltaEMA=valueEMA100-valueEMA50
trend=tostring(deltaEMA)
The output ends up as "NaN", so basically I can't extract a number this way. When I put an actual number in the tostring() function, I get that on the chart the way it is intended. Any ideas on how I can access the values?
Upvotes: 0
Views: 2539
Reputation: 8779
This uses our f_print()
function which takes care of printing a label:
//@version=4
study("", "", true)
valueEMA100=sma(close, 100)
valueEMA50=sma(close, 50)
deltaEMA=valueEMA100-valueEMA50
trend=tostring(deltaEMA)
f_print(_txt) => var _lbl = label.new(bar_index, highest(10)[1], _txt, xloc.bar_index, yloc.price, #00000000, label.style_none, color.gray, size.large, text.align_left), label.set_xy(_lbl, bar_index, highest(10)[1]), label.set_text(_lbl, _txt)
f_print(trend)
Upvotes: 1