Reputation: 3
I have a trading strategy, which compares ema(2) value vs ema(21)(which happens to be the middle line of bollinger band.)
So I am trying to plot a shot horizontal line which equals to the last value of ema(2), and shift it 2 - 3 time units from current bar. below is the code I am trying:
plot(ema(close,2)[0], title="EMA2", linewidth=2, color=color.aqua, show_last=3, offset=2)
However I think what I get is the last 3 time units curve and shift to the right for 2 time units.
Shouldn't the ema(close,2)[0] give me one single value equals to the last value of this ema price curve?
Upvotes: 0
Views: 737
Reputation: 2568
In your case, you need to use the line.new()
function
//@version=4
study("Help (hline)", overlay=true)
ema2 = ema(close,2)
line ln = na
line.delete(ln[1])
//ln := line.new(bar_index - 3, ema2, bar_index, ema2, width=2, color=color.aqua, extend=extend.right)
//For intraday timeframes, three bars back and three bars forward
ln := line.new(time - timeframe.multiplier * 3 * 60 * 1000, ema2, time + timeframe.multiplier * 3 * 60 * 1000, ema2, xloc=xloc.bar_time, width=2, color=color.aqua)
//plot(ema(close,2)[0], title="EMA2", linewidth=2, color=color.aqua, show_last=3, offset=2)
Upvotes: 0