I’m not sure I had the perfect picture, but here is a new draft version:
The three changes made:
- Today-only lines —
DEFPARAM DrawOnLastBarOnly = True means every drawing is redrawn from scratch on the last bar only, so DRAWSEGMENT always draws a fresh single segment anchored to StartBar. The staircase on previous days came from the RETURN series plotting a continuous connected line across all history. Fixed by returning 0 for all bars before StartBar, so the price-scale series has no values before today’s session. - Midnight detection — replaced
OpenDay <> OpenDay[1] with a time-based check using OpenTime and a calculated ResetTime. OpenTime is in UTC on PRT servers. For UTC+1 local midnight = 23:00 UTC the previous day, so ResetTime = MOD(24 - UTCOffset, 24) * 10000. UTCOffset is a user-adjustable parameter at the top. Set it to 0 for UTC, 1 for UTC+1, 2 for UTC+2, -5 for UTC-5 etc.
DEFPARAM DrawOnLastBarOnly = True
// --- Indicator: Midnight Reset Pro (ADR % Flag) ---
// --- USER OPTIONS ---
Offset = 5 // Bars to extend lines to the right of current bar
ADRPeriod = 14
UTCOffset = 1 // Your timezone offset from UTC (e.g. 1 for UTC+1, 0 for UTC, -5 for UTC-5)
// --------------------
// Calculate the reset time expressed in platform UTC time
// Midnight local (UTC+X) = hour (24 - UTCOffset) mod 24 in UTC
// e.g. UTCOffset=1 => ResetTime=230000 (23:00 UTC = midnight UTC+1)
ResetHour = MOD(24 - UTCOffset, 24)
ResetTime = ResetHour * 10000
// Detect the first bar at or just past the timezone-adjusted midnight
IsNewDay = (OpenTime = ResetTime) OR (OpenTime > ResetTime AND OpenTime[1] < ResetTime)
// 1. Track today's session high/low from the adjusted midnight
ONCE TodayHigh = High
ONCE TodayLow = Low
ONCE StartBar = BarIndex
IF IsNewDay THEN
StartBar = BarIndex
TodayHigh = High
TodayLow = Low
ELSE
TodayHigh = MAX(TodayHigh, High)
TodayLow = MIN(TodayLow, Low)
ENDIF
// 2. Calculations
CurrentRange = TodayHigh - TodayLow
MidPoint = (TodayHigh + TodayLow) / 2
MyADR = ROUND(Average[ADRPeriod](DHigh(1) - DLow(1)))
IF MyADR > 0 THEN
PctOfADR = (CurrentRange / MyADR) * 100
ELSE
PctOfADR = 0
ENDIF
// 3. DRAW VISUALS
// Vertical dotted line at the timezone-adjusted midnight bar
DRAWVLINE(StartBar) coloured(150,150,150) style(dottedline,1)
// Horizontal segments from midnight bar to Offset bars beyond current bar
// DrawOnLastBarOnly redraws these fresh every tick — no staircase, today only
DRAWSEGMENT(StartBar, TodayHigh, BarIndex + Offset, TodayHigh) coloured(0,255,0) style(line,3)
DRAWSEGMENT(StartBar, TodayLow, BarIndex + Offset, TodayLow) coloured(255,0,0) style(line,3)
DRAWSEGMENT(StartBar, MidPoint, BarIndex + Offset, MidPoint) coloured(255,255,0) style(dottedline,2)
// Colour logic and label
IF PctOfADR >= 90 THEN
r = 255
g = 165
b = 0
BACKGROUNDCOLOR(255, 165, 0, 20)
ELSE
r = 255
g = 255
b = 255
ENDIF
DisplayPct = ROUND(PctOfADR)
DRAWTEXT("#DisplayPct#% ADR", BarIndex + Offset, TodayHigh + 5*pipsize, SansSerif, Bold, 12) coloured(r, g, b)
// 4. Return series for the price scale
// Only feed values for today's bars (BarIndex >= StartBar)
// Bars before today return 0, preventing the series lines extending back over history
IF BarIndex >= StartBar THEN
RetHigh = TodayHigh
RetLow = TodayLow
RetMid = ROUND(MidPoint)
ELSE
RetHigh = 0
RetLow = 0
RetMid = 0
ENDIF
RETURN RetHigh AS "High" COLOURED(0,255,0), RetLow AS "Low" COLOURED(255,0,0), RetMid AS "Mid" COLOURED(255,255,0), MyADR AS "ADR" COLOURED(200,200,200)
A note on UTCOffset and DST: PRT platform servers run UTC. If your broker feeds tick data in UTC this works precisely. If your platform is set to a local timezone, OpenTime will reflect that offset automatically and you may need to set UTCOffset = 0 in that case and instead rely purely on the IsNewDay time comparison against 000000. The safest way to verify is to check what value OpenTime shows at what you know to be midnight on the chart then adjust UTCOffset so that ResetTime matches.
Also, make sure the instrument has *really* 24 hours (not the case for Futures), so amend the formula at line 13 with the amount of hours available on the time axis.