Previous Day High and Low Breakout Indicator for ThinkorSwim

Is there a way to add chart bubbles to these levels?

Just saw your request.

Here is the bubble code added to your script below. They will display in expansion andt you can move sideways at input bubblemover.

Capture.jpg

Code:
# 5 min opening range
# Robert Payne
#Plot opening range high / low
input OpenRangeMinutes = 5;
input MarketOpenTime = 0930;
input ShowTodayOnly = yes;

def Today = if GetDay() == GetLastDay() then 1 else 0;
def FirstMinute = if SecondsFromTime(MarketOpenTime) < 60 then 1 else 0;
def OpenRangeTime = if SecondsFromTime(MarketOpenTime) < 60 * OpenRangeMinutes then 1 else 0;

#Plot yesterday's high / low
plot Yhigh = if ShowTodayOnly and !Today then Double.NaN else high(period = "day" )[1];
plot Ylow = if ShowTodayOnly and !Today then Double.NaN else low(period = "day" )[1];

Yhigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Yhigh.SetDefaultColor(Color.UPTICK);
Yhigh.SetLineWeight(2);
Ylow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Ylow.SetDefaultColor(Color.DOWNTICK);
Ylow.SetLineWeight(2);

#Plot pivot
plot Pivot = if ShowTodayOnly and !Today then Double.NaN else (high(period = "day" )[1] + low(period = "day" )[1] + close(period = "day" )[1]) / 3;
Pivot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Pivot.SetDefaultColor(Color.YELLOW);
Pivot.SetLineWeight(2);

#Plot 10 day high / low
plot TenHigh = if ShowTodayOnly and !Today then Double.NaN else Highest(high(period = "day" )[1], 10);
plot TenLow = if ShowTodayOnly and !Today then Double.NaN else Lowest(low(period = "day" )[1], 10);

TenHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
TenHigh.SetDefaultColor(Color.UPTICK);
TenHigh.SetLineWeight(3);
TenLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
TenLow.SetDefaultColor(Color.DOWNTICK);
TenLow.SetLineWeight(3);

input showbubbles = yes;
input bubblemover = 3;
def   b           = bubblemover;
def   b1          = b + 1;

addchartBubble(showbubbles and !isnan(close[b1]) and isnan(close[b]), yhigh, "YH", color.green);
addchartBubble(showbubbles and !isnan(close[b1]) and isnan(close[b]), ylow, "YL", color.red);
addchartBubble(showbubbles and !isnan(close[b1]) and isnan(close[b]), pivot, "Pivot", color.yellow);
addchartBubble(showbubbles and !isnan(close[b1]) and isnan(close[b]), Tenhigh, "TenH", color.green);
addchartBubble(showbubbles and !isnan(close[b1]) and isnan(close[b]), Tenlow, "TenL", color.red);

AssignPriceColor(if close >= Yhigh then Color.GREEN
else if close <= Ylow then Color.RED
else Color.CURRENT);

AssignPriceColor(if close > Yhigh and open < close then Color.WHITE
else if close > Yhigh and open > close then Color.GRAY
else if close < Ylow and open < close then Color.WHITE
else if close < Ylow and open > close then Color.GRAY
else Color.CURRENT);
 
Last edited:

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

Just saw your request.

Here is the bubble code added to your script below. They will display in expansion andt you can move sideways at input bubblemover.
Hi, can you edit this wonderful script for just yesterday's High/Low and the day before yesterday's High/low(keep bubbles on charts, please). I'm interested to do some research with small cap stocks and small cap stocks usually won't break out 10 days low and high if it has high volatility recently.Thank you for your help.
 
Hi, can you edit this wonderful script for just yesterday's High/Low and the day before yesterday's High/low(keep bubbles on charts, please). I'm interested to do some research with small cap stocks and small cap stocks usually won't break out 10 days low and high if it has high volatility recently.Thank you for your help.

Here is modified script from above to change tenhigh / tenlow to x_daysback high / low with bubbles showing on last day

Ruby:
# 5 min opening range
# Robert Payne
# Plot opening range high / low
# Modified to x days back hih / low rather than highest / lowest in days back

input OpenRangeMinutes = 5;
input MarketOpenTime = 0930;
input ShowTodayOnly = yes;

def Today = if GetDay() == GetLastDay() then 1 else 0;
def FirstMinute = if SecondsFromTime(MarketOpenTime) < 60 then 1 else 0;
def OpenRangeTime = if SecondsFromTime(MarketOpenTime) < 60 * OpenRangeMinutes then 1 else 0;

#Plot yesterday's high / low
plot Yhigh = if ShowTodayOnly and !Today then Double.NaN else high(period = "day" )[1];
plot Ylow = if ShowTodayOnly and !Today then Double.NaN else low(period = "day" )[1];

Yhigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Yhigh.SetDefaultColor(Color.UPTICK);
Yhigh.SetLineWeight(2);
Ylow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Ylow.SetDefaultColor(Color.DOWNTICK);
Ylow.SetLineWeight(2);

#Plot pivot
plot Pivot = if ShowTodayOnly and !Today then Double.NaN else (high(period = "day" )[1] + low(period = "day" )[1] + close(period = "day" )[1]) / 3;
Pivot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Pivot.SetDefaultColor(Color.YELLOW);
Pivot.SetLineWeight(2);

#Plot x days hack high / low
input x_daysback = 2;
plot xHigh = if ShowTodayOnly and !Today then Double.NaN else high(period = "day" )[ x_daysback];
plot xLow = if ShowTodayOnly and !Today then Double.NaN else low(period = "day" )[ x_daysback];

xHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
xHigh.SetDefaultColor(Color.UPTICK);
xHigh.SetLineWeight(3);
xLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
xLow.SetDefaultColor(Color.DOWNTICK);
xLow.SetLineWeight(3);

input showbubbles = yes;
input bubblemover = 3;
def   b           = bubblemover;
def   b1          = b + 1;

AddChartBubble(showbubbles and !IsNaN(close[b1]) and IsNaN(close[b]), Yhigh, "YH", Color.GREEN);
AddChartBubble(showbubbles and !IsNaN(close[b1]) and IsNaN(close[b]), Ylow, "YL", Color.RED);
AddChartBubble(showbubbles and !IsNaN(close[b1]) and IsNaN(close[b]), Pivot, "Pivot", Color.YELLOW);
AddChartBubble(showbubbles and !IsNaN(close[b1]) and IsNaN(close[b]), xHigh, x_daysback + "H", Color.GREEN);
AddChartBubble(showbubbles and !IsNaN(close[b1]) and IsNaN(close[b]), xLow, x_daysback + "L", Color.RED);

AssignPriceColor(if close >= Yhigh then Color.GREEN
else if close <= Ylow then Color.RED
else Color.CURRENT);

AssignPriceColor(if close > Yhigh and open < close then Color.WHITE
else if close > Yhigh and open > close then Color.GRAY
else if close < Ylow and open < close then Color.WHITE
else if close < Ylow and open > close then Color.GRAY
else Color.CURRENT);
 
Here is modified script from above to change tenhigh / tenlow to x_daysback high / low with bubbles showing on last day
I have this code but only works if you have the chart settings to RTH Only - I can not get it to work on the ETH Chart as it shows the overnight levels i.e. ("Show Extended-Hours Trading session")

Is there a way to code this to run on an ETH only chart and only show the cash session/RTH High/Low?

#Plots RTH only High/Low
input OpenRangeMinutes = 5;
input MarketOpenTime = 0930;
input ShowTodayOnly = yes;

def Today = if GetDay() == GetLastDay() then 1 else 0;

#Plot yesterday's high / low
plot Yhigh = if ShowTodayOnly and !Today then Double.NaN else high(period = "day" )[1];
plot Ylow = if ShowTodayOnly and !Today then Double.NaN else low(period = "day" )[1];

Yhigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Yhigh.SetDefaultColor(Color.UPTICK);
Yhigh.SetLineWeight(2);
Ylow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Ylow.SetDefaultColor(Color.DOWNTICK);
Ylow.SetLineWeight(2);
 
I have this code but only works if you have the chart settings to RTH Only - I can not get it to work on the ETH Chart as it shows the overnight levels i.e. ("Show Extended-Hours Trading session")

Is there a way to code this to run on an ETH only chart and only show the cash session/RTH High/Low?

#Plots RTH only High/Low
input OpenRangeMinutes = 5;
input MarketOpenTime = 0930;
input ShowTodayOnly = yes;

def Today = if GetDay() == GetLastDay() then 1 else 0;

#Plot yesterday's high / low
plot Yhigh = if ShowTodayOnly and !Today then Double.NaN else high(period = "day" )[1];
plot Ylow = if ShowTodayOnly and !Today then Double.NaN else low(period = "day" )[1];

Yhigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Yhigh.SetDefaultColor(Color.UPTICK);
Yhigh.SetLineWeight(2);
Ylow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Ylow.SetDefaultColor(Color.DOWNTICK);
Ylow.SetLineWeight(2);
Yes, you have to have the chart settings to RTH Only
 
I took this indicator from Robert and tweaked it a little to my need. Originally it plots the 5 min opening range breakout. However, I took that out and only keep the previous day high and low. Then I add some customizations to it to make the breakout or breakdown more noticeable.

Here is what it looks like:

3DOqpxq.png


When the price is within the previous day high and low range then you would see the color of the regular candle. When it's outside of the range then red candles become gray and green candles become white.

thinkScript Code

Rich (BB code):
# 5 min opening range
# Robert Payne
#Plot opening range high / low
input OpenRangeMinutes = 5;
input MarketOpenTime = 0930;
input ShowTodayOnly = yes;

def Today = if GetDay() == GetLastDay() then 1 else 0;
def FirstMinute = if SecondsFromTime(MarketOpenTime) < 60 then 1 else 0;
def OpenRangeTime = if SecondsFromTime(MarketOpenTime) < 60 * OpenRangeMinutes then 1 else 0;

#Plot yesterday's high / low
plot Yhigh = if ShowTodayOnly and !Today then Double.NaN else high(period = "day" )[1];
plot Ylow = if ShowTodayOnly and !Today then Double.NaN else low(period = "day" )[1];

Yhigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Yhigh.SetDefaultColor(Color.UPTICK);
Yhigh.SetLineWeight(2);
Ylow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Ylow.SetDefaultColor(Color.DOWNTICK);
Ylow.SetLineWeight(2);

#Plot pivot
plot Pivot = if ShowTodayOnly and !Today then Double.NaN else (high(period = "day" )[1] + low(period = "day" )[1] + close(period = "day" )[1]) / 3;
Pivot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Pivot.SetDefaultColor(Color.YELLOW);
Pivot.SetLineWeight(2);

#Plot 10 day high / low
plot TenHigh = if ShowTodayOnly and !Today then Double.NaN else Highest(high(period = "day" )[1], 10);
plot TenLow = if ShowTodayOnly and !Today then Double.NaN else Lowest(low(period = "day" )[1], 10);

TenHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
TenHigh.SetDefaultColor(Color.UPTICK);
TenHigh.SetLineWeight(3);
TenLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
TenLow.SetDefaultColor(Color.DOWNTICK);
TenLow.SetLineWeight(3);

AssignPriceColor(if close >= Yhigh then Color.GREEN
  else if close <= Ylow then Color.RED
  else Color.CURRENT);

AssignPriceColor(if close > Yhigh and open < close then Color.White
  else if close > YHIGH and open > close then Color.Gray
  else if close < Ylow and open < close then Color.White
  else if close < Ylow and open > close then Color.Gray
  else Color.CURRENT);

Shareable Link

https://tos.mx/tbjMgb

Previous Intradays High, Low, Mean

Code:
# Previous Intradays High, Low, Mean
# Mobius
# V01.12.2017 Desktop and Mobile
# Revised original code that uses SecondsFromTime() and SecondsTillTime(). Code now uses RegularTradingStart() and RegularTradingEnd() to bracket RTH. Works in Mobile Apps

def bar = barNumber();
def h = high;
def l = low;
def c = close;
def firstBar = if getTime() crosses above RegularTradingStart(GetYYYYMMDD()) and
                  !isNaN(close)
               then bar
               else double.nan;
def lastBar = if getTime() crosses above RegularTradingEnd(GetYYYYMMDD()) and
                 !isNaN(close)
              then bar
              else double.nan;
addVerticalLine(bar == HighestAll(firstBar), "first bar", color.cyan, curve.short_dash);
addVerticalLine(bar == HighestAll(lastBar), "last bar", color.cyan, curve.short_dash);
def bar_t1 = if !isNaN(firstBar)
            then bar
            else bar_t1[1];
def bar_t2 = if !isNaN(lastBar)
             then bar
             else bar_t2[1];
def prevFirstBar = if bar_t1 != bar_t1[1]
              then bar_t1[1]
              else prevFirstBar[1];
def prevLastBar = if bar_t2 != bar_t2[1]
                  then bar_t2[1]
                  else prevLastBar[1];
addVerticalLine(bar == HighestAll(prevFirstBar), "prev first bar", color.red, curve.short_dash);
addVerticalLine(bar == HighestAll(prevLastBar), "prev Last bar", color.red, curve.short_dash);
def hh = if bar == HighestAll(prevFirstBar)
         then h
         else if between(bar, highestAll(prevFirstBar), highestAll(LastBar)) and
                 h > hh[1]
              then h
              else hh[1];
def hhBar = if h == hh and between(bar, highestAll(prevFirstBar), highestAll(LastBar))
            then barNumber()
            else double.nan;
def ll = if bar == HighestAll(prevFirstBar)
         then l
         else if between(bar, highestAll(prevFirstBar), highestAll(LastBar)) and
                 l < ll[1]
              then l
              else ll[1];
def llBar = if l == ll and between(bar, highestAll(prevFirstBar), highestAll(LastBar))
            then bar
            else double.nan;
plot PrevDayHigh = if bar >= highestAll(hhBar)
                   then highestAll(if isNaN(c[-1])
                                   then hh
                                   else double.nan)
                   else double.nan;
     PrevDayHigh.SetStyle(Curve.Long_Dash);
     PrevDayHigh.SetLineWeight(3);
     PrevDayHigh.SetDefaultColor(Color.Green);
     PrevDayHigh.HideTitle();
plot PrevDayLow = if bar >= HighestAll(llBar)
                  then highestAll(if isNaN(c[-1])
                                  then ll
                                  else double.nan)
                  else double.nan;
     PrevDayLow.SetStyle(Curve.Long_Dash);
     PrevDayLow.SetLineWeight(3);
     PrevDayLow.SetDefaultColor(Color.Red);
     PrevDayLow.HideTitle();
def hl2bar = Floor((highestAll(hhbar) + highestAll(llBar)) / 2);
def hl2price = Round(((PrevDayHigh + PrevDayLow) / 2) / TickSize(), 0) * TickSize();
plot PrevDayHL2 = if bar >= highestAll(HL2bar)
               then highestAll(if !isNaN(c[-1])
                               then HL2price
                               else double.nan)
               else double.nan;
     PrevDayHL2.SetStyle(Curve.Long_Dash);
     PrevDayHL2.SetLineWeight(3);
     PrevDayHL2.SetDefaultColor(Color.Yellow);
     PrevDayHL2.HideTitle();
# End Code Previous Days High, Low, Mean
can someone add "close price" of previous day to this script?
i have problem configurate this one badly..thank you!

can someone add "close price" of previous day to this script? It is the only script that plot high, low, mean on mobile..THANK YOU!
 
can someone add "close price" of previous day to this script?
i have problem configurate this one badly..thank you!

can someone add "close price" of previous day to this script? It is the only script that plot high, low, mean on mobile..THANK YOU!

Just saw this. See if this helps.

Screenshot-2022-10-26-075419.png
Ruby:
# Previous Intradays High, Low, Mean
# Mobius
# V01.12.2017 Desktop and Mobile
# Revised original code that uses SecondsFromTime() and SecondsTillTime(). Code now uses RegularTradingStart() and RegularTradingEnd() to bracket RTH. Works in Mobile Apps

def bar = barNumber();
def h = high;
def l = low;
def c = close;
def firstBar = if getTime() crosses above RegularTradingStart(GetYYYYMMDD()) and
                  !isNaN(close)
               then bar
               else double.nan;
def lastBar = if getTime() crosses above RegularTradingEnd(GetYYYYMMDD()) and
                 !isNaN(close)
              then bar
              else double.nan;
addVerticalLine(bar == HighestAll(firstBar), "first bar", color.cyan, curve.short_dash);
addVerticalLine(bar == HighestAll(lastBar), "last bar", color.cyan, curve.short_dash);
def bar_t1 = if !isNaN(firstBar)
            then bar
            else bar_t1[1];
def bar_t2 = if !isNaN(lastBar)
             then bar
             else bar_t2[1];
def prevFirstBar = if bar_t1 != bar_t1[1]
              then bar_t1[1]
              else prevFirstBar[1];
def prevLastBar = if bar_t2 != bar_t2[1]
                  then bar_t2[1]
                  else prevLastBar[1];
addVerticalLine(bar == HighestAll(prevFirstBar), "prev first bar", color.red, curve.short_dash);
addVerticalLine(bar == HighestAll(prevLastBar), "prev Last bar", color.red, curve.short_dash);
def hh = if bar == HighestAll(prevFirstBar)
         then h
         else if between(bar, highestAll(prevFirstBar), highestAll(LastBar)) and
                 h > hh[1]
              then h
              else hh[1];
def hhBar = if h == hh and between(bar, highestAll(prevFirstBar), highestAll(LastBar))
            then barNumber()
            else double.nan;
def ll = if bar == HighestAll(prevFirstBar)
         then l
         else if between(bar, highestAll(prevFirstBar), highestAll(LastBar)) and
                 l < ll[1]
              then l
              else ll[1];
def llBar = if l == ll and between(bar, highestAll(prevFirstBar), highestAll(LastBar))
            then bar
            else double.nan;
plot PrevDayHigh = if bar >= highestAll(hhBar)
                   then highestAll(if isNaN(c[-1])
                                   then hh
                                   else double.nan)
                   else double.nan;
     PrevDayHigh.SetStyle(Curve.Long_Dash);
     PrevDayHigh.SetLineWeight(3);
     PrevDayHigh.SetDefaultColor(Color.Green);
     PrevDayHigh.HideTitle();
plot PrevDayLow = if bar >= HighestAll(llBar)
                  then highestAll(if isNaN(c[-1])
                                  then ll
                                  else double.nan)
                  else double.nan;
     PrevDayLow.SetStyle(Curve.Long_Dash);
     PrevDayLow.SetLineWeight(3);
     PrevDayLow.SetDefaultColor(Color.Red);
     PrevDayLow.HideTitle();
def hl2bar = Floor((highestAll(hhbar) + highestAll(llBar)) / 2);
def hl2price = Round(((PrevDayHigh + PrevDayLow) / 2) / TickSize(), 0) * TickSize();
plot PrevDayHL2 = if bar >= highestAll(HL2bar)
               then highestAll(if !isNaN(c[-1])
                               then HL2price
                               else double.nan)
               else double.nan;
     PrevDayHL2.SetStyle(Curve.Long_Dash);
     PrevDayHL2.SetLineWeight(3);
     PrevDayHL2.SetDefaultColor(Color.Yellow);
     PrevDayHL2.HideTitle();
# End Code Previous Days High, Low, Mean

def cc = if bar == HighestAll(prevFirstBar)
         then c
         else if between(bar, highestAll(prevFirstBar), highestAll(LastBar)) and
                 c
              then c
              else cc[1];
def ccBar = if cc and between(bar, highestAll(prevFirstBar), highestAll(LastBar))
            then bar
            else double.nan;
plot PrevDayclose = if bar >= highestAll(ccBar)
                   then highestAll(if isNaN(c[-1])
                                   then cc
                                   else double.nan)
                   else double.nan;
     PrevDayclose.SetStyle(Curve.Long_Dash);
     PrevDayclose.SetLineWeight(3);
     PrevDayclose.SetDefaultColor(Color.white);
     PrevDayclose.HideTitle();
 
Can anyone help me set up the following script?

I just want to get information for:
the maximum of the previous day and the minimum of the previous day.
I'm using the following example, but it only works for High, and I can't figure out why this is happening
Code:
#High From XYZ days ago INCLUDING EXT HOURS
#BY XeoNoX via usethikscript.com
# recommended aggregation should be 1 minute
#Days and time are according to USA Eastern (NewYork) time
#Change input Days_Ago to your desired days ago

Input Days_Ago = 2;

def lastDate = HighestAll( if GetDay() == GetLastDay() and GetYear() == GetLastYear() then GetYYYYMMDD() else Double.NaN );
def today = if GetYYYYMMDD() < lastDate then GetYYYYMMDD() else lastDate;
def priorday = if CountTradingDays(today, LastDate ) == Days_Ago then yes else no;

def PREV_ALL_DAY_HIGH = HighestAll(if  priorday then high else 0);
def PREV_ALL_DAY_LOW = LowestAll(if  priorday then low else 0);

AddLabel (yes, "High " + PREV_ALL_DAY_HIGH  +", Low " + PREV_ALL_DAY_LOW );
 
Can anyone help me set up the following script?

I just want to get information for:
the maximum of the previous day and the minimum of the previous day.
I'm using the following example, but it only works for High, and I can't figure out why this is happening
Code:
#High From XYZ days ago INCLUDING EXT HOURS
#BY XeoNoX via usethikscript.com
# recommended aggregation should be 1 minute
#Days and time are according to USA Eastern (NewYork) time
#Change input Days_Ago to your desired days ago

Input Days_Ago = 2;

def lastDate = HighestAll( if GetDay() == GetLastDay() and GetYear() == GetLastYear() then GetYYYYMMDD() else Double.NaN );
def today = if GetYYYYMMDD() < lastDate then GetYYYYMMDD() else lastDate;
def priorday = if CountTradingDays(today, LastDate ) == Days_Ago then yes else no;

def PREV_ALL_DAY_HIGH = HighestAll(if  priorday then high else 0);
def PREV_ALL_DAY_LOW = LowestAll(if  priorday then low else 0);

AddLabel (yes, "High " + PREV_ALL_DAY_HIGH  +", Low " + PREV_ALL_DAY_LOW );
I'll answer my own question.
In order for this code to work, you need to correct just one digit
Code:
def PREV_ALL_DAY_LOW = LowestAll(if  priorday then low else 0);
need to fix on
Code:
def PREV_ALL_DAY_LOW = LowestAll(if  priorday then low else 2000);
 
I'll answer my own question.
In order for this code to work, you need to correct just one digit
Code:
def PREV_ALL_DAY_LOW = LowestAll(if  priorday then low else 0);
need to fix on
Code:
def PREV_ALL_DAY_LOW = LowestAll(if  priorday then low else 2000);

You just need to substitute double.nan for 0 both high/low.

Ruby:
#High From XYZ days ago INCLUDING EXT HOURS
#BY XeoNoX via usethikscript.com
# recommended aggregation should be 1 minute
#Days and time are according to USA Eastern (NewYork) time
#Change input Days_Ago to your desired days ago

Input Days_Ago = 2;

def lastDate = HighestAll( if GetDay() == GetLastDay() and GetYear() == GetLastYear() then GetYYYYMMDD() else Double.NaN );
def today = if GetYYYYMMDD() < lastDate then GetYYYYMMDD() else lastDate;
def priorday = if CountTradingDays(today, LastDate ) == Days_Ago then yes else no;

def PREV_ALL_DAY_HIGH = HighestAll(if  priorday then high else double.nan);
def PREV_ALL_DAY_LOW = LowestAll(if  priorday then low else double.nan);

AddLabel (yes, "High " + PREV_ALL_DAY_HIGH  +", Low " + PREV_ALL_DAY_LOW );
 
Just saw this. See if this helps.
Hi @SleepyZ

Hope all is well! I was wondering if you could help me with an iteration of this study.

I was looking to see if it were possible to have a study plot price levels for the High and Low prices for the last 10D, 20D, 30D. However, lets say if the last 30D price High or Low was the same as the 10D high or low, it would just ignore it. So essentially, only one price level would plot.

I think I could try to piece that together based on the PlotTen in the above script, but the IF statement part was throwing me off.

Thanks in advance!!
 
Hi @SleepyZ

Hope all is well! I was wondering if you could help me with an iteration of this study.

I was looking to see if it were possible to have a study plot price levels for the High and Low prices for the last 10D, 20D, 30D. However, lets say if the last 30D price High or Low was the same as the 10D high or low, it would just ignore it. So essentially, only one price level would plot.

I think I could try to piece that together based on the PlotTen in the above script, but the IF statement part was throwing me off.

Thanks in advance!!

Using the code provided and a script function, this will plot 3 highs and 3 lows with bubbles.
If the highs or lows are the same, then the lines will appear as one and the bubbles will stack upon each other.
There is an option to only display the lines on the lastday only.
Make sure your chart has at least the highest number of days_ago viewing on your chart.

Screenshot-2023-02-09-141258.png
Code:
#High From XYZ days ago INCLUDING EXT HOURS
#BY XeoNoX via usethikscript.com
# recommended aggregation should be 1 minute
#Days and time are according to USA Eastern (NewYork) time
#Change input Days_Ago to your desired days ago

script hl {
    input Days_Ago = 2;

    def lastDate = HighestAll( if GetDay() == GetLastDay() and GetYear() == GetLastYear() then GetYYYYMMDD() else Double.NaN );
    def today = if GetYYYYMMDD() < lastDate then GetYYYYMMDD() else lastDate;
    def priorday = if CountTradingDays(today, lastDate ) == Days_Ago then yes else no;

    plot PREV_ALL_DAY_HIGH = if CountTradingDays(today, lastDate ) > Days_Ago then Double.NaN else HighestAll(if priorday then high else Double.NaN);
    plot PREV_ALL_DAY_LOW = if CountTradingDays(today, lastDate ) > Days_Ago then Double.NaN else LowestAll(if  priorday then low else Double.NaN);

#AddLabel (yes, "High " + PREV_ALL_DAY_HIGH  +", Low " + PREV_ALL_DAY_LOW );
}

input days_ago_1 = 10;
input days_ago_2 = 20;
input days_ago_3 = 30;

input show_on_lastday_only = yes;
def lastday = GetDay() == GetLastDay();
plot H1 = if show_on_lastday_only and lastday then hl(days_ago_1) else if !show_on_lastday_only then hl(days_ago_1) else Double.NaN;
plot H2 = if show_on_lastday_only and lastday then hl(days_ago_2) else if !show_on_lastday_only then hl(days_ago_2) else Double.NaN;
plot H3 = if show_on_lastday_only and lastday then hl(days_ago_3) else if !show_on_lastday_only then hl(days_ago_3) else Double.NaN;

plot L1 = if show_on_lastday_only and lastday then hl(days_ago_1).PREV_ALL_DAY_LOW else if !show_on_lastday_only then hl(days_ago_1).PREV_ALL_DAY_LOW else Double.NaN;
plot L2 = if show_on_lastday_only and lastday then hl(days_ago_2).PREV_ALL_DAY_LOW else if !show_on_lastday_only then hl(days_ago_2).PREV_ALL_DAY_LOW else Double.NaN;
plot L3 = if show_on_lastday_only and lastday then hl(days_ago_3).PREV_ALL_DAY_LOW else if !show_on_lastday_only then hl(days_ago_3).PREV_ALL_DAY_LOW else Double.NaN;

DefineGlobalColor("HL10", Color.CYAN);
DefineGlobalColor("HL20", Color.WHITE);
DefineGlobalColor("HL30", Color.YELLOW);

H1.SetDefaultColor(GlobalColor("HL10"));
L1.SetDefaultColor(GlobalColor("HL10"));
H2.SetDefaultColor(GlobalColor("HL20"));
L2.SetDefaultColor(GlobalColor("HL20"));
H3.SetDefaultColor(GlobalColor("HL30"));
L3.SetDefaultColor(GlobalColor("HL30"));

input show_bubbles = yes;
input bubblemover  = 2;
def b = bubblemover;
def b1 = b + 1;
AddChartBubble(IsNaN(close[b]) and !IsNaN(close[b1]), H1[b], "10H", H1.TakeValueColor());
AddChartBubble(IsNaN(close[b]) and !IsNaN(close[b1]), H2[b], "20H", H2.TakeValueColor());
AddChartBubble(IsNaN(close[b]) and !IsNaN(close[b1]), H3[b], "30H", H3.TakeValueColor());

AddChartBubble(IsNaN(close[b]) and !IsNaN(close[b1]), L1[b], "10L", L1.TakeValueColor());
AddChartBubble(IsNaN(close[b]) and !IsNaN(close[b1]), L2[b], "20L", L2.TakeValueColor());
AddChartBubble(IsNaN(close[b]) and !IsNaN(close[b1]), L3[b], "30L", L3.TakeValueColor());
 
Using the code provided and a script function, this will plot 3 highs and 3 lows with bubbles.
If the highs or lows are the same, then the lines will appear as one and the bubbles will stack upon each other.
There is an option to only display the lines on the lastday only.
Make sure your chart has at least the highest number of days_ago viewing on your chart.
Thank you!

I think I may not have explained what I was trying to get at correctly.

So from the above code, correct me if I'm wrong, but what it is doing is taking the High and Low from 10 days ago, 20 days ago, 30 days ago, and plotting those lines correct?

What I was trying to see that could be done would be to do this. Hopefully this makes sense, please let me know. My apologies if what I originally described did not articulate what my goal was.

While I was looking for the study to look back 10 days, 20 days, 30 days, I was looking to have it plot the lines for what the high and low price was within that aggregated period.

For example, on 10 days. It would look back 10 days and plot 2 price levels. One of the price high and price low within that 10 day aggregated period. Then do the same for the last 20 days and 30 days.

If the price high and low lets say in the 30 day period matches what was in either the 10day or 20 day, it would just plot the same line or not plot the duplicate price levels at all.

Sorry if the original line of codes you just wrote took some time to put together, I feel bad if so.
 
Thank you!

I think I may not have explained what I was trying to get at correctly.

So from the above code, correct me if I'm wrong, but what it is doing is taking the High and Low from 10 days ago, 20 days ago, 30 days ago, and plotting those lines correct?

What I was trying to see that could be done would be to do this. Hopefully this makes sense, please let me know. My apologies if what I originally described did not articulate what my goal was.

While I was looking for the study to look back 10 days, 20 days, 30 days, I was looking to have it plot the lines for what the high and low price was within that aggregated period.

For example, on 10 days. It would look back 10 days and plot 2 price levels. One of the price high and price low within that 10 day aggregated period. Then do the same for the last 20 days and 30 days.

If the price high and low lets say in the 30 day period matches what was in either the 10day or 20 day, it would just plot the same line or not plot the duplicate price levels at all.

Sorry if the original line of codes you just wrote took some time to put together, I feel bad if so.

Here is a mod to capture the highest high and lowest low in the range of days_ago to present day. The bubbles will show when multiple highs/lows are the same.

Screenshot-2023-02-10-033044.png
Code:
#High From XYZ days ago INCLUDING EXT HOURS

script hl {
    input Days_Ago = 2;
    def ymd      = GetYYYYMMDD();
    def candles  = !IsNaN(close);
    def capture  = candles and ymd != ymd[1];
    def dayCount = CompoundValue(1, if capture then dayCount[1] + 1 else dayCount[1], 0);
    def thisDay  = (HighestAll(dayCount) - dayCount) ;
    def H = if thisDay == Days_Ago then high else if thisDay <= Days_Ago then Max(high, H[1]) else Double.NaN;
    plot HH = if thisDay > Days_Ago then Double.NaN else HighestAll(H);
    def L = if thisDay == Days_Ago then low else if thisDay <= Days_Ago then Min(low, L[1]) else Double.NaN;
    plot LL = if thisDay > Days_Ago then Double.NaN else LowestAll(L);
}

input days_ago_1 = 10;
input days_ago_2 = 20;
input days_ago_3 = 30;

input show_on_lastday_only = no;
def lastday = GetDay() == GetLastDay();
plot H1 = if show_on_lastday_only and lastday then hl(days_ago_1) else if !show_on_lastday_only then hl(days_ago_1) else Double.NaN;
plot H2 = if show_on_lastday_only and lastday then hl(days_ago_2) else if !show_on_lastday_only then hl(days_ago_2) else Double.NaN;
plot H3 = if show_on_lastday_only and lastday then hl(days_ago_3) else if !show_on_lastday_only then hl(days_ago_3) else Double.NaN;

plot L1 = if show_on_lastday_only and lastday then hl(days_ago_1).LL else if !show_on_lastday_only then hl(days_ago_1).LL else Double.NaN;
plot L2 = if show_on_lastday_only and lastday then hl(days_ago_2).LL else if !show_on_lastday_only then hl(days_ago_2).LL else Double.NaN;
plot L3 = if show_on_lastday_only and lastday then hl(days_ago_3).LL else if !show_on_lastday_only then hl(days_ago_3).LL else Double.NaN;

DefineGlobalColor("HL10", Color.CYAN);
DefineGlobalColor("HL20", Color.WHITE);
DefineGlobalColor("HL30", Color.YELLOW);

H1.SetDefaultColor(GlobalColor("HL10"));
L1.SetDefaultColor(GlobalColor("HL10"));
H2.SetDefaultColor(GlobalColor("HL20"));
L2.SetDefaultColor(GlobalColor("HL20"));
H3.SetDefaultColor(GlobalColor("HL30"));
L3.SetDefaultColor(GlobalColor("HL30"));

input show_bubbles = yes;
input bubblemover  = 2;
def b = bubblemover;
def b1 = b + 1;
AddChartBubble(IsNaN(close[b]) and !IsNaN(close[b1]), H1[b], "10H", H1.TakeValueColor());
AddChartBubble(IsNaN(close[b]) and !IsNaN(close[b1]), H2[b], "20H", H2.TakeValueColor());
AddChartBubble(IsNaN(close[b]) and !IsNaN(close[b1]), H3[b], "30H", H3.TakeValueColor());

AddChartBubble(IsNaN(close[b]) and !IsNaN(close[b1]), L1[b], "10L", L1.TakeValueColor());
AddChartBubble(IsNaN(close[b]) and !IsNaN(close[b1]), L2[b], "20L", L2.TakeValueColor());
AddChartBubble(IsNaN(close[b]) and !IsNaN(close[b1]), L3[b], "30L", L3.TakeValueColor());
 
Here is a mod to capture the highest high and lowest low in the range of days_ago to present day. The bubbles will show when multiple highs/lows are the same.
Hey SleepyZ!

Quick question on this, do you mind confirming the fact this won't update if a new low/high is hit in current day correct? For example, lets say 10L is 4000 and in the current day session we hit 3998. Until tomorrow, the marked price level from the indicator will remain at 4000 and not update intraday correct?
 
Last edited:

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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