Previous Day High/Low/Close For ThinkOrSwim

thanks for the response! this is close to what i want but do not want the lines to stay on the graph for older days, or if they do stay there maybe only during the market hours portion so it is just straight lines. dont want a crowded graph if i zoom out a couple of days
Update: 2nd thought i probably just want them on for today and all old days dissapear
 
I need something very simple and basic. Can I get a auto fib line drawn for the previous day high and low at 50%. Also known as the Half Candle Retracement. Muchas Gracias.
 
I need something very simple and basic. Can I get a auto fib line drawn for the previous day high and low at 50%. Also known as the Half Candle Retracement. Muchas Gracias.
Try this. It allows you to plot previous selectable days H, L, and/or HL2

Screenshot-2021-08-18-115546.jpg
Ruby:
input Day = 1;
input showplot = {Default HL2, H, L, All};
input lineweight = 2;

def DH    = high;
def DL    = low;
def bar   = BarNumber();
def na    = Double.nan;
def Today = GetDay() == GetLastDay() - Day and SecondsFromTime(0930);

def Dayhigh    = if Today and !Today[1] then DH else if Today[1] and DH > Dayhigh[1] then DH else Dayhigh[1];
def DayHighBar = if Today and DH == Dayhigh then bar else Double.NaN;
def DayHighest = if BarNumber() == HighestAll(DayHighBar)  then Dayhigh else DayHighest[1];

def Daylow    = if Today and !Today[1] then dl else if Today[1] and dl < Daylow[1] then low else Daylow[1];
def DaylowBar = if Today and dl == Daylow then bar else Double.NaN;
def Daylowest = if BarNumber() == HighestAll(DaylowBar)  then Daylow else Daylowest[1];


plot DayHigh1 = if (DayHighest > 0) then DayHighest else Double.NaN;
plot Daylow1  = if (Daylowest > 0) then Daylowest else Double.NaN;
plot DayHL2   = (DayHigh1 + Daylow1)/2;

DayHigh1.sethiding(showplot==showplot.L or showplot==showplot.HL2);
Daylow1.sethiding(showplot==showplot.H or showplot==showplot.HL2);
DayHL2.sethiding(showplot==showplot.H or showplot==showplot.L);
DayHigh1.setdefaultColor(color.green);
daylow1.setdefaultColor(color.red);
dayhl2.setdefaultColor(color.white);
DayHigh1.setlineWeight(lineweight);
daylow1.setlineWeight(lineweight);
dayhl2.setlineWeight(lineweight);
 
I know that time values are frequently used to start and end plots but is there a way to plot something like a moving average or cumulative volume from the low or high of the prior day up to today only? Thanks in advance.
 
Yes, you can limit how many periods back from the current period plots are drawn. The way I do this is by checking to see if there's data for a future candle. If not, then don't draw anything.

Ruby:
input periodsToShow = 5;
def ema21 = ExpAverage(close, 21);
plot EMA = if IsNaN(close[-periodsToShow]) then ema21 else Double.NaN;
 
Yes, you can limit how many periods back from the current period plots are drawn. The way I do this is by checking to see if there's data for a future candle. If not, then don't draw anything.

Ruby:
input periodsToShow = 5;
def ema21 = ExpAverage(close, 21);
plot EMA = if IsNaN(close[-periodsToShow]) then ema21 else Double.NaN;
Excellent! Thanks! In this example I think the last line was meant to be the following:
Ruby:
plot EMA = if IsNaN(close[-periodsToShow]) then Double.Nan else ema21;
 
Excellent! Thanks! In this example I think the last line was meant to be the following:
Ruby:
plot EMA = if IsNaN(close[-periodsToShow]) then Double.Nan else ema21;
what slippage has listed is correct.
when the code looks at 'periodsToShow' bars in the future and finds a nan value, then it starts to draw a line.
 
I know that time values are frequently used to start and end plots but is there a way to plot something like a moving average or cumulative volume from the low or high of the prior day up to today only? Thanks in advance.
sure. if you can define some point in time by a formula, then you can use it in other formulas.

summary of one way,
if you want to plot from the 2nd to last day, reference your variable offsets from that day.
..find the high of a day, while looking at future bars to see if it is 2nd to last day.
..save the barnumber of when the day high occurred.
..if barnumber > barnumber of the high, then plot stuff
 
sure. if you can define some point in time by a formula, then you can use it in other formulas.

summary of one way,
if you want to plot from the 2nd to last day, reference your variable offsets from that day.
..find the high of a day, while looking at future bars to see if it is 2nd to last day.
..save the barnumber of when the day high occurred.
..if barnumber > barnumber of the high, then plot stuff
I am just trying to get the intraday High and Low Label during the trading day that
reflects the most recent intraday high and low. Attached was my attempt.
Please advise!
# Intraday_High_Low
def High: == high(period(0) = "dayhigh" );
def Low: == low(period(0), = "daylow" );

AddLabel (Show_"dayHigh"; dayHigh[0],color.green);
AddLabel (Show_"dayLow"; dayLow[0], color.red);
 
I know that time values are frequently used to start and end plots but is there a way to plot something like a moving average or cumulative volume from the low or high of the prior day up to today only? Thanks in advance.

Here is another example. It limits the plotting of the exponential moving average to beginning at the high of the previous day to the beginning of regular trading hours of the current day

Screenshot-2021-08-22-094135.jpg
Ruby:
def ema = ExpAverage(close, 9);
def DH    = high;
def bar   = BarNumber();
input Day = 1;
def Today = GetDay() == GetLastDay() - Day and SecondsFromTime(0930);
def Dayhigh    = if Today and !Today[1] then DH else if Today[1] and DH > Dayhigh[1] then DH else Dayhigh[1];
def DayHighBar = if Today and DH == Dayhigh then bar else Double.NaN;
def DayHighest = if BarNumber() == HighestAll(DayHighBar)  then Dayhigh else DayHighest[1];

plot emalimit = if BarNumber() < HighestAll(DayHighBar) or (GetDay() == GetLastDay() and SecondsFromTime(0930) > 0) then Double.NaN else ema;

input debug   = yes;
plot DayHigh1 = if debug and (DayHighest > 0) then DayHighest else Double.NaN;
 
I am just trying to get the intraday High and Low Label during the trading day that
reflects the most recent intraday high and low. Attached was my attempt.
Please advise!
# Intraday_High_Low
def High: == high(period(0) = "dayhigh" );
def Low: == low(period(0), = "daylow" );

AddLabel (Show_"dayHigh"; dayHigh[0],color.green);
AddLabel (Show_"dayLow"; dayLow[0], color.red);
This is my latest attempt to get the intraday High and Low Label during the trading day that

reflects the most recent intraday high and low. Attached was my attempt.

Highs are correct Lows are not Please advise!

# Intraday_High_Low

AddLabel(1, "Intraday High: "+ Highestall(high), color.green);
AddLabel(1, "Intraday Low: "+ lowestAll(low), color.red);
 
This is my latest attempt to get the intraday High and Low Label during the trading day that

reflects the most recent intraday high and low. Attached was my attempt.

Highs are correct Lows are not Please advise!

# Intraday_High_Low

AddLabel(1, "Intraday High: "+ Highestall(high), color.green);
AddLabel(1, "Intraday Low: "+ lowestAll(low), color.red);

So that each day's plots of intraday information is more easily available, I have found the following code useful. You can adjust the beginning and ending timeframes for most options. I have posted it in response to other similar request recently.

Screenshot-2021-08-15-063228.jpg
Ruby:
input afterbegin = 0930;
input afterend   = 1600;
def aftermarket =  SecondsFromTime(afterbegin) >= 0 and SecondsTillTime(afterend) >= 0;
def bars   = 2000;

input pricePerRowHeightMode = { AUTOMATIC, default TICKSIZE, CUSTOM};
input customRowHeight = 1.0;
input timePerProfile = {default BAR};
input onExpansion = no;
input profiles = 1000;

def period;

switch (timePerProfile) {
case BAR:
    period = BarNumber() - 1;
}


def count = CompoundValue(1, if aftermarket and period != period[1] then (count[1] + period - period[1]) % bars else count[1], 0);
def cond = count < count[1] + period - period[1];
def height;
switch (pricePerRowHeightMode) {
case AUTOMATIC:
    height = PricePerRow.AUTOMATIC;
case TICKSIZE:
    height = PricePerRow.TICKSIZE;
case CUSTOM:
    height = customRowHeight;
}

profile vol = VolumeProfile("startNewProfile" = cond, "onExpansion" = no, "numberOfProfiles" = 1000, "pricePerRow" = height, "value area percent" = 0);
def con = CompoundValue(1, onExpansion, no);

def hProfile = if aftermarket and IsNaN(vol.GetHighest()) and con then hProfile[1] else vol.GetHighest();
def lProfile = if aftermarket and IsNaN(vol.GetLowest()) and con then lProfile[1] else vol.GetLowest();
def plotsDomain = IsNaN(close) == onExpansion;
def ProfileHigh = if aftermarket and plotsDomain then hProfile else Double.NaN;
def ProfileLow = if aftermarket and plotsDomain then lProfile else Double.NaN;

plot hrange = ProfileHigh;
plot lrange = ProfileLow;
hrange.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
lrange.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
hrange.SetDefaultColor(Color.GREEN);
lrange.SetDefaultColor(Color.RED);
hrange.SetLineWeight(2);
lrange.SetLineWeight(2);

input bubblemover = 0;
def b  = bubblemover;
def b1 = b + 1;


input showbubbles = yes;
AddChartBubble(showbubbles and (IsNaN(hrange[b1]) and hrange[b])  , hrange, AsText(hrange), Color.LIGHT_GREEN);
AddChartBubble(showbubbles and (IsNaN(hrange[b1]) and hrange[b]) , lrange, AsText(lrange), Color.LIGHT_RED, up = no);

input showverticalline = yes;
AddVerticalLine(showverticalline and hrange != hrange[1], "", Color.BLUE, stroke = Curve.FIRM);
 
I mean I’m looking for stocks that are continually opening higher than the previous day‘s close. Like every day it will open higher than close of the day before. I used 20 days because I wanted to see that pattern for a consecutive period not just one day, but for a longer period.
 
Last edited by a moderator:
Hello, Is there is script that sound alerts you when candle crosses over or below previous Day High/Low/Close on the chart you are currently on. Sometimes you have multiple charts open and it would be nice to get an alert if a stock just touched one of these levels.
I have this script and I need to set an alert every time bar crosses the levels.


#Study:Common Level
#by thetrader.top
declare hide_on_daily;
declare once_per_bar;

input timeFrame = {default DAY, WEEK, MONTH};

plot high = If(GetAggregationPeriod() <= AggregationPeriod.FIFTEEN_MIN, high(period = timeFrame)[1], Double.NaN);
plot Low = If(GetAggregationPeriod() <= AggregationPeriod.FIFTEEN_MIN, low(period = timeFrame)[1], Double.NaN);
plot Close = If(GetAggregationPeriod() <= AggregationPeriod.FIFTEEN_MIN, close(period = timeFrame)[1], Double.NaN);

high.SetDefaultColor (Color.GREEN);
high.SetPaintingStrategy(PaintingStrategy.DASHES);
Low.SetDefaultColor(Color.RED);
Low.SetPaintingStrategy(PaintingStrategy.DASHES);
Close.SetDefaultColor (Color.GRAY);
Close.SetPaintingStrategy(PaintingStrategy.DASHES);
 
Last edited:
How can I compare the last/mark price with yesterday's close price?

I currently have this in thinkScript Editor but would like it in real-time using


close is greater than close from 1 bar ago

would like something like this

input price = pricetype.MARK;
plot scan = price is greater than close [1];
 
Can someone help me write a script to find stocks with the high of today within 5% of the high of two days ago?
I have zero knowledge of TOS script language.
Thank you
 
Pullback: Scan For 20% Down For Yesterday's High
  • Save the below study in the study tab
  • In the scanner, select the name of the study
  • Under plot: select scan is true
Ruby:
# Previous Day Scan
# Assembled by @MerryDay at UseThinkScript.com

input percent = 0.20 ;
input aggregationPeriod = AggregationPeriod.DAY;

def prevhigh = high(period = aggregationPeriod)[1];
def pullback = high - (high * percent) ;

plot highLine = highestAll(if isNaN(close[-1]) then prevhigh else Double.NaN);
plot pullback_line = highestAll(if isNaN(close[-1]) then pullback else Double.NaN);

highLine.SetLineWeight(2);
highLine.SetDefaultColor(color.blue) ;
pullback_line.SetLineWeight(2);
pullback_line.SetDefaultColor(color.blue) ;

plot scan = close <= pullback ;
scan.hide();

AddLabel(yes, Concat("Prev High = ", prevhigh), color.blue);
AddLabel(yes, Concat("Pullback = ", round(pullback,2)), color.blue);
# End Code
EQEfTBf.png

Screenshot (85).png

@Drmoh1800
 
Last edited:

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
357 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