0
votes

how can i output a horizontal line with pine script that follows the EMA8. You should do a small calculation and print the line on the desired time with price on the right side.

EMA 8 (close) minus 1/2 of the ATR(14) = line output.

1
//@version=3 study("LINE", overlay=true) ma_len = 8 src = close res = "D" htf_ma = sma(src, ma_len) out = security(tickerid, res, htf_ma) plot(out, color=red, show_last=1, linewidth=3) I have already tried something here. Need a solid line and I want to subtract half of the ATR14 value. - handy

1 Answers

0
votes

To subtract atr you can call built-in atr function

atr14 = atr(14)

To plot a horizontal ray you can set the trackprice argument of the plot function. However it will extent the line to the left as well.

//@version=3 
study("LINE", overlay=true) 
ma_len = 8 
src = close 
res = "D" 
htf_ma = sma(src, ma_len) 
out = security(tickerid, res, htf_ma) 
plot(out, color=red, show_last=1, linewidth=3)

atr14 = atr(14)
plot(out - (atr14/2), color=red, linewidth=3, show_last=1, trackprice = true)

enter image description here