Premarket Opening Range Breakout (ORB) with Targets
Before the market opens, this indicator generates daily targets for the upside and downside. It calculates the "In the Zone" shaded area between 8-8:15am EST. Price will typically move away from this zone and hit at least one of the target levels every day. Sometimes price will breach far beyond the third target as shown in the second day of the below picture.
Code:
# ==============================================
# STUDY: PREMARKET_ORB 15-Min Range (08:00-08:15 EST) Visualizer
# ==============================================
input startTime = 0800;
input endTime = 0815;
def aggregationPeriod = AggregationPeriod.MIN;
Assert(getAggregationPeriod() <= AggregationPeriod.fifteen_min, "Less than 15M");
# --- 1. DEFINE THE RANGE WINDOW ---
# We are "In the Zone" if time is between 08:00 and 08:15
def inRange = SecondsFromTime(startTime) >= 0 and SecondsFromTime(endTime) < 0;
def isPostRange = SecondsFromTime(endTime) >= 0;
# --- 2. CAPTURE THE AGGREGATE HIGH / LOW ---
# Recursive variables to track the Max/Min during the window.
# Once the window closes (isPostRange), we lock the value.
rec rHigh =
if SecondsFromTime(startTime) == 0 then high
else if inRange and high > rHigh[1] then high
else if inRange then rHigh[1]
else rHigh[1]; # Lock the value after 08:15
rec rLow =
if SecondsFromTime(startTime) == 0 then low
else if inRange and low < rLow[1] then low
else if inRange then rLow[1]
else rLow[1]; # Lock the value after 08:15
def rMid = (rHigh + rLow) / 2;
# --- 3. PLOT THE LEVELS ---
# We only plot these lines starting at 08:15 so the chart stays clean.
plot Midpoint = if isPostRange then rMid else Double.NaN;
Midpoint.SetDefaultColor(Color.YELLOW);
#Midpoint.SetStyle(Curve.SHORT_DASH);
Midpoint.SetLineWeight(2);
plot RangeHigh = if isPostRange then rHigh else Double.NaN;
RangeHigh.SetDefaultColor(Color.GREEN);
RangeHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
RangeHigh.SetLineWeight(2);
plot RangeLow = if isPostRange then rLow else Double.NaN;
RangeLow.SetDefaultColor(Color.RED);
RangeLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
RangeLow.SetLineWeight(2);
# --- 4. FILL THE RANGE ---
# Shades the zone between High and Low
AddCloud(RangeHigh, RangeLow, Color.GRAY, Color.GRAY);
# --- 5. TARGETS
# First target is gray line, second target is red line and third target is white line.
plot F_HT = RANGELOW -(RANGELOW-RANGEHIGH) * 4.68;
F_HT.setdefaultcolor(color.red);
F_HT.setlineweight(3);
plot F_LT = RANGEHIGH -(RANGELOW-RANGEHIGH) * -4.68;
F_LT.setdefaultcolor(color.red);
F_LT.setlineweight(3);
plot F_HT1 = RANGELOW -(RANGELOW-RANGEHIGH) * 7.58;
F_HT1.setdefaultcolor(color.WHITE);
F_HT1.setlineweight(3);
plot F_LT1 = RANGEHIGH -(RANGELOW-RANGEHIGH) * -7.58;
F_LT1.setdefaultcolor(color.WHITE);
F_LT1.setlineweight(3);
plot UM = (F_HT - Rangehigh)/2 + rangehigh;
UM.setdefaultColor(color.gray);
plot LM = rangelow - (F_HT - Rangehigh)/2;
LM.setdefaultColor(color.gray);
Last edited: