Previous Days High, Low, Open, Close, and High/Low of defined timeframe For ThinkOrSwim

Svanoy

Expert
VIP
Lifetime
@jonshank62
AnGOGMS.png

Code:
#plots high and low of defined timeframe.
#Inputs for periodstart and periodend have to be start times for bars of the aggregation period used on chart.

input periodstart = 1515;
input periodend = 1600;
def activeperiod = If secondsFromTime(periodstart)>=0 and secondsTillTime(periodend)>0 then yes else Double.NaN;
def acriveperiodstartbar = if secondsFromTime(periodstart)==0 then barnumber() else acriveperiodstartbar[1];
def activeperiodendbar = fold i=0 to AbsValue(BarNumber()) while !IsNaN(GetValue(activeperiod,-i)) do GetValue(BarNumber(),-i);
def activeperiodlength = 1+(activeperiodendbar-acriveperiodstartbar);

def activeperiodhigh;
if secondsFromTime(periodstart)==0 {
activeperiodhigh = high;
}else if !IsNaN(activeperiod) and high>=activeperiodhigh[1]{
activeperiodhigh = high;
}else{
activeperiodhigh = activeperiodhigh[1];}

def activeperiodlow;
if secondsFromTime(periodstart)==0 {
activeperiodlow = low;
}else if !IsNaN(activeperiod) and low<=activeperiodlow[1]{
activeperiodlow = low;
}else{
activeperiodlow = activeperiodlow[1];}

def activephigh = fold iah=0 to AbsValue(activeperiodlength) while !IsNaN(activeperiod) do GetValue(activeperiodhigh,-iah);
def activeplow = fold ial=0 to AbsValue(activeperiodlength) while !IsNaN(activeperiod) do GetValue(activeperiodlow,-ial);
def aph = fold iaph = 0 to 1 while !IsNaN(close[10]) do activeperiodhigh;
def apl = fold iapl = 0 to 1 while !IsNaN(close[10]) do activeperiodlow;

plot ActiveHigh = if !IsNaN(activeperiod) and activephigh>0 then activephigh else Double.NaN;
ActiveHigh.SetPaintingStrategy(PaintingStrategy.LINE);
ActiveHigh.SetDefaultColor(Color.LIME);

plot ActiveLow = if !IsNaN(activeperiod) and activeplow>0 then activeplow else Double.NaN;
ActiveLow.SetPaintingStrategy(PaintingStrategy.LINE);
ActiveLow.SetDefaultColor(Color.PINK);

plot APHigh = if IsNaN(activeperiod) and aph>0 then aph else Double.NaN;
APHigh.SetPaintingStrategy(PaintingStrategy.DASHES);
APHigh.SetDefaultColor(Color.LIME);

plot APLow = if IsNaN(activeperiod) and apl>0 then apl else Double.NaN;
APLow.SetPaintingStrategy(PaintingStrategy.DASHES);
APLow.SetDefaultColor(Color.PINK);

AddCloud(ActiveHigh,ActiveLow,color.LIGHT_GRAY,color.LIGHT_GRAY);
 

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

@SJP07
Code:
#Shows previous days High, Low, Open, Close, and High/Low of defined timeframe defaulted to premarket hours.
#Code by Svanoy

input Show_High = No;
input Show_Low = No;
input Show_Open = No;
input Show_Close = Yes;
input Show_Premarket_High_and_Low = No;

input sPeriod = {default DAY};
def offset = 1;

def Today = if GetDay()==GetLastDay() then 1 else 0;
def varhigh = high(period = sPeriod)[offset];
def varlow = low(period = sPeriod)[offset];
def varopen = open(period = sPeriod)[offset];
def varclose = close(period = sPeriod)[offset];
def periodstart = 0400;
def periodend = 0930;
def activeperiod = If secondsFromTime(periodstart)>=0 and secondsTillTime(periodend)>0 then yes else Double.NaN;
def acriveperiodstartbar = if secondsFromTime(periodstart)==0 then barnumber() else acriveperiodstartbar[1];
def activeperiodendbar = fold i=0 to AbsValue(BarNumber()) while !IsNaN(GetValue(activeperiod,-i)) do GetValue(BarNumber(),-i);
def activeperiodlength = 1+(activeperiodendbar-acriveperiodstartbar);

def activeperiodhigh;
if secondsFromTime(periodstart)==0 {
activeperiodhigh = high;
}else if !IsNaN(activeperiod) and high>=activeperiodhigh[1]{
activeperiodhigh = high;
}else{
activeperiodhigh = activeperiodhigh[1];}

def activeperiodlow;
if secondsFromTime(periodstart)==0 {
activeperiodlow = low;
}else if !IsNaN(activeperiod) and low<=activeperiodlow[1]{
activeperiodlow = low;
}else{
activeperiodlow = activeperiodlow[1];}

def activephigh = fold iah=0 to AbsValue(activeperiodlength) while !IsNaN(activeperiod) do GetValue(activeperiodhigh,-iah);
def activeplow = fold ial=0 to AbsValue(activeperiodlength) while !IsNaN(activeperiod) do GetValue(activeperiodlow,-ial);
def aph = fold iaph = 0 to 1 while !IsNaN(close[10]) do activeperiodhigh;
def apl = fold iapl = 0 to 1 while !IsNaN(close[10]) do activeperiodlow;
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 PreHigh = if !IsNaN(activeperiod) and activephigh>0 then activephigh else Double.NaN;
PreHigh.SetPaintingStrategy(PaintingStrategy.LINE);
PreHigh.SetDefaultColor(Color.LIME);
PreHigh.SetHiding(!Show_Premarket_High_and_Low);
 
plot PreLow = if !IsNaN(activeperiod) and activeplow>0 then activeplow else Double.NaN;
PreLow.SetPaintingStrategy(PaintingStrategy.LINE);
PreLow.SetDefaultColor(Color.PINK);
PreLow.SetHiding(!Show_Premarket_High_and_Low);

plot PMHigh = if IsNaN(activeperiod) and aph>0 then aph else Double.NaN;
PMHigh.SetPaintingStrategy(PaintingStrategy.DASHES);
PMHigh.SetDefaultColor(Color.LIME);
PMHigh.SetHiding(!Show_Premarket_High_and_Low);

plot PMLow = if IsNaN(activeperiod) and apl>0 then apl else Double.NaN;
PMLow.SetPaintingStrategy(PaintingStrategy.DASHES);
PMLow.SetDefaultColor(Color.PINK);
PreLow.SetHiding(!Show_Premarket_High_and_Low);

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

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

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);
DayOpen.SetHiding(!Show_Open);

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);
DayClose.SetHiding(!Show_Close);

AddChartBubble(IsNaN(PreHigh[1]) and !IsNaN(PreHigh) and Show_Premarket_High_and_Low,PreHigh,"PreMarket High",Color.WHITE,yes);
AddChartBubble(IsNaN(PreLow[1]) and !IsNaN(PreLow) and Show_Premarket_High_and_Low,PreLow,"PreMarketLow",Color.WHITE,no);
AddChartBubble(DayHigh!=DayHigh[1] and !IsNaN(close) and Show_High,h,"PrevDayHigh",Color.WHITE,yes);
AddChartBubble(DayLow!=DayLow[1] and !IsNaN(close)and Show_Low,l,"PrevDayLow",Color.WHITE,no);
AddChartBubble(DayOpen!=DayOpen[1] and !IsNaN(close) and Show_Open,o,"PrevDayOpen",Color.WHITE,if o>=c then yes else no);
AddChartBubble(DayClose!=DayClose[1] and !IsNaN(close) and Show_Close,c,"PrevDayClose",Color.WHITE, if o>=c then no else yes);

AddCloud(if Show_Premarket_High_and_Low then PreHigh else Double.NEGATIVE_INFINITY,if Show_Premarket_High_and_Low then PreLow else Double.NEGATIVE_INFINITY,color.LIGHT_GRAY,color.LIGHT_GRAY);
 
@SJP07
Code:
#Shows previous days High, Low, Open, Close, and High/Low of defined timeframe defaulted to premarket hours.
#Code by Svanoy

input Show_High = No;
input Show_Low = No;
input Show_Open = No;
input Show_Close = Yes;
input Show_Premarket_High_and_Low = No;

input sPeriod = {default DAY};
def offset = 1;

def Today = if GetDay()==GetLastDay() then 1 else 0;
def varhigh = high(period = sPeriod)[offset];
def varlow = low(period = sPeriod)[offset];
def varopen = open(period = sPeriod)[offset];
def varclose = close(period = sPeriod)[offset];
def periodstart = 0400;
def periodend = 0930;
def activeperiod = If secondsFromTime(periodstart)>=0 and secondsTillTime(periodend)>0 then yes else Double.NaN;
def acriveperiodstartbar = if secondsFromTime(periodstart)==0 then barnumber() else acriveperiodstartbar[1];
def activeperiodendbar = fold i=0 to AbsValue(BarNumber()) while !IsNaN(GetValue(activeperiod,-i)) do GetValue(BarNumber(),-i);
def activeperiodlength = 1+(activeperiodendbar-acriveperiodstartbar);

def activeperiodhigh;
if secondsFromTime(periodstart)==0 {
activeperiodhigh = high;
}else if !IsNaN(activeperiod) and high>=activeperiodhigh[1]{
activeperiodhigh = high;
}else{
activeperiodhigh = activeperiodhigh[1];}

def activeperiodlow;
if secondsFromTime(periodstart)==0 {
activeperiodlow = low;
}else if !IsNaN(activeperiod) and low<=activeperiodlow[1]{
activeperiodlow = low;
}else{
activeperiodlow = activeperiodlow[1];}

def activephigh = fold iah=0 to AbsValue(activeperiodlength) while !IsNaN(activeperiod) do GetValue(activeperiodhigh,-iah);
def activeplow = fold ial=0 to AbsValue(activeperiodlength) while !IsNaN(activeperiod) do GetValue(activeperiodlow,-ial);
def aph = fold iaph = 0 to 1 while !IsNaN(close[10]) do activeperiodhigh;
def apl = fold iapl = 0 to 1 while !IsNaN(close[10]) do activeperiodlow;
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 PreHigh = if !IsNaN(activeperiod) and activephigh>0 then activephigh else Double.NaN;
PreHigh.SetPaintingStrategy(PaintingStrategy.LINE);
PreHigh.SetDefaultColor(Color.LIME);
PreHigh.SetHiding(!Show_Premarket_High_and_Low);
 
plot PreLow = if !IsNaN(activeperiod) and activeplow>0 then activeplow else Double.NaN;
PreLow.SetPaintingStrategy(PaintingStrategy.LINE);
PreLow.SetDefaultColor(Color.PINK);
PreLow.SetHiding(!Show_Premarket_High_and_Low);

plot PMHigh = if IsNaN(activeperiod) and aph>0 then aph else Double.NaN;
PMHigh.SetPaintingStrategy(PaintingStrategy.DASHES);
PMHigh.SetDefaultColor(Color.LIME);
PMHigh.SetHiding(!Show_Premarket_High_and_Low);

plot PMLow = if IsNaN(activeperiod) and apl>0 then apl else Double.NaN;
PMLow.SetPaintingStrategy(PaintingStrategy.DASHES);
PMLow.SetDefaultColor(Color.PINK);
PreLow.SetHiding(!Show_Premarket_High_and_Low);

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

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

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);
DayOpen.SetHiding(!Show_Open);

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);
DayClose.SetHiding(!Show_Close);

AddChartBubble(IsNaN(PreHigh[1]) and !IsNaN(PreHigh) and Show_Premarket_High_and_Low,PreHigh,"PreMarket High",Color.WHITE,yes);
AddChartBubble(IsNaN(PreLow[1]) and !IsNaN(PreLow) and Show_Premarket_High_and_Low,PreLow,"PreMarketLow",Color.WHITE,no);
AddChartBubble(DayHigh!=DayHigh[1] and !IsNaN(close) and Show_High,h,"PrevDayHigh",Color.WHITE,yes);
AddChartBubble(DayLow!=DayLow[1] and !IsNaN(close)and Show_Low,l,"PrevDayLow",Color.WHITE,no);
AddChartBubble(DayOpen!=DayOpen[1] and !IsNaN(close) and Show_Open,o,"PrevDayOpen",Color.WHITE,if o>=c then yes else no);
AddChartBubble(DayClose!=DayClose[1] and !IsNaN(close) and Show_Close,c,"PrevDayClose",Color.WHITE, if o>=c then no else yes);

AddCloud(if Show_Premarket_High_and_Low then PreHigh else Double.NEGATIVE_INFINITY,if Show_Premarket_High_and_Low then PreLow else Double.NEGATIVE_INFINITY,color.LIGHT_GRAY,color.LIGHT_GRAY);
Hi Savory!

Thanks for working on this. I'm afraid that I wasn't as clear as I thought I was. I'vee attached a screenshot of what I'm looking for...

 
Hello everyone,

I'm looking for a script that plots a line for the close of the lowest bar from a day ago. It'ss simlar to this code: https://usethinkscript.com/threads/plot-a-horizontal-line-at-previous-day-close.7327/

So for example, if the low on the SPY yesterday was $427, but the close of the low candle was at $427.50 then a horizontal line would be plotted the next day.

I hope that made sense. Thanks in advance!

this will draw a horizontal line, from the close of the lowest bar, x days back from the current day.
can enter how many days back to look. default is 1.
can turn on a bubble to show, the close and low of the desired bar.

EDIT .. added an arrow on desired bar


dAtzYGM.jpg


Ruby:
# prevdaylow_cls_01

# draw a line, from the close of lowest bar, x days back

def bn = barnumber();
def na = double.nan;

# open/close times  (EST)
input start = 0930;
input end = 1600;
def daytime = if SecondsFromTime(start) >= 0 and SecondsTillTime(end) > 0 then 1 else 0;

def diffday = if GetDay() != GetDay()[1] then 1 else 0;
def daycnt = if  diffday then (daycnt[1] + 1) else  daycnt[1];

def big = 9999999;
def daylo;
def daylobn;
def daylocls;
if diffday then {
# find low of day
  daylo = fold a = 0 to 600
  with p = big
  while daycnt == GetValue(daycnt, -a)
  do if GetValue(low , -a) < p then GetValue(low , -a) else p;

# find bn of low of day
  daylobn = fold b = 0 to 600
  with q
  while daycnt == GetValue(daycnt, -b) and q == 0
  do if daylo == GetValue(low , -b) then getvalue(bn, -b) else q;

# find low-close of day
  daylocls = fold c = 0 to 600
  with r
  while daycnt == GetValue(daycnt, -c) and r == 0
  do if daylobn == GetValue(bn , -c) then getvalue(close, -c) else r;

} else {
    daylo = daylo[1];
    daylobn = daylobn[1];
    daylocls = daylocls[1];
}

# --------------------------------

input days_back = 1;

def daycnthi = highestall(if !isnan(close) then daycnt else 0);
def prevday = if (daycnthi - days_back) == daycnt then 1 else 0;

def prevdaylowcls = if (bn == 1 or daycnt > daycnthi) then na
  else if prevday then daylocls
  else prevdaylowcls[1];

plot z1 = prevdaylowcls;
z1.SetDefaultColor(Color.white);
#z1.hidebubble();
#z1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#z1.SetStyle(Curve.MEDIUM_DASH);
#z1.setlineweight(1);

input show_arrow = yes;
plot z2 = if ( show_arrow and prevday and daylobn == bn) then low*0.998 else na;
z2.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
z2.SetDefaultColor(Color.white);
z2.setlineweight(2);
#z2.hidebubble();

input show_bubble = no;
addchartbubble( (show_bubble and prevday and daylobn == bn), low,
round(daylocls,2) + "  Close\n" +
round(daylo,2) + "  Low"
, color.yellow, no);
#
 
Last edited:
this will draw a horizontal line, from the close of the lowest bar, x days back from the current day.
can enter how many days back to look. default is 1.
can turn on a bubble to show, the close and low of the desired bar.

EDIT .. added an arrow on desired bar


dAtzYGM.jpg


Ruby:
# prevdaylow_cls_01

# draw a line, from the close of lowest bar, x days back

def bn = barnumber();
def na = double.nan;

# open/close times  (EST)
input start = 0930;
input end = 1600;
def daytime = if SecondsFromTime(start) >= 0 and SecondsTillTime(end) > 0 then 1 else 0;

def diffday = if GetDay() != GetDay()[1] then 1 else 0;
def daycnt = if  diffday then (daycnt[1] + 1) else  daycnt[1];

def big = 9999999;
def daylo;
def daylobn;
def daylocls;
if diffday then {
# find low of day
  daylo = fold a = 0 to 600
  with p = big
  while daycnt == GetValue(daycnt, -a)
  do if GetValue(low , -a) < p then GetValue(low , -a) else p;

# find bn of low of day
  daylobn = fold b = 0 to 600
  with q
  while daycnt == GetValue(daycnt, -b) and q == 0
  do if daylo == GetValue(low , -b) then getvalue(bn, -b) else q;

# find low-close of day
  daylocls = fold c = 0 to 600
  with r
  while daycnt == GetValue(daycnt, -c) and r == 0
  do if daylobn == GetValue(bn , -c) then getvalue(close, -c) else r;

} else {
    daylo = daylo[1];
    daylobn = daylobn[1];
    daylocls = daylocls[1];
}

# --------------------------------

input days_back = 1;

def daycnthi = highestall(if !isnan(close) then daycnt else 0);
def prevday = if (daycnthi - days_back) == daycnt then 1 else 0;

def prevdaylowcls = if (bn == 1 or daycnt > daycnthi) then na
  else if prevday then daylocls
  else prevdaylowcls[1];

plot z1 = prevdaylowcls;
z1.SetDefaultColor(Color.white);
#z1.hidebubble();
#z1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#z1.SetStyle(Curve.MEDIUM_DASH);
#z1.setlineweight(1);

input show_arrow = yes;
plot z2 = if ( show_arrow and prevday and daylobn == bn) then low*0.998 else na;
z2.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
z2.SetDefaultColor(Color.white);
z2.setlineweight(2);
#z2.hidebubble();

input show_bubble = no;
addchartbubble( (show_bubble and prevday and daylobn == bn), low,
round(daylocls,2) + "  Close\n" +
round(daylo,2) + "  Low"
, color.yellow, no);
#
Could you also do the same thing for the high bar? I over estimated my coding skills and thought I could just edit the code myself.

Thanks in advance!
 
Could you also do the same thing for the high bar? I over estimated my coding skills and thought I could just edit the code myself.

Thanks in advance!

added code to look for a high on a prev day, then find the close.


OT9FxAC.jpg



Ruby:
# prevdaylow_cls_02

# add - find high

# draw a line, from the close of lowest bar, x days back

def bn = barnumber();
def na = double.nan;

# open/close times  (EST)
input start = 0930;
input end = 1600;
def daytime = if SecondsFromTime(start) >= 0 and SecondsTillTime(end) > 0 then 1 else 0;

def diffday = if GetDay() != GetDay()[1] then 1 else 0;
def daycnt = if  diffday then (daycnt[1] + 1) else  daycnt[1];

def big = 9999999;
def daylo;
def daylobn;
def daylocls;

def dayhi;
def dayhibn;
def dayhicls;

if diffday then {
# find low of day
  daylo = fold a = 0 to 600
  with p = big
  while daycnt == GetValue(daycnt, -a)
  do if GetValue(low , -a) < p then GetValue(low , -a) else p;

# find bn of low of day
  daylobn = fold b = 0 to 600
  with q
  while daycnt == GetValue(daycnt, -b) and q == 0
  do if daylo == GetValue(low , -b) then getvalue(bn, -b) else q;

# find low-close of day
  daylocls = fold c = 0 to 600
  with r
  while daycnt == GetValue(daycnt, -c) and r == 0
  do if daylobn == GetValue(bn , -c) then getvalue(close, -c) else r;

#--------------------------------------------------

# find high of day
  dayhi = fold a2 = 0 to 600
  with p2 = 0
  while daycnt == GetValue(daycnt, -a2)
  do if GetValue(high , -a2) > p2 then GetValue(high , -a2) else p2;

# find bn of high of day
  dayhibn = fold b2 = 0 to 600
  with q2
  while daycnt == GetValue(daycnt, -b2) and q2 == 0
  do if dayhi == GetValue(high , -b2) then getvalue(bn, -b2) else q2;

# find high-close of day
  dayhicls = fold c2 = 0 to 600
  with r2
  while daycnt == GetValue(daycnt, -c2) and r2 == 0
  do if dayhibn == GetValue(bn , -c2) then getvalue(close, -c2) else r2;

} else {
    daylo = daylo[1];
    daylobn = daylobn[1];
    daylocls = daylocls[1];

    dayhi = dayhi[1];
    dayhibn = dayhibn[1];
    dayhicls = dayhicls[1];
}

# --------------------------------

input days_back = 1;

def daycnthi = highestall(if !isnan(close) then daycnt else 0);
def prevday = if (daycnthi - days_back) == daycnt then 1 else 0;

# ----------------------------------------
# low-close
def prevdaylowcls = if (bn == 1 or daycnt > daycnthi) then na
  else if prevday then daylocls
  else prevdaylowcls[1];

plot z1 = prevdaylowcls;
z1.SetDefaultColor(Color.white);
#z1.hidebubble();
#z1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#z1.SetStyle(Curve.MEDIUM_DASH);
#z1.setlineweight(1);

input show_low_arrow = yes;
plot z2 = if ( show_low_arrow and prevday and daylobn == bn) then low*0.998 else na;
z2.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
z2.SetDefaultColor(Color.white);
z2.setlineweight(2);
#z2.hidebubble();

# ----------------------------------------
# high-close

def prevdayhighcls = if (bn == 1 or daycnt > daycnthi) then na
  else if prevday then dayhicls
  else prevdayhighcls[1];

plot z3 = prevdayhighcls;
z3.SetDefaultColor(Color.white);
#z1.hidebubble();
#z1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#z1.SetStyle(Curve.MEDIUM_DASH);
#z1.setlineweight(1);

input show_high_arrow = yes;
plot z4 = if ( show_high_arrow and prevday and dayhibn == bn) then high*1.002 else na;
z4.SetPaintingStrategy(PaintingStrategy.ARROW_down);
z4.SetDefaultColor(Color.white);
z4.setlineweight(2);
#z2.hidebubble();

# ----------------------------------------

input show_bubble = no;
addchartbubble( (show_bubble and prevday and daylobn == bn), low,
round(daylocls,2) + "  Close\n" +
round(daylo,2) + "  Low"
, color.yellow, no);
#
 
hello I was wondering if someone could help create a script that would plot the high and low of the previous day's last hour high and low value before close( high and low between 15:00 and 14:00), so I could be able to see the next morning, I would really appreciate it
 
@ziongotoptions

Code:
#Shows previous days High, Low, Open, Close, and High/Low of defined timeframe.
#Code by Svanoy

input Show_High = No;
input Show_Low = No;
input Show_Open = No;
input Show_Close = No;
input Show_Time_Frame_High_and_Low = Yes;
input periodstart = 1400;
input periodend = 1500;
input sPeriod = {default DAY};
def offset = 1;

def Today = if GetDay()==GetLastDay() then 1 else 0;
def varhigh = high(period = sPeriod)[offset];
def varlow = low(period = sPeriod)[offset];
def varopen = open(period = sPeriod)[offset];
def varclose = close(period = sPeriod)[offset];

def activeperiod = If secondsFromTime(periodstart)>=0 and secondsTillTime(periodend)>0 then yes else Double.NaN;
def acriveperiodstartbar = if secondsFromTime(periodstart)==0 then barnumber() else acriveperiodstartbar[1];
def activeperiodendbar = fold i=0 to AbsValue(BarNumber()) while !IsNaN(GetValue(activeperiod,-i)) do GetValue(BarNumber(),-i);
def activeperiodlength = 1+(activeperiodendbar-acriveperiodstartbar);

def activeperiodhigh;
if secondsFromTime(periodstart)==0 {
activeperiodhigh = high;
}else if !IsNaN(activeperiod) and high>=activeperiodhigh[1]{
activeperiodhigh = high;
}else{
activeperiodhigh = activeperiodhigh[1];}

def activeperiodlow;
if secondsFromTime(periodstart)==0 {
activeperiodlow = low;
}else if !IsNaN(activeperiod) and low<=activeperiodlow[1]{
activeperiodlow = low;
}else{
activeperiodlow = activeperiodlow[1];}

def activephigh = fold iah=0 to AbsValue(activeperiodlength) while !IsNaN(activeperiod) do GetValue(activeperiodhigh,-iah);
def activeplow = fold ial=0 to AbsValue(activeperiodlength) while !IsNaN(activeperiod) do GetValue(activeperiodlow,-ial);
def aph = fold iaph = 0 to 1 while !IsNaN(close[10]) do activeperiodhigh;
def apl = fold iapl = 0 to 1 while !IsNaN(close[10]) do activeperiodlow;
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 PreHigh = if !IsNaN(activeperiod) and activephigh>0 then activephigh else Double.NaN;
PreHigh.SetPaintingStrategy(PaintingStrategy.LINE);
PreHigh.SetDefaultColor(Color.LIME);
PreHigh.SetHiding(!Show_Time_Frame_High_and_Low);
 
plot PreLow = if !IsNaN(activeperiod) and activeplow>0 then activeplow else Double.NaN;
PreLow.SetPaintingStrategy(PaintingStrategy.LINE);
PreLow.SetDefaultColor(Color.PINK);
PreLow.SetHiding(!Show_Time_Frame_High_and_Low);

plot PMHigh = if IsNaN(activeperiod) and aph>0 then aph else Double.NaN;
PMHigh.SetPaintingStrategy(PaintingStrategy.DASHES);
PMHigh.SetDefaultColor(Color.LIME);
PMHigh.SetHiding(!Show_Time_Frame_High_and_Low);

plot PMLow = if IsNaN(activeperiod) and apl>0 then apl else Double.NaN;
PMLow.SetPaintingStrategy(PaintingStrategy.DASHES);
PMLow.SetDefaultColor(Color.PINK);
PMLow.SetHiding(!Show_Time_Frame_High_and_Low);

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

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

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);
DayOpen.SetHiding(!Show_Open);

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);
DayClose.SetHiding(!Show_Close);

AddChartBubble(IsNaN(PreHigh[1]) and !IsNaN(PreHigh) and Show_Time_Frame_High_and_Low,PreHigh,"Time Frame High",Color.WHITE,yes);
AddChartBubble(IsNaN(PreLow[1]) and !IsNaN(PreLow) and Show_Time_Frame_High_and_Low,PreLow,"Time Frame Low",Color.WHITE,no);
AddChartBubble(DayHigh!=DayHigh[1] and !IsNaN(close) and Show_High,h,"PrevDayHigh",Color.WHITE,yes);
AddChartBubble(DayLow!=DayLow[1] and !IsNaN(close)and Show_Low,l,"PrevDayLow",Color.WHITE,no);
AddChartBubble(DayOpen!=DayOpen[1] and !IsNaN(close) and Show_Open,o,"PrevDayOpen",Color.WHITE,if o>=c then yes else no);
AddChartBubble(DayClose!=DayClose[1] and !IsNaN(close) and Show_Close,c,"PrevDayClose",Color.WHITE, if o>=c then no else yes);

AddCloud(if Show_Time_Frame_High_and_Low then PreHigh else Double.NEGATIVE_INFINITY,if Show_Time_Frame_High_and_Low then PreLow else Double.NEGATIVE_INFINITY,color.LIGHT_GRAY,color.LIGHT_GRAY);
 
Last edited:
Looking for a script to scan for stocks with current price above previous days high and previous overnight/ premarket high. I will be scanning during regular trading hours.

This piece scans previous day, not sure how to include extended hours in this:

def CurrentDay = GetDay() == GetLastDay();
def previousHigh = if CurrentDay then high(period = AggregationPeriod.Day)[1] else Double.NaN;
def previousLow = if CurrentDay then low(period = AggregationPeriod.Day)[1] else Double.NaN;

plot scan = close crosses above previousHigh;
 
Last edited:
@wkoslo
See if this helps you, it's a script of mine I keep handy for displaying previous day high, low, open, close, and premarket high/low.
Ruby:
#Shows previous days High, Low, Open, Close, and High/Low of defined timeframe.
#Code by Svanoy

input Show_High = yes;
input Show_Low = yes;
input Show_Open = yes;
input Show_Close = yes;
input Show_Time_Frame_High_and_Low = yes;
input periodstart = 0400;
input periodend = 0930;
input sPeriod = {default DAY};
def offset = 1;

def Today = if GetDay()==GetLastDay() then 1 else 0;
def varhigh = high(period = sPeriod)[offset];
def varlow = low(period = sPeriod)[offset];
def varopen = open(period = sPeriod)[offset];
def varclose = close(period = sPeriod)[offset];

def activeperiod = If secondsFromTime(periodstart)>=0 and secondsTillTime(periodend)>0 then yes else Double.NaN;
def acriveperiodstartbar = if secondsFromTime(periodstart)==0 then barnumber() else acriveperiodstartbar[1];
def activeperiodendbar = fold i=0 to AbsValue(BarNumber()) while !IsNaN(GetValue(activeperiod,-i)) do GetValue(BarNumber(),-i);
def activeperiodlength = 1+(activeperiodendbar-acriveperiodstartbar);

def activeperiodhigh;
if secondsFromTime(periodstart)==0 {
activeperiodhigh = high;
}else if !IsNaN(activeperiod) and high>=activeperiodhigh[1]{
activeperiodhigh = high;
}else{
activeperiodhigh = activeperiodhigh[1];}

def activeperiodlow;
if secondsFromTime(periodstart)==0 {
activeperiodlow = low;
}else if !IsNaN(activeperiod) and low<=activeperiodlow[1]{
activeperiodlow = low;
}else{
activeperiodlow = activeperiodlow[1];}

def activephigh = fold iah=0 to AbsValue(activeperiodlength) while !IsNaN(activeperiod) do GetValue(activeperiodhigh,-iah);
def activeplow = fold ial=0 to AbsValue(activeperiodlength) while !IsNaN(activeperiod) do GetValue(activeperiodlow,-ial);
def aph = fold iaph = 0 to 1 while !IsNaN(close[10]) do activeperiodhigh;
def apl = fold iapl = 0 to 1 while !IsNaN(close[10]) do activeperiodlow;
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 PreHigh = if !IsNaN(activeperiod) and activephigh>0 then activephigh else Double.NaN;
PreHigh.SetPaintingStrategy(PaintingStrategy.LINE);
PreHigh.SetDefaultColor(Color.LIME);
PreHigh.SetHiding(!Show_Time_Frame_High_and_Low);
 
plot PreLow = if !IsNaN(activeperiod) and activeplow>0 then activeplow else Double.NaN;
PreLow.SetPaintingStrategy(PaintingStrategy.LINE);
PreLow.SetDefaultColor(Color.PINK);
PreLow.SetHiding(!Show_Time_Frame_High_and_Low);

plot PMHigh = if IsNaN(activeperiod) and aph>0 then aph else Double.NaN;
PMHigh.SetPaintingStrategy(PaintingStrategy.DASHES);
PMHigh.SetDefaultColor(Color.LIME);
PMHigh.SetHiding(!Show_Time_Frame_High_and_Low);

plot PMLow = if IsNaN(activeperiod) and apl>0 then apl else Double.NaN;
PMLow.SetPaintingStrategy(PaintingStrategy.DASHES);
PMLow.SetDefaultColor(Color.PINK);
PMLow.SetHiding(!Show_Time_Frame_High_and_Low);

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

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

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);
DayOpen.SetHiding(!Show_Open);

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);
DayClose.SetHiding(!Show_Close);

AddChartBubble(IsNaN(PreHigh[1]) and !IsNaN(PreHigh) and Show_Time_Frame_High_and_Low,PreHigh,"Time Frame High",Color.WHITE,yes);
AddChartBubble(IsNaN(PreLow[1]) and !IsNaN(PreLow) and Show_Time_Frame_High_and_Low,PreLow,"Time Frame Low",Color.WHITE,no);
AddChartBubble(DayHigh!=DayHigh[1] and !IsNaN(close) and Show_High,h,"PrevDayHigh",Color.WHITE,yes);
AddChartBubble(DayLow!=DayLow[1] and !IsNaN(close)and Show_Low,l,"PrevDayLow",Color.WHITE,no);
AddChartBubble(DayOpen!=DayOpen[1] and !IsNaN(close) and Show_Open,o,"PrevDayOpen",Color.WHITE,if o>=c then yes else no);
AddChartBubble(DayClose!=DayClose[1] and !IsNaN(close) and Show_Close,c,"PrevDayClose",Color.WHITE, if o>=c then no else yes);

AddCloud(if Show_Time_Frame_High_and_Low then PreHigh else Double.NEGATIVE_INFINITY,if Show_Time_Frame_High_and_Low then PreLow else Double.NEGATIVE_INFINITY,color.LIGHT_GRAY,color.LIGHT_GRAY);
 
looking for some assistance coding a label,,,,

color Gray when inside Premarket levels and previous days high and low,,, "inside Day"
yellow when break PREMARKET high or low but still inside previous day high and low, "ABOVE/Below Premarket"
yellow when breaks PREVIOUS DAY Hgh low but still indside Pre market levels "above/below PDAY"
Green when breaks above pre market high and previous day high "above all"
Red when breaks below pre market low and previous day low

any assistance will be greatly appreciated,,,,,
 
Hi,

Is there way to scan stock which are near to previous day low, high, close or open price ? Alternatively if we can scan stock if they are close to previous day volume profile?

I was trying to scan based on pivot point but not getting proper results.

thank you
 
https://usethinkscript.com/threads/code-to-grab-close-of-lowest-bar.9855/#post-88681

#Shows previous days High, Low, Open, Close, and High/Low of defined timeframe defaulted to premarket hours.
#Code by Svanoy

input Show_High = No;
input Show_Low = No;
input Show_Open = No;
input Show_Close = Yes;
input Show_Premarket_High_and_Low = No;

input sPeriod = {default DAY};
def offset = 1;

def Today = if GetDay()==GetLastDay() then 1 else 0;
def varhigh = high(period = sPeriod)[offset];
def varlow = low(period = sPeriod)[offset];
def varopen = open(period = sPeriod)[offset];
def varclose = close(period = sPeriod)[offset];
def periodstart = 0400;
def periodend = 0930;
def activeperiod = If secondsFromTime(periodstart)>=0 and secondsTillTime(periodend)>0 then yes else Double.NaN;
def acriveperiodstartbar = if secondsFromTime(periodstart)==0 then barnumber() else acriveperiodstartbar[1];
def activeperiodendbar = fold i=0 to AbsValue(BarNumber()) while !IsNaN(GetValue(activeperiod,-i)) do GetValue(BarNumber(),-i);
def activeperiodlength = 1+(activeperiodendbar-acriveperiodstartbar);

def activeperiodhigh;
if secondsFromTime(periodstart)==0 {
activeperiodhigh = high;
}else if !IsNaN(activeperiod) and high>=activeperiodhigh[1]{
activeperiodhigh = high;
}else{
activeperiodhigh = activeperiodhigh[1];}

def activeperiodlow;
if secondsFromTime(periodstart)==0 {
activeperiodlow = low;
}else if !IsNaN(activeperiod) and low<=activeperiodlow[1]{
activeperiodlow = low;
}else{
activeperiodlow = activeperiodlow[1];}

def activephigh = fold iah=0 to AbsValue(activeperiodlength) while !IsNaN(activeperiod) do GetValue(activeperiodhigh,-iah);
def activeplow = fold ial=0 to AbsValue(activeperiodlength) while !IsNaN(activeperiod) do GetValue(activeperiodlow,-ial);
def aph = fold iaph = 0 to 1 while !IsNaN(close[10]) do activeperiodhigh;
def apl = fold iapl = 0 to 1 while !IsNaN(close[10]) do activeperiodlow;
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 PreHigh = if !IsNaN(activeperiod) and activephigh>0 then activephigh else Double.NaN;
PreHigh.SetPaintingStrategy(PaintingStrategy.LINE);
PreHigh.SetDefaultColor(Color.LIME);
PreHigh.SetHiding(!Show_Premarket_High_and_Low);

plot PreLow = if !IsNaN(activeperiod) and activeplow>0 then activeplow else Double.NaN;
PreLow.SetPaintingStrategy(PaintingStrategy.LINE);
PreLow.SetDefaultColor(Color.PINK);
PreLow.SetHiding(!Show_Premarket_High_and_Low);

plot PMHigh = if IsNaN(activeperiod) and aph>0 then aph else Double.NaN;
PMHigh.SetPaintingStrategy(PaintingStrategy.DASHES);
PMHigh.SetDefaultColor(Color.LIME);
PMHigh.SetHiding(!Show_Premarket_High_and_Low);

plot PMLow = if IsNaN(activeperiod) and apl>0 then apl else Double.NaN;
PMLow.SetPaintingStrategy(PaintingStrategy.DASHES);
PMLow.SetDefaultColor(Color.PINK);
PreLow.SetHiding(!Show_Premarket_High_and_Low);

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

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

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);
DayOpen.SetHiding(!Show_Open);

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);
DayClose.SetHiding(!Show_Close);

AddChartBubble(IsNaN(PreHigh[1]) and !IsNaN(PreHigh) and Show_Premarket_High_and_Low,PreHigh,"PreMarket High",Color.WHITE,yes);
AddChartBubble(IsNaN(PreLow[1]) and !IsNaN(PreLow) and Show_Premarket_High_and_Low,PreLow,"PreMarketLow",Color.WHITE,no);
AddChartBubble(DayHigh!=DayHigh[1] and !IsNaN(close) and Show_High,h,"PrevDayHigh",Color.WHITE,yes);
AddChartBubble(DayLow!=DayLow[1] and !IsNaN(close)and Show_Low,l,"PrevDayLow",Color.WHITE,no);
AddChartBubble(DayOpen!=DayOpen[1] and !IsNaN(close) and Show_Open,o,"PrevDayOpen",Color.WHITE,if o>=c then yes else no);
AddChartBubble(DayClose!=DayClose[1] and !IsNaN(close) and Show_Close,c,"PrevDayClose",Color.WHITE, if o>=c then no else yes);

AddCloud(if Show_Premarket_High_and_Low then PreHigh else Double.NEGATIVE_INFINITY,if Show_Premarket_High_and_Low then PreLow else Double.NEGATIVE_INFINITY,color.LIGHT_GRAY,color.LIGHT_GRAY);
 
Last edited by a moderator:
@Nari2007 This will help you get started.
Ruby:
#Shows previous days High, Low, Open, Close, and High/Low of defined timeframe.
#Code by Svanoy
input Show_Bubbles = yes;
input Show_High = yes;
input Show_Low = yes;
input Show_Open = yes;
input Show_Close = yes;
input Show_Time_Frame_High_and_Low = yes;
input periodstart = 0400;
input periodend = 0930;
input sPeriod = {default DAY};
def offset = 1;

def Today = if GetDay()==GetLastDay() then 1 else 0;
def varhigh = high(period = sPeriod)[offset];
def varlow = low(period = sPeriod)[offset];
def varopen = open(period = sPeriod)[offset];
def varclose = close(period = sPeriod)[offset];

def activeperiod = If secondsFromTime(periodstart)>=0 and secondsTillTime(periodend)>0 then yes else Double.NaN;
def acriveperiodstartbar = if secondsFromTime(periodstart)==0 then barnumber() else acriveperiodstartbar[1];
def activeperiodendbar = fold i=0 to AbsValue(BarNumber()) while !IsNaN(GetValue(activeperiod,-i)) do GetValue(BarNumber(),-i);
def activeperiodlength = 1+(activeperiodendbar-acriveperiodstartbar);

def activeperiodhigh;
if secondsFromTime(periodstart)==0 {
activeperiodhigh = high;
}else if !IsNaN(activeperiod) and high>=activeperiodhigh[1]{
activeperiodhigh = high;
}else{
activeperiodhigh = activeperiodhigh[1];}

def activeperiodlow;
if secondsFromTime(periodstart)==0 {
activeperiodlow = low;
}else if !IsNaN(activeperiod) and low<=activeperiodlow[1]{
activeperiodlow = low;
}else{
activeperiodlow = activeperiodlow[1];}

def activephigh = fold iah=0 to AbsValue(activeperiodlength) while !IsNaN(activeperiod) do GetValue(activeperiodhigh,-iah);
def activeplow = fold ial=0 to AbsValue(activeperiodlength) while !IsNaN(activeperiod) do GetValue(activeperiodlow,-ial);
def aph = fold iaph = 0 to 1 while !IsNaN(close[10]) do activeperiodhigh;
def apl = fold iapl = 0 to 1 while !IsNaN(close[10]) do activeperiodlow;
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 PreHigh = if !IsNaN(activeperiod) and activephigh>0 then activephigh else Double.NaN;
PreHigh.SetPaintingStrategy(PaintingStrategy.LINE);
PreHigh.SetDefaultColor(Color.LIME);
PreHigh.SetHiding(!Show_Time_Frame_High_and_Low);
 
plot PreLow = if !IsNaN(activeperiod) and activeplow>0 then activeplow else Double.NaN;
PreLow.SetPaintingStrategy(PaintingStrategy.LINE);
PreLow.SetDefaultColor(Color.PINK);
PreLow.SetHiding(!Show_Time_Frame_High_and_Low);

plot PMHigh = if IsNaN(activeperiod) and aph>0 then aph else Double.NaN;
PMHigh.SetPaintingStrategy(PaintingStrategy.DASHES);
PMHigh.SetDefaultColor(Color.LIME);
PMHigh.SetHiding(!Show_Time_Frame_High_and_Low);

plot PMLow = if IsNaN(activeperiod) and apl>0 then apl else Double.NaN;
PMLow.SetPaintingStrategy(PaintingStrategy.DASHES);
PMLow.SetDefaultColor(Color.PINK);
PMLow.SetHiding(!Show_Time_Frame_High_and_Low);

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

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

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);
DayOpen.SetHiding(!Show_Open);

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);
DayClose.SetHiding(!Show_Close);

AddChartBubble(Show_Bubbles and IsNaN(PreHigh[1]) and !IsNaN(PreHigh) and Show_Time_Frame_High_and_Low,PreHigh,"Time Frame High",Color.WHITE,yes);
AddChartBubble(Show_Bubbles and IsNaN(PreLow[1]) and !IsNaN(PreLow) and Show_Time_Frame_High_and_Low,PreLow,"Time Frame Low",Color.WHITE,no);

AddChartBubble(Show_Bubbles and !Today and DayHigh!=DayHigh[1] and !IsNaN(close) and Show_High,h,"PrevDayHigh" ,Color.WHITE,yes);
AddChartBubble(Show_Bubbles and DayHigh==DayHigh[1] and !IsNaN(DayHigh) and IsNaN(DayHigh[-1]) and Show_High,h,"PrevDayHigh" ,Color.WHITE,yes);

AddChartBubble(Show_Bubbles and !Today and DayLow!=DayLow[1] and !IsNaN(close)and Show_Low,l,"PrevDayLow",Color.WHITE,no);
AddChartBubble(Show_Bubbles and DayLow==DayLow[1] and !IsNaN(DayLow) and IsNaN(DayLow[-1]) and Show_Low,l,"PrevDayLow",Color.WHITE,no);

AddChartBubble(Show_Bubbles and !Today and DayOpen!=DayOpen[1] and !IsNaN(close) and Show_Open,o,"PrevDayOpen",Color.WHITE,if o>=c then yes else no);
AddChartBubble(Show_Bubbles and DayOpen==DayOpen[1] and !IsNaN(DayOpen) and IsNaN(DayOpen[-1]) and Show_Open,o,"PrevDayOpen",Color.WHITE,if o>=c then yes else no);

AddChartBubble(Show_Bubbles and !Today and DayClose!=DayClose[1] and !IsNaN(close) and Show_Close,c,"PrevDayClose",Color.WHITE, if o>=c then no else yes);
AddChartBubble(Show_Bubbles and DayClose==DayClose[1] and !IsNaN(DayClose) and IsNaN(DayClose[-1]) and Show_Close,c,"PrevDayClose",Color.WHITE, if o>=c then no else yes);

AddCloud(if Show_Time_Frame_High_and_Low then PreHigh else Double.NEGATIVE_INFINITY,if Show_Time_Frame_High_and_Low then PreLow else Double.NEGATIVE_INFINITY,color.LIGHT_GRAY,color.LIGHT_GRAY);
 
Please do not share personal information on public forums
@SJP07
Code:
#Shows previous days High, Low, Open, Close, and High/Low of defined timeframe defaulted to premarket hours.
#Code by Svanoy

input Show_High = No;
input Show_Low = No;
input Show_Open = No;
input Show_Close = Yes;
input Show_Premarket_High_and_Low = No;

input sPeriod = {default DAY};
def offset = 1;

def Today = if GetDay()==GetLastDay() then 1 else 0;
def varhigh = high(period = sPeriod)[offset];
def varlow = low(period = sPeriod)[offset];
def varopen = open(period = sPeriod)[offset];
def varclose = close(period = sPeriod)[offset];
def periodstart = 0400;
def periodend = 0930;
def activeperiod = If secondsFromTime(periodstart)>=0 and secondsTillTime(periodend)>0 then yes else Double.NaN;
def acriveperiodstartbar = if secondsFromTime(periodstart)==0 then barnumber() else acriveperiodstartbar[1];
def activeperiodendbar = fold i=0 to AbsValue(BarNumber()) while !IsNaN(GetValue(activeperiod,-i)) do GetValue(BarNumber(),-i);
def activeperiodlength = 1+(activeperiodendbar-acriveperiodstartbar);

def activeperiodhigh;
if secondsFromTime(periodstart)==0 {
activeperiodhigh = high;
}else if !IsNaN(activeperiod) and high>=activeperiodhigh[1]{
activeperiodhigh = high;
}else{
activeperiodhigh = activeperiodhigh[1];}

def activeperiodlow;
if secondsFromTime(periodstart)==0 {
activeperiodlow = low;
}else if !IsNaN(activeperiod) and low<=activeperiodlow[1]{
activeperiodlow = low;
}else{
activeperiodlow = activeperiodlow[1];}

def activephigh = fold iah=0 to AbsValue(activeperiodlength) while !IsNaN(activeperiod) do GetValue(activeperiodhigh,-iah);
def activeplow = fold ial=0 to AbsValue(activeperiodlength) while !IsNaN(activeperiod) do GetValue(activeperiodlow,-ial);
def aph = fold iaph = 0 to 1 while !IsNaN(close[10]) do activeperiodhigh;
def apl = fold iapl = 0 to 1 while !IsNaN(close[10]) do activeperiodlow;
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 PreHigh = if !IsNaN(activeperiod) and activephigh>0 then activephigh else Double.NaN;
PreHigh.SetPaintingStrategy(PaintingStrategy.LINE);
PreHigh.SetDefaultColor(Color.LIME);
PreHigh.SetHiding(!Show_Premarket_High_and_Low);
 
plot PreLow = if !IsNaN(activeperiod) and activeplow>0 then activeplow else Double.NaN;
PreLow.SetPaintingStrategy(PaintingStrategy.LINE);
PreLow.SetDefaultColor(Color.PINK);
PreLow.SetHiding(!Show_Premarket_High_and_Low);

plot PMHigh = if IsNaN(activeperiod) and aph>0 then aph else Double.NaN;
PMHigh.SetPaintingStrategy(PaintingStrategy.DASHES);
PMHigh.SetDefaultColor(Color.LIME);
PMHigh.SetHiding(!Show_Premarket_High_and_Low);

plot PMLow = if IsNaN(activeperiod) and apl>0 then apl else Double.NaN;
PMLow.SetPaintingStrategy(PaintingStrategy.DASHES);
PMLow.SetDefaultColor(Color.PINK);
PreLow.SetHiding(!Show_Premarket_High_and_Low);

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

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

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);
DayOpen.SetHiding(!Show_Open);

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);
DayClose.SetHiding(!Show_Close);

AddChartBubble(IsNaN(PreHigh[1]) and !IsNaN(PreHigh) and Show_Premarket_High_and_Low,PreHigh,"PreMarket High",Color.WHITE,yes);
AddChartBubble(IsNaN(PreLow[1]) and !IsNaN(PreLow) and Show_Premarket_High_and_Low,PreLow,"PreMarketLow",Color.WHITE,no);
AddChartBubble(DayHigh!=DayHigh[1] and !IsNaN(close) and Show_High,h,"PrevDayHigh",Color.WHITE,yes);
AddChartBubble(DayLow!=DayLow[1] and !IsNaN(close)and Show_Low,l,"PrevDayLow",Color.WHITE,no);
AddChartBubble(DayOpen!=DayOpen[1] and !IsNaN(close) and Show_Open,o,"PrevDayOpen",Color.WHITE,if o>=c then yes else no);
AddChartBubble(DayClose!=DayClose[1] and !IsNaN(close) and Show_Close,c,"PrevDayClose",Color.WHITE, if o>=c then no else yes);

AddCloud(if Show_Premarket_High_and_Low then PreHigh else Double.NEGATIVE_INFINITY,if Show_Premarket_High_and_Low then PreLow else Double.NEGATIVE_INFINITY,color.LIGHT_GRAY,color.LIGHT_GRAY);
The previous day's indicator compresses the candlestick chart.When I tick the left left axis it will be ok but does not show the correct lines.
 
Last edited by a moderator:
@Jerseystranger turn off extended hours if you are not viewing a futures chart. The High, Low, Open, and Close are from RTH of the previous day.
Also, the Monday holiday trading hours effects the chart plots for the week on futures charts, It will correct itself the following week.
 
Last edited:
Is it possible to convert this script to scan ? I am looking for stocks near yesterday's or two days ago OHLC. In 15 mins or 60 min chart.
thank you
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
412 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