Reputation: 5
I'm stuck with the problem below.
What I would like to achieve:
I tried with plotchar and I managed to add the arrows to all bar, but I failed to filter them to show only at the last bar (show_last=1 was not accepted as argument).
I tried to add "text=variable" but Pine accepts only literal string there. I tried tostring(value) but was not accepted.
My code so far which works fine:
//
study("Percent diff. from 200 day EMA", shorttitle="% From EMA", overlay=true, precision=2)
dif200 = (close - (ema(close,200))) * 100 / ema(close,200)
plot(dif200, "Diff. from 200", color=#2196f399, linewidth=2, title="From 200", style=columns)
plot(dif200, "Actual value", color=#2196f399, trackprice=true, linewidth=1, transp=10, offset=-9999)
hline(0, color=red, title="Zero line", linestyle=solid, linewidth=2)
What should be my next step?
Thank you for your kind help! Regards, Ivan
Upvotes: 0
Views: 1787
Reputation: 3828
barcolor
function.//@version=4
. To plot a dynamic value you have to use label.new
+ tostring
functions as in the example below. To be able to plot the same dynamic label on the chart pane you have to create a separate script and load it on the chart.//@version=4
study("Percent diff. from 200 day EMA", shorttitle="% From EMA", overlay=false, precision=2)
dif200 = (close - (ema(close,200))) * 100 / ema(close,200)
plot(dif200, "Diff. from 200", color=#2196f399, linewidth=2, title="From 200", style=plot.style_columns)
plot(dif200, "Actual value", color=#2196f399, trackprice=true, linewidth=1, transp=10, offset=-9999)
hline(0, color=color.red, title="Zero line", linestyle=hline.style_solid, linewidth=2)
if barstate.islast
label.new(bar_index, dif200, tostring(dif200), xloc.bar_index, yloc.price, #2196f399, label.style_label_left, color.white)
Upvotes: 0