Pre Market Range


New member
Hi - I am looking to plot a shaded box in my ToS with the premarket prices as the upper and lower bounds, shaded in between. However, these bounds should be limited to the high and low prices of the equity between 6:00am and 9:20am EST. My code is below, and I can't get it to work. Would love some help. (I realize code below is incomplete)

plot Data = close;

#defines PRE mkt hours I want to use as:
input openingESTime  = 0600.0;
input openingTime  = 0920.0;

def isDaily = If (GetAggregationPeriod() == AggregationPeriod.DAY, yes, no);

def isPreMarket = If (GetDay() == GetLastDay() and SecondsTillTime(openingTime) <300, yes, no);
input LineWidth = 1;
def na = Double.NaN;

def isBelowDaily = If (GetAggregationPeriod() < AggregationPeriod.DAY, yes, no);
def isToday = If (GetDay() == GetLastDay() and SecondsFromTime(openingESTime) >= 300, yes, no);
def day = GetDay();

def PMopenBar = day != day[1];
def PMOpen = if PMopenBar then open else PMOpen[1];



Active member
This what you're looking for?
# see
declare once_per_bar;

input PlotPreMktLinesHrsPastOpen = yes;
input ShowChartBubbles = yes;

def bar = BarNumber();
def nan = Double.NaN;
def vHigh = high;
def vLow = low;

def PMhrs = RegularTradingStart (GetYYYYMMDD()) > GetTime();
def RMhrs = RegularTradingStart (GetYYYYMMDD()) < GetTime();
def PMStart = RMhrs[1] and PMhrs;
def PMHigh = CompoundValue(1, if PMStart then vHigh else if PMhrs then Max(vHigh, PMHigh[1]) else PMHigh[1], 0);
def PMLow = CompoundValue(1, if PMStart then vLow else if PMhrs then Min(vLow, PMLow[1]) else PMLow[1], 0);
def highBar = if PMhrs and vHigh == PMHigh then bar else nan;
def lowBar = if PMhrs and vLow == PMLow then bar else nan;
def PMHighBar = if bar == HighestAll(highBar) then PMHigh else PMHighBar[1];
def PMLowBar = if bar == HighestAll(lowBar) then PMLow else PMLowBar[1];

plot PMH =  if PlotPreMktLinesHrsPastOpen and PMHighBar != 0
            then PMHighBar
            else nan;
plot PML =  if PlotPreMktLinesHrsPastOpen and PMLowBar != 0
            then PMLowBar
            else nan;

AddChartBubble(ShowChartBubbles and bar == HighestAll(highBar),
  "PM High",

AddChartBubble(ShowChartBubbles and bar == HighestAll(lowBar),
  "PM Low",


# end of script


Agreed. This is terrific @tradebyday and thank you.

TWO follow-up questions.

1 - Can we change the time frame? Like, maybe have it paint at 915 or 900?

2 - Do you think there is a way to turn it into a scan?

Something to alert and say:
A) "These stocks just crossed the PM High or PM Low"
B) "These stocks just moved away from the PM High by 10%"

That way, we could see if things are going nuts before the open as a possible opportunity.


Active member
I will let someone else tag in for those changes, this was not my code, but modified it to have the cloud as requested. I am not too familiar wit setting up scans personally as I do not use them myself

Similar threads