Reputation: 5
I wanted to know how to lookback or pick daily candle values only irrespective of the time frame open on the chart / window.
I need this to calculate and hence display MA on screen (MA displayed on screen today basis close of yesterday) and also to calculate last five days high / low etc.
I can use
highestHigh = ta.highest(high, 5)
highestClose = ta.lowest(low, 5)
but here 5 bars will change with TF of chart - 5 minis / 15 mins / 55 mins. So how to pick daily values?
For the five days high / low I will need to know to define range too.
Thank you
In below code, I want close to be of yesterday even when I am using 5-15 mins today. How can I do this? Second question is how do I code a date range? eg If I want to pick highest / lowest from last five days
study("", "Daily 20MA", true, scale = scale.none)
MALength = input(20)
barsRight = input(3)
Source=(close)
numberFormat = input("#.##")
plotchar(10e10, "", "")
DMA = security(syminfo.tickerid, "D", sma(Source,MALength), lookahead = barmerge.lookahead_on)
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)
if barstate.islast
f_print(tostring(DMA, numberFormat))
Upvotes: 0
Views: 880
Reputation: 21342
You can use the security()
function for this purpose and pass your highest and lowest variables to it. It would then return the highest and lowest prices of the daily timeframe.
//@version=5
indicator("My script", overlay=true)
_highest = ta.highest(5)
_lowest = ta.lowest(5)
[highest_daily, lowest_daily] = request.security(syminfo.tickerid, "D", [_highest, _lowest])
plot(highest_daily, color=color.green)
plot(lowest_daily, color=color.red)
Upvotes: 0