Reputation: 13
I dont't know Pine Script, but I found in other post, this script to print the ATR daily. Is it posible to modify it to print the ATR daily of previous day (Yesterday)?
Many thanks in advance...
//@version=4
//@author=LucF, for PineCoders
// Indicator needs to be on "no scale".
study("", "Daily ATR", true, scale = scale.none)
atrLength = input(5)
barsRight = input(5)
// Adjust the conversion formatting string to the instrument: e.g., "#.########" for crypto.
numberFormat = input("#.####")
// Plot invisible value to give a large upper scale to indie space.
plotchar(10e10, "", "")
// Fetch daily ATR. We want the current daily value so we use a repainting security() call.
dAtr = security(syminfo.tickerid, "D", atr(atrLength), lookahead = barmerge.lookahead_on)
// Label-creating function puts label at the top of the large scale.
f_print(_txt) => var _lbl = label(na), label.delete(_lbl), _lbl := label.new(time + (time-
time[1]) * barsRight, 10e10, _txt, xloc.bar_time, yloc.price, size = size.normal)
// Print value on last bar only, so code runs faster.
if barstate.islast
f_print(tostring(dAtr, numberFormat))
Upvotes: 0
Views: 606
Reputation: 21121
You can use the history reference operator []
to access historical values.
dAtr
already has the current daily atr value. So if you do dAtr[1]
, you would get the atr value of the previous day.
if barstate.islast
f_print(tostring(dAtr[1], numberFormat))
Upvotes: 1