OPEN-SOURCE SCRIPT

Prev Day High/Low + 15min Range Boxes

267
//version=5
indicator("Prev Day High/Low + 15min Range Boxes (Next Day Display)", overlay=true, dynamic_requests=true)

rth_tz = "America/New_York"
rth_start = timestamp(rth_tz, year, month, dayofmonth, 9, 30)
rth_end = timestamp(rth_tz, year, month, dayofmonth, 16, 0)

// Get 15-minute data
[hi15, lo15, op15, cl15, time15] = request.security(syminfo.tickerid, "15", [high, low, open, close, time])

// Define yesterday's RTH
curr = time("15")
prev = curr - 24 * 60 * 60 * 1000
yesterday_start = timestamp(rth_tz, year(prev), month(prev), dayofmonth(prev), 9, 30)
yesterday_end = timestamp(rth_tz, year(prev), month(prev), dayofmonth(prev), 16, 0)

// Collect yesterday's RTH extremes
var float prevHigh = na
var float prevLow = na
var int prevHighTime = na
var int prevLowTime = na
var float prevHighBody = na
var float prevLowBody = na
inRTH_yesterday = time15 >= yesterday_start and time15 <= yesterday_end

if inRTH_yesterday
if na(prevHigh) or hi15 > prevHigh
prevHigh := hi15
prevHighTime := time15
prevHighBody := na
if na(prevLow) or lo15 < prevLow
prevLow := lo15
prevLowTime := time15
prevLowBody := na

// Capture the body of the next 15m candle after the extremes
highNextCond = not na(prevHighTime) and time15 == prevHighTime + 15 * 60 * 1000
lowNextCond = not na(prevLowTime) and time15 == prevLowTime + 15 * 60 * 1000
if highNextCond
prevHighBody := math.max(op15, cl15)
if lowNextCond
prevLowBody := math.min(op15, cl15)

// ⏱ Today’s RTH
today_start = timestamp(rth_tz, year, month, dayofmonth, 9, 30)
today_end = timestamp(rth_tz, year, month, dayofmonth, 16, 0)
inRTH_today = time >= today_start and time <= today_end

// Draw the yellow boxes on current RTH using previous day’s high/low
var box highBox = na
var box lowBox = na

if inRTH_today and not na(prevHigh) and not na(prevHighBody)
if na(highBox)
highBox := box.new(left=today_start, right=today_end, top=prevHigh, bottom=prevHighBody,
xloc=xloc.bar_time, border_color=color.yellow, bgcolor=color.new(color.yellow, 70), border_width=1)

if inRTH_today and not na(prevLow) and not na(prevLowBody)
if na(lowBox)
lowBox := box.new(left=today_start, right=today_end, top=prevLowBody, bottom=prevLow,
xloc=xloc.bar_time, border_color=color.yellow, bgcolor=color.new(color.yellow, 70), border_width=1)

Feragatname

Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, işlem veya diğer türden tavsiye veya tavsiyeler anlamına gelmez ve teşkil etmez. Kullanım Şartları'nda daha fazlasını okuyun.