'Pine Script / TradingView - Get Close Price of particular hour on Daily Chart?
I'm using a daily chart, and would like to get the close price of the ticker at a particular hour (let's say 15:00 EST), how do I go about doing that?
I know I can do:
TimePrice := (hour== 15 and minute == 0) ? close : TimePrice
But that only seems to work on charts that are half hour or faster.
Is there a way to get the close price for a particular hour while using the daily chart?
Solution 1:[1]
Not fully tested but you can try this:
//@version=5
indicator("Show close price at 15:00",overlay=true)
tnow = timenow
t1500 = timestamp(year(time) , month(time) , dayofmonth(time) , 15 , 0, 0)
t1530 = timestamp(year(time) , month(time) , dayofmonth(time) , 15 , 30, 0)
index = tnow>t1530? 2: tnow>t1500? 1 : na
close30 = index>=0 ? request.security(syminfo.tickerid, "30", close[index]) : na
a = array.new_float(1)
array.set(a, 0, close30)
close1500 = array.get(a, 0)[0]
var table msgDisplay = table.new(position.bottom_right, 1, 1)
table.cell(msgDisplay, 0, 0, str.tostring(close1500), bgcolor = color.yellow)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | jcemp |
