Is it possible to return the time the daily high was made? (pinescript)

Lew2234

So I’m basically building a custom indicator and trying to retrieve the time the previous daily high was made.

I’m using:

PDH = request.security(syminfo.tickerid, ‘D’, high[1])

To retrieve the previous daily high price but is it possible to retrieve the time the high was made?

Would greatly appreciate any help with this, been bugging me for hours!

Many thanks in advance!

vitruvius

You can use the below function to convert time to a date-time string.

f_timeToString(_t) =>
      str.tostring(year(_t), "0000") + "." + str.tostring(month(_t), "00") + "." + str.tostring(dayofmonth(_t), "00") + " " +
      str.tostring(hour(_t), "00") + ":" + str.tostring(minute(_t), "00") + ":" + str.tostring(second(_t), "00")

To get the time and value, I would simply use var variables. Update them when it is a new day or if there is a new high.

//@version=5
indicator("My script", overlay=true, max_labels_count = 500)

f_timeToString(_t) =>
  str.tostring(year(_t), "0000") + "." + str.tostring(month(_t), "00") + "." + str.tostring(dayofmonth(_t), "00") + " " +
  str.tostring(hour(_t), "00") + ":" + str.tostring(minute(_t), "00") + ":" + str.tostring(second(_t), "00")

var int daily_high_time = na
var int prev_daily_high_time = na
var float daily_high = na
var float prev_daily_high = na

is_new_day = ta.change(time("D"))

prev_daily_high_time := is_new_day ? daily_high_time : prev_daily_high_time
prev_daily_high := is_new_day ? daily_high : prev_daily_high
daily_high_time := is_new_day ? time : (high > daily_high) ? time : daily_high_time
daily_high := is_new_day ? high : (high > daily_high) ? high : daily_high

if (is_new_day)
    s = "Daily High: " + str.tostring(prev_daily_high) + "\nTime:\n" + f_timeToString(prev_daily_high_time)
    label.new(prev_daily_high_time, prev_daily_high, s, xloc=xloc.bar_time)

bgcolor(is_new_day ? color.new(color.blue, 85) : na)

enter image description here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Running PHP script as close to daily time as possible

How do I plot a horizontal line on the high and low of a specific time in Pinescript?

How to get daily high and low time in pine script?

is it possible to determine local time of the machine from which an api request is made?

PineScript: Is it possible to scroll inside a table?

PineScript - How to compare a higher high to current price

trigger strategy at specified time in pinescript

Pinescript: How to change weekly high & low to previous weekly high & low

Calculating rate of return for multiple time frames (annualized, quarterly) with daily time series data (S&P 500 (SPX index) daily prices)

Is it possible to upload pinescript from local filesystem?

Daily High/Low on intraday data

How to get the highest high and the lowest low of specific timeframe in pinescript

Line is not starting from previous day high in TradingView Pinescript

Is there any possible way to append an event (custom made) to an object created in run-time ?[C++ Builder]

Adjusting Daily return in Quantmod

Intraday daily return

It is possible to create a new data frame on Pandas from a time series, with the daily diference?

Daily Time Schedule (MySQL)

Daily Time Series Forecasting

Plot daily time series

Is it possible to yield two things at a time just like return?

Is it possible to declare a pointer to a function with unknown (at compile time) return type

Is it possible for fscanf to return zero and consume input at the same time?

How to determine a functions` return value choosing possible options at compile time

Is it possible to initialize a vector and return it at the same time in c++?

Not getting proper daily high and low on Historical bars

Avoid high daily charges with Cloud SQL

Is is possible to decrease connection that made to db?

Pinescript strategy is not printing correctly on charts (possible timestamp problem)