Previous Day High/Low/Close For ThinkOrSwim

I know there are several posts about this, but i can't seem to put all of the codes together and make it work.

I'm looking to plot the previous day high and then create a scanner using a 2min time frame that alerts me when a stock has broken above the previous day high. Can someone please help me with this?

I'm currently using the TOS built in study "dailyhighlow" which does a great job of plotting a reference line. But i can't seem to make the scanner work b/c of the "aggregation period" error.

thanks
 
I know there are several posts about this, but i can't seem to put all of the codes together and make it work.

I'm looking to plot the previous day high and then create a scanner using a 2min time frame that alerts me when a stock has broken above the previous day high. Can someone please help me with this?

I'm currently using the TOS built in study "dailyhighlow" which does a great job of plotting a reference line. But i can't seem to make the scanner work b/c of the "aggregation period" error.

thanks
The following script in the code below seems to work on testing (501 hits just a few minutes ago) using a 2m scan setting.

Ruby:
def ymd         = GetYYYYMMDD();
def capture     = !IsNaN(close) and ymd != ymd[1];
def dayCount    = CompoundValue(1, if capture then dayCount[1] + 1 else dayCount[1], 0);
def pd          = (HighestAll(dayCount) - dayCount)  ;
def ph          = if pd==1 and secondsfromTime(0930) == 0
                  then high
                  else if pd==1 and secondsTillTime(1600) > 0
                  then max(high, ph[1])
                  else ph[1];
plot scan       = pd == 0 and secondstillTime(1600) > 0 and close crosses above ph;

You can use this grid to test the scan on charts. https://tos.mx/k9BDX1v

Capture.jpg
 
The following script in the code below seems to work on testing (501 hits just a few minutes ago) using a 2m scan setting.



You can use this grid to test the scan on charts. https://tos.mx/k9BDX1v
Thanks. So how would i set up a scanner using this code? Would i enter a new study in my scan and do something like "when close crossed above StudyName"?
 
Can someone help me with the code below just like how i am getting previous day close, open i want globex as well. I added globex but its putting a line for previous days and no labels are showing. Please make Globex look like previous day close, open, hight etc. Thanks!
Ruby:
def NA = Double.NaN;

input agg = AggregationPeriod.DAY;
input showOnlyLastPeriod = no;
input showBubbles = yes;
input showValuesInBubbles = yes;
input spaceBetween = 1;
plot currentOpen;
plot prevDayClose;
plot prevDayLow;
plot prevDayHigh;
def exp = IsNaN(close[spaceBetween]);

currentOpen = if exp then open("period"=agg) else NA;
prevDayClose = if exp then close("period"=agg)[1] else NA;
prevDayLow = if exp then low("period"=agg)[1] else NA;
prevDayHigh = if exp then high("period"=agg)[1] else NA;

AddChartBubble(showBubbles, if IsNaN(currentOpen[1]) and !IsNaN(currentOpen) then currentOpen else NA, if showValuesInBubbles then "CurrOpen $"+currentOpen else "CurrOpen", Color.WHITE, yes);
AddChartBubble(showBubbles, if IsNaN(prevDayClose[1]) and !IsNaN(prevDayClose) then prevDayClose else NA, if showValuesInBubbles then "PrevClose $"+prevDayClose else "PrevClose", Color.YELLOW, yes);
AddChartBubble(showBubbles, if IsNaN(prevDayLow[1]) and !IsNaN(prevDayLow) then prevDayLow else NA, if showValuesInBubbles then "PrevLow $"+prevDayLow else "PrevLow", Color.RED, yes);
AddChartBubble(showBubbles, if IsNaN(prevDayHigh[1]) and !IsNaN(prevDayHigh) then prevDayHigh else NA, if showValuesInBubbles then "PrevHigh $"+prevDayHigh else "PrevHigh", Color.GREEN, yes);

currentOpen.SetDefaultColor(Color.WHITE);
prevDayLow.SetDefaultColor(Color.RED);
prevDayHigh.SetDefaultColor(Color.GREEN);
prevDayClose.SetDefaultColor(Color.YELLOW);
currentOpen.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
prevDayLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
prevDayHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
prevDayClose.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

declare once_per_bar;
declare hide_on_daily;

def Globex_Open = 1630;
def Globex_Close = 0930;

def today = GetDay() == GetLastDay();

#change plots to if today then globexhigh else double.nan;

def h = high;
def l = low;
def globexOpen = secondsFromTime(Globex_Open) >= 0 or secondsTillTime(Globex_Close)>0;
def globexReset = globexOpen and !globexOpen[1];


def globexHigh = compoundValue(1, if((h > globexHigh[1] and globexOpen) or globexReset, h, globexHigh[1]), h);
def globexLow = compoundValue(1, if((l < globexLow[1] and globexOpen) or globexReset, l, globexLow[1]), l);


plot Globex_High = globexHigh;
Globex_High.HideBubble();
Globex_High.HideTitle();
plot Globex_Low = globexLow;
Globex_Low.HideBubble();
Globex_Low.HideTitle();
 
Last edited by a moderator:
Thanks. So how would i set up a scanner using this code? Would i enter a new study in my scan and do something like "when close crossed above StudyName"?
Just copy the scan code in post #100 below into the thinkscript editor

Capture.jpg
Ruby:
def ymd         = GetYYYYMMDD();
def capture     = !IsNaN(close) and ymd != ymd[1];
def dayCount    = CompoundValue(1, if capture then dayCount[1] + 1 else dayCount[1], 0);
def pd          = (HighestAll(dayCount) - dayCount)  ;
def ph          = if pd==1 and secondsfromTime(0930) == 0
                  then high
                  else if pd==1 and secondsTillTime(1600) > 0
                  then max(high, ph[1])
                  else ph[1];
plot scan       = pd == 0 and secondstillTime(1600) > 0 and close crosses above ph;
 

I want to add a customized version of the Net Change/Net Percent quotes to my watchlists that use the dailyopen price instead of the prior session's closing price as the input.

Is there a way to view/copy/edit/paste the code from ToS's standard quotes? If I can copy/edit the standard Net Change code to change the inputs, that would be helpful.

Thanks.
 
Last edited by a moderator:
Does anyone know of a scan that is set up on a 5min time frame that alters when price close above the previous day. I know there is one that you can use for the first 5 minutes and is was built by Robert Payne.

I am looking for a scan that runs throughout the day for and stock where the price crosses the previous high/low of day on a 5 min timeframe.
 
I am trying to write a script that scans for stocks who's current price is above yesterday's high. That seems like it should be a simple script, but I can't seem to figure it out. I tried searching for scripts but no luck. Thanks.
 
The following script in the code below seems to work on testing (501 hits just a few minutes ago) using a 2m scan setting.



You can use this grid to test the scan on charts. https://tos.mx/k9BDX1v
Is there a way to scan for stocks that have a moving average line cross the previous day high? So for example, a 21 day exponential moving average line?
 
Is there a way to scan for stocks that have a moving average line cross the previous day high? So for example, a 21 day exponential moving average line?

ExpAverage(close, 21) crosses high[1]
 
high[1] is the definition of the previous day high.
Please provide a screen grab of a chart that highlight the plots you are looking for and illustrate the crossover that you want to scan.

Unsure of how to upload screenshots to the forum, Here are directions.
 
I am trying to put this into 1 or 2 min scan and I get an error saying that secondary period not allowed: day

Requirement: Find the ticket that current candle high crosses the high in first 15 mins and open is greater than yesterday close.

Code:
input ORBegin = 0930;
input OREnd = 0945;
def ORActive = if SecondsTillTime(OREnd) > 0 and SecondsFromTime(ORBegin) >= 0 then 1 else 0;
rec ORHigh = if ORHigh[1] == 0 or ORActive[1] == 0 and ORActive == 1 then high else if ORActive and high > ORHigh[1] then high else ORHigh[1];
def Yclose = close(period = "day" )[1];
plot breakOpen = if (high crosses above ORHigh and open > Yclose)  then 1 else 0;

Is this the right way to put as a scan to fit my requirement?
 
Last edited:
Try this. It allows you to plot previous selectable days H, L, and/or HL2
This is great I have been looking for something like this! A couple of questions for you:

Is there a reason it does not plot the high and lows for the day? I see that it is coded for highs and lows to show up as green and red, and I would love to be able to have them too if possible.

Also, it looks like I can only get it to display on intraday charts, how would I have this display on daily timeframes?

How could I get this do to the same thing for weekly or monthly candles?

Thanks again!!
 

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
366 Online
Create Post

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