pine script - Get HH and LL and Close value for specific time range - Stack Overflow

admin2025-05-01  0

For the time range that I have given as input, it should get the higher high, lower low and close of the previous day within that time range. I am a beginner to Pine Script. I have collaborated codes from different sources other than my own. But, I still need help to achieve this. Can anyone help? My code didn't give the correct results. Im using IST timezone.

    //@version=5
indicator("Previous Day Highs and Lows", overlay=true)

// User-defined sessions
first_session = input.session("0915-1225", title="First Session")
second_session = input.session("1230-1530", title="Second Session")

// Functions to identify high and low during a session
is_in_first_session = (time >= timestamp(year, month, dayofmonth, 9, 15)) and (time <= timestamp(year, month, dayofmonth, 12, 25))
is_in_second_session = (time >= timestamp(year, month, dayofmonth, 12, 30)) and (time <= timestamp(year, month, dayofmonth, 15, 30))

// Get previous day high/low based on session time frames
var float first_session_high = na
var float first_session_low = na
var float second_session_high = na
var float second_session_low = na

// Track highs and lows during the first session
if (is_in_first_session)
    first_session_high := na(first_session_high) ? high : math.max(first_session_high, high)
    first_session_low := na(first_session_low) ? low : math.min(first_session_low, low)

// Track highs and lows during the second session
if (is_in_second_session)
    second_session_high := na(second_session_high) ? high : math.max(second_session_high, high)
    second_session_low := na(second_session_low) ? low : math.min(second_session_low, low)


if barstate.islast
    label.new(x=bar_index + 2, y=hl2, style=label.style_label_upper_right,color=color.new(color.yellow, 70), size=size.large,text= "second_session_high"+str.tostring(second_session_high)+"\nsecond_session_low:"+str.tostring(second_session_low) )
转载请注明原文地址:http://anycun.com/QandA/1746111475a91826.html