Search code examples
pine-scriptpine-script-v5algorithmic-tradingtradingview-api

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


I'm trying to figure out how to get the daily high and low time so I can apply it to my conditions on the lower time frame.
Actually, I want to find out which of the lower or upper levels is more distant or closer in time.
In the code below, the desired section is empty and I don't know how to get those time values. Please guide me if you can.

//@version=5
indicator('HiLo', overlay=true, shorttitle='HiLo')
    
//Get High&Low Price
isess = session.regular
t = ticker.new(syminfo.prefix, syminfo.ticker, session=isess)

todayHigh = request.security(t, 'D', high[0], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
todayLow = request.security(t, 'D', low[0], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)

//How To Get todayHigh and todayLow Time?
//Thank you in advance

todayHighTime = 
todayLowTime =

////////////

Solution

  • Track the daily high and low yourself. You don't need a security() function for this.

    Here is an example for the high price.

    //@version=5
    indicator("My script", overlay=true)
    
    var float high_price = na
    var int high_time = na
    
    is_new_day = ta.change(time("D"))
    bgcolor(is_new_day ? color.new(color.blue, 85) : na)
    
    if (is_new_day)
        high_price := high
        high_time := time
    else
        if (high > high_price)
            high_price := high
            high_time := time
    
    plot(high_price)
    

    Please note that time returns time in UNIX format.