Previous Day High/Low/Close

generic

Active member
@iselloptions This is what I use, you can split the script into 2 if you want.
Code:
# TS_GlobexRange
# http://thinkscripter.wordpress.com
# [email protected]
# Last Update 18 JUL 2009

declare once_per_bar;
declare hide_on_daily;

def Globex_Open = 1630;
def Globex_Close = 0930;

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();

# Previous day HiLo
plot hi = high(period = AggregationPeriod.DAY)[1];
hi.HideBubble();
hi.HideTitle();
plot lo = low(period = AggregationPeriod.DAY)[1];
lo.HideBubble();
lo.HideTitle();
 

iselloptions

New member
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
 

sandya61

New member
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.
 

Slippage

Well-known member
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;
 

sandya61

New member
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;
 

halcyonguy

Active member
VIP
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.
 

halcyonguy

Active member
VIP
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
 

QUIKTDR1

Member
VIP
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);
 

SleepyZ

Well-known member
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;
 

QUIKTDR1

Member
VIP
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);
 

SleepyZ

Well-known member
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);
 

Jacque

New member
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:

AlexeyMironenko

New member
VIP
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:

ramzee15

New member
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];
 

antonio

New member
VIP
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
 

Lyled7

New member
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
 

Similar threads

Top