As show in the image, the first three candles of the day.
0
votes
1 Answers
0
votes
You are asking basically about opening range. This will take the time as input and will plot horizontal lines with the highs and lows of that period, so if you are on 15m TF and you want to get the higher high and lowest low of 3 candles, set it with a difference of a 45 min (15 * 3 = 45)...and so on.
It's not a square as your drawing, but it's what you asked.
//@version=4
study("My Script - Opening range", overlay=true)
// Inputs
my_session = input("0930-1015", type=input.session, title='Custom Session')
FILL = input(true, title="Show Session BGcolor?")
// Determine if we are in a session
in_session = time(timeframe.period, my_session)
is_new_session(res, sess) =>
t = time(res, sess)
na(t[1]) and not na(t) or t[1] < t
new_session = is_new_session("1440", my_session)
// Start of Session
is_newbar(res,sess) =>
t = time(res,sess)
not na(t) and (na(t[1]) or t > t[1])
new = (is_newbar("1440", my_session) ? 1 : 0)
// Plot Start Of Session
col_Start_of_Session = new_session and new==1? color.aqua:na
//plotshape(high, color=col_Start_of_Session, style=shape.circle, location= location.absolute, size=size.small, title="Start_of_Session")
// In Session High/Low Calculations
var float _low = close
var float _high = close
_low := new_session? low : in_session ? min(low, _low[1]) : na
_high := new_session ? high : in_session ? max(high, _high[1]) : na
col_low = _low == low? na: true?color.red:na
col_high = _high== high? na:true? color.green:na
// Plot High/Low Line
Low=plot(_low, style=plot.style_line, linewidth=1, color=col_low)
High=plot(_high, style=plot.style_line, linewidth=1, color=col_high)
// BG Color
Fill_col = FILL ? color.new(color.yellow, 70):na
fill(Low,High, color=Fill_col)
// End of Session
start_of_session_value = valuewhen((new==1),high,0)
end_session_condition = start_of_session_value !=start_of_session_value[1]?0: in_session?1:0
end_session = (end_session_condition == 0) and (end_session_condition[1]==1)? color.orange:na
//plotshape(close, color=end_session, location=location.absolute, style=shape.circle, size=size.small)
// Extend High/Low Session Lines
v_extend_low = valuewhen((_low == low),low,0)
col_v_extend_low = (end_session_condition == 0) and v_extend_low ==v_extend_low[1] ? color.red:na
v_extend_high = valuewhen((_high == high),high,0)
col_v_extend_high = (end_session_condition == 0) and v_extend_high ==v_extend_high[1] ? color.green:na
plot(v_extend_low, color=col_v_extend_low, title="Extend Low")
plot(v_extend_high, color=col_v_extend_high, title="Extend High")
