0
votes

Im trying to utilize an ATR overlay script, but I don't want it to take into account any price data from the current day. Presently, the overlay will change based on minute by minute price data even though the script is using the average of daily closes over the last 14 days.

Im working off of someone else's public code (Im not a developer, but have modified a few scripts in the past), but it is below.

//
study(title="Average True Range Overlay", shorttitle="ATRO", overlay=true)
atrlen = input(14, minval=1)
emalen = input(2, minval=1)
watrband = input(1, minval=0)
//
// Always use the Daily data in this overlay regardless of the current time scale
cl=ema(close, emalen)
atrbh  = cl + watrband*atr(atrlen)
atrbl  = cl - watrband*atr(atrlen)
atrbhD = security(tickerid, 'D', atrbh)
atrblD = security(tickerid, 'D', atrbl)
plot(atrbhD, color=blue, linewidth=2, offset=1)
plot(atrblD, color=blue, linewidth=2, offset=1)
//

When its working properly, it looks like this, smooth straight lines: (https://imgur.com/L8g1YDf)

When live price data is coming in, it starts to plot data in realtime and the lines starts to squiggle and create lines that are not horizontal: (https://imgur.com/keynwZU)

Is there a way to have it just plot the average true range for the last 14 days without including the present day?

Thanks in advance for any assistance!

1

1 Answers

0
votes

Yes, your script "repaints". If you'll reload the page those curve lines will become straight. You can avoid it by using the previous daily data in the security functions:

atrbhD = security(tickerid, 'D', atrbh[1])
atrblD = security(tickerid, 'D', atrbl[1])