Yesterday's and Premarket High/Low

Batman

Member
What would be the code for a scan that shows a line for yesterday's high/low and premarket high/low? I've found similar scans, but they all include bells and whistles that I do not want, like Fib retracement levels and candlestick coloring, and I mess up the code when I try to edit the extra stuff out. I would just want to have four simple grey lines, indicating yesterday's and premarket high/low.
 
Solution
ohlc.png


Code:
#Svanoy 
#Previous_Days_H_O_L_C w/premarket H_L
#Previous days High, Open, Close, and Low w/premarket High and Low.

input sPeriod = {default DAY};
def varhigh = high(period = sPeriod)[1];
def varlow = low(period = sPeriod)[1];
def varopen = open(period = sPeriod)[1];
def varclose = close(period = sPeriod)[1];
def premarketopen = 0400;
def premarketclose = 0930;
def premarket = secondsFromTime(premarketopen)>=0 and secondsTillTime(premarketclose)>0;

def premarkethigh;
if secondsFromTime(premarketopen)==0 {
premarkethigh = high;
}else if premarket and high>=premarkethigh[1]{
premarkethigh = high;
}else{
premarkethigh = premarkethigh[1];}

def premarketlow;
if secondsFromTime(premarketopen)==0 {
premarketlow = low;
}else...
ohlc.png


Code:
#Svanoy 
#Previous_Days_H_O_L_C w/premarket H_L
#Previous days High, Open, Close, and Low w/premarket High and Low.

input sPeriod = {default DAY};
def varhigh = high(period = sPeriod)[1];
def varlow = low(period = sPeriod)[1];
def varopen = open(period = sPeriod)[1];
def varclose = close(period = sPeriod)[1];
def premarketopen = 0400;
def premarketclose = 0930;
def premarket = secondsFromTime(premarketopen)>=0 and secondsTillTime(premarketclose)>0;

def premarkethigh;
if secondsFromTime(premarketopen)==0 {
premarkethigh = high;
}else if premarket and high>=premarkethigh[1]{
premarkethigh = high;
}else{
premarkethigh = premarkethigh[1];}

def premarketlow;
if secondsFromTime(premarketopen)==0 {
premarketlow = low;
}else if premarket and low<=premarketlow[1]{
premarketlow = low;
}else{
premarketlow = premarketlow[1];}


def pmh = fold ipmh = 0 to 1 while !IsNaN(close[10]) do premarkethigh;
def pml = fold ipml = 0 to 1 while !IsNaN(close[10]) do premarketlow;
def h = fold ih = 0 to 1 while !IsNaN(close[10]) do varhigh;
def l = fold il = 0 to 1 while !IsNaN(close[10]) do varlow;
def o = fold io = 0 to 1 while !IsNaN(close[10]) do varopen;
def c = fold ic = 0 to 1 while !IsNaN(close[10]) do varclose;

plot PMHigh = if pmh > 1 and !premarket then pmh else Double.NaN;
PMHigh.SetPaintingStrategy(PaintingStrategy.DASHES);
PMHigh.SetDefaultColor(Color.LIME);

plot PMLow = if pml > 1 and !premarket then pml else Double.NaN;
PMLow.SetPaintingStrategy(PaintingStrategy.DASHES);
PMLow.SetDefaultColor(Color.PINK);

plot DayHigh = if h > 1 then h else Double.NaN;
DayHigh.SetPaintingStrategy(PaintingStrategy.DASHES);
DayHigh.SetDefaultColor(Color.LIGHT_GREEN);

plot DayLow = if l > 1 then l else Double.NaN;
DayLow.SetPaintingStrategy(PaintingStrategy.DASHES);
DayLow.SetDefaultColor(Color.LIGHT_RED);

plot DayOpen = if o > 1 then o else Double.NaN;
DayOpen.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DayOpen.AssignValueColor(if varopen >= varclose then Color.GREEN else Color.RED);

plot DayClose = if c > 1 then c else Double.NaN;
DayClose.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DayClose.AssignValueColor(if varopen >= varclose then Color.RED else Color.GREEN);

AddChartBubble(IsNaN(PMHigh) and IsNaN(close),pmh[1],"PreMarket High",Color.WHITE,yes);
AddChartBubble(IsNaN(PMLow) and IsNaN(close),pml[1],"PreMarket Low",Color.WHITE,no);
AddChartBubble(IsNaN(DayHigh),h[1],"Prev Day High",Color.WHITE,yes);
AddChartBubble(IsNaN(DayLow),l[1],"Prev Day Low",Color.WHITE,no);
AddChartBubble(IsNaN(DayOpen),o[1],"Prev Day Open",Color.WHITE,if o>=c then yes else no);
AddChartBubble(IsNaN(DayClose),c[1],"Prev Day Close",Color.WHITE, if o>=c then no else yes);
 
Solution
I am having issues with this code.
1) I want the premarket high and low levels.
2) For the time, I have set 0400 and 0930.
3) I want my chart interval set to "Today"
The issue I am having; if premarket trading for a specific stock starts after 4am, it will not show the levels because I have my chart interval to "Today".
Any work arounds?
Code:
input openingTime = 0400;
input closingTime = 0930;

def sec1    = SecondsFromTime(openingTime);
def sec2    = SecondsFromTime(closingTime);
def isTime1 = (sec1 >= 0 and sec1[1] < 0) or (sec1 < sec1[1] and sec1 >= 0);
def isTime2 = (sec2 >= 0 and sec2[1] < 0) or (sec2 < sec2[1] and sec2 >= 0);
def inRange = CompoundValue(1, if isTime1 then 1 else if isTime2 then 0 else inRange[1], 0);

def rhi        = if inRange and !inRange[1]
                 then high
                 else if inRange[1] and high > rhi[1]
                 then high else rhi[1];
def rHighBar   = if inRange and high == rhi then BarNumber() else Double.NaN;
def rHighest   = if BarNumber() == HighestAll(rHighBar)  then rhi else rHighest[1];

plot rangehigh = if (rHighest > 0) then rHighest else Double.NaN;
rangehigh.setpaintingStrategy(paintingStrategy.HORIZONTAL);
rangehigh.setlineWeight(2);

def rlow       = if inRange and !inRange[1]
                 then low
                 else if inRange[1] and low < rlow[1]
                 then low else rlow[1];
def rLowBar    = if inRange and low == rlow then BarNumber() else Double.NaN;
def rlowest    = if BarNumber() == HighestAll(rLowBar) then rlow else rlowest[1];

plot rangelow  = if (rlowest > 0) then rlowest else Double.NaN;
rangelow.setpaintingStrategy(paintingStrategy.HORIZONTAL);
rangelow.setlineWeight(2);
 
If you just want the daytime high/low, and keeping it simple:

Ruby:
declare once_per_bar;

plot PreviousDayHigh = if  IsNaN(hlc3(period = AggregationPeriod.DAY)[-1])
    then  high(period = AggregationPeriod.DAY)[1]
    else Double.NaN;

plot PreviousDayLow = if  IsNaN(hlc3(period = AggregationPeriod.DAY)[-1])
    then  low(period = AggregationPeriod.DAY)[1]
    else Double.NaN;

As a bonus it only draws the lines for the last day.
 
This shows the previous day high and low even when we select “today” timeframe?

If you just want the daytime high/low, and keeping it simple:

Ruby:
declare once_per_bar;

plot PreviousDayHigh = if  IsNaN(hlc3(period = AggregationPeriod.DAY)[-1])
    then  high(period = AggregationPeriod.DAY)[1]
    else Double.NaN;

plot PreviousDayLow = if  IsNaN(hlc3(period = AggregationPeriod.DAY)[-1])
    then  low(period = AggregationPeriod.DAY)[1]
    else Double.NaN;

As a bonus it only draws the lines for the last day.
 
Anyone have this for the week instead of the day? I tried altering the script by changing it to "week" every time it said "day", but it didn't work haha.
 
Anyone have this for the week instead of the day? I tried altering the script by changing it to "week" every time it said "day", but it didn't work haha.

Code:
#https://www.reddit.com/r/thinkorswim/comments/lpyivt/previous_day_high_low_close_indicator/


input timeFrame = {default Day, Week, Month, Quarter, Year};

plot High = high(period = timeFrame)[1];

plot Low = low(period = timeFrame)[1];

plot Close = close(period = timeFrame)[1];

High.SetDefaultColor (Color.GREEN);

High.SetPaintingStrategy(PaintingStrategy.DASHES);

Low.SetDefaultColor(Color.RED);

Low.SetPaintingStrategy(PaintingStrategy.DASHES);

Close.SetDefaultColor (Color.GRAY);

Close.SetPaintingStrategy(PaintingStrategy.DASHES);
 
Thanks bredren. Any way to make it so levels extend to the week it's displaced by, instead of just showing on the current day?
I am sorry my friend; I am not good at coding so I would not know how to do that.

I have a suggestion - on Reddit, there is a gentleman called Mobius_TS, who is a legend with ThinkScript. You may try asking him directly on Reddit; he is very active there.

My best to you.
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
329 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top