Previous Day High and Low Breakout Indicator for ThinkorSwim

BenTen

BenTen

Administrative
Staff
VIP
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:



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

http://tos.mx/tbjMgb
 
Last edited:
D

desirobinhood

New member
Indicator to show previous day High Low and Close on the current day chart


Rich (BB code):
input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = yes;
plot PrevDayHigh;
plot PrevDayLow;
plot PrevDayClose;

if showOnlyLastPeriod and !IsNaN(high(period = aggregationPeriod)[-1]) and !IsNaN(low(period = aggregationPeriod)[-1]) and !IsNaN(close(period = aggregationPeriod)[-1])
{
    PrevDayHigh = Double.NaN;
    PrevDayLow = Double.NaN;
    PrevDayClose = Double.NaN;
}
else
{
    PrevDayHigh = Highest(high(period = aggregationPeriod)[-displace], length);
    PrevDayLow = Highest(low(period = aggregationPeriod)[-displace], length);
    PrevDayClose = Highest(close(period = aggregationPeriod)[-displace], length);
}
PrevDayHigh.SetDefaultColor(CreateColor(0,255,255));
PrevDayHigh.SetPaintingStrategy(PaintingStrategy.LINE);

PrevDayLow.SetDefaultColor(CreateColor(0,255,255));
PrevDayLow.SetPaintingStrategy(PaintingStrategy.LINE);

PrevDayClose.SetDefaultColor(CreateColor(116,189,239));
PrevDayClose.SetPaintingStrategy(PaintingStrategy.LINE);
PrevDayClose.SetStyle(Curve.LONG_DASH)
 
J

jayboo876

New member
How would you apply this to the tos scanner to alert when price goes outside of "yesterday's range on a 5min chart? I know tos has limitations around custom scan having different time frames - in this case a 5min and daily time frame. Thank you.
 
T

tomsk

Well-known member
VIP
How would you apply this to the tos scanner to alert when price goes outside of "yesterday's range on a 5min chart? I know tos has limitations around custom scan having different time frames - in this case a 5min and daily time frame. Thank you.
@jayboo876 Here is a real simple way to scan for stocks that are breaking above the previous day's high. Since it is after market hours now, try this scan when trading resumes on Monday

Code:
# High Low Previous Day Breakout Scan
# tomsk
# 12.7.2019

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;
# End High Low Previous Day Breakout Scan
If you wish to scan for stocks that are breaking down from yesterday's low, then replace the scan statement with the following in the code above

Code:
plot scan = close crosses below previousLow;
 
J

jposeyx2

New member
what are you referring to as a scan....how is the code applied in TOS ?
 
U

Utajiri

New member
I need help with a pretty simple script? I want to plot the previous OHLC price that draws a line across the chart (end to end) - with multiple time aggregation periods. Such that I can overlay (for instance) the 4hr previous closing price (drawn as a line) and overlay it on the 3min time frame. Also want to be able to turn on/off which of the price types (of the previous OHLC) I want to use at any time. I appreciate the help
 
Welkin

Welkin

Active member
VIP
@Utajiri give this a try, put this together based off of another previous ohlc indicator.

Although it doesn't plot across the entire chart, its a good starting point for what you want.

http://tos.mx/Kg3P3Du

Code:
#MTF Prev OHLC


def NA = Double.NaN;
input Aggregation1 = AggregationPeriod.DAY;
input Aggregation2 = AggregationPeriod.HOUR;
input Aggregation3 = AggregationPeriod.FIFTEEN_MIN;

input ShowAgg1O = yes;
input ShowAgg1H = yes;
input ShowAgg1L = yes;
input ShowAgg1C = yes;

input ShowAgg2O = no;
input ShowAgg2H = no;
input ShowAgg2L = no;
input ShowAgg2C = no;

input ShowAgg3O = no;
input ShowAgg3H = no;
input ShowAgg3L = no;
input ShowAgg3C = no;

input length1 = 1;
input length2 = 1;
input length3 = 1;

input displace1 = -1;
input displace2 = -1;
input displace3 = -1;

input showOnlyLastPeriod1 = no;
input showOnlyLastPeriod2 = no;
input showOnlyLastPeriod3 = no;

plot Agg1O;
plot Agg1H;
plot Agg1L;
plot Agg1C;

plot Agg2O;
plot Agg2H;
plot Agg2L;
plot Agg2C;

plot Agg3O;
plot Agg3H;
plot Agg3L;
plot Agg3C;

#Agg1
if showOnlyLastPeriod1 and !IsNaN(open(period = Aggregation1)[-1]) { Agg1O = Double.NaN; }
else { Agg1O = Highest(open(period = Aggregation1)[-displace1], length1); }

if showOnlyLastPeriod1 and !IsNaN(high(period = Aggregation1)[-1]) { Agg1H = Double.NaN; }
else { Agg1H = Highest(high(period = Aggregation1)[-displace1], length1); }

if showOnlyLastPeriod1 and !IsNaN(low(period = Aggregation1)[-1]) { Agg1L = Double.NaN; }
else { Agg1L = Highest(low(period = Aggregation1)[-displace1], length1); }

if showOnlyLastPeriod1 and !IsNaN(close(period = Aggregation1)[-1]) { Agg1C = Double.NaN; }
else { Agg1C = Highest(close(period = Aggregation1)[-displace1], length1); }

#Agg2
if showOnlyLastPeriod2 and !IsNaN(open(period = Aggregation2)[-1]) { Agg2O = Double.NaN; }
else { Agg2O = Highest(open(period = Aggregation2)[-displace2], length2); }

if showOnlyLastPeriod2 and !IsNaN(high(period = Aggregation2)[-1]) { Agg2H = Double.NaN; }
else { Agg2H = Highest(high(period = Aggregation2)[-displace2], length2); }

if showOnlyLastPeriod2 and !IsNaN(low(period = Aggregation2)[-1]) { Agg2L = Double.NaN; }
else { Agg2L = Highest(low(period = Aggregation2)[-displace2], length2); }

if showOnlyLastPeriod2 and !IsNaN(close(period = Aggregation2)[-1]) { Agg2C = Double.NaN; }
else { Agg2C = Highest(close(period = Aggregation2)[-displace2], length2); }

#Agg3

if showOnlyLastPeriod3 and !IsNaN(open(period = Aggregation3)[-1]) { Agg3O = Double.NaN; }
else { Agg3O = Highest(open(period = Aggregation3)[-displace3], length3); }

if showOnlyLastPeriod3 and !IsNaN(high(period = Aggregation3)[-1]) { Agg3H = Double.NaN; }
else { Agg3H = Highest(high(period = Aggregation3)[-displace3], length3); }

if showOnlyLastPeriod3 and !IsNaN(low(period = Aggregation3)[-1]) { Agg3L = Double.NaN; }
else { Agg3L = Highest(low(period = Aggregation3)[-displace3], length3); }

if showOnlyLastPeriod3 and !IsNaN(close(period = Aggregation3)[-1]) { Agg3C = Double.NaN; }
else { Agg3C = Highest(close(period = Aggregation3)[-displace3], length3); }


Agg1O.SetHiding(GetAggregationPeriod() >= Aggregation1 or !ShowAgg1O);
Agg1H.SetHiding(GetAggregationPeriod() >= Aggregation1 or !ShowAgg1H);
Agg1L.SetHiding(GetAggregationPeriod() >= Aggregation1 or !ShowAgg1L);
Agg1C.SetHiding(GetAggregationPeriod() >= Aggregation1 or !ShowAgg1C);

Agg2O.SetHiding(GetAggregationPeriod() >= Aggregation2 or !ShowAgg2O);
Agg2H.SetHiding(GetAggregationPeriod() >= Aggregation2 or !ShowAgg2H);
Agg2L.SetHiding(GetAggregationPeriod() >= Aggregation2 or !ShowAgg2L);
Agg2C.SetHiding(GetAggregationPeriod() >= Aggregation2 or !ShowAgg2C);

Agg3O.SetHiding(GetAggregationPeriod() >= Aggregation3 or !ShowAgg3O);
Agg3H.SetHiding(GetAggregationPeriod() >= Aggregation3 or !ShowAgg3H);
Agg3L.SetHiding(GetAggregationPeriod() >= Aggregation3 or !ShowAgg3L);
Agg3C.SetHiding(GetAggregationPeriod() >= Aggregation3 or !ShowAgg3C);

#Aggregation1 Format
Agg1O.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Agg1O.SetDefaultColor(Color.WHITE);
Agg1H.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Agg1H.SetDefaultColor(Color.GREEN);
Agg1L.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Agg1L.SetDefaultColor(Color.RED);
Agg1C.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Agg1C.SetDefaultColor(Color.YELLOW);

#Aggregation2 Format
Agg2O.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Agg2O.SetDefaultColor(Color.WHITE);
Agg2H.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Agg2H.SetDefaultColor(Color.GREEN);
Agg2L.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Agg2L.SetDefaultColor(Color.RED);
Agg2C.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Agg2C.SetDefaultColor(Color.YELLOW);

#Aggregation3 Format
Agg3O.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Agg3O.SetDefaultColor(Color.WHITE);
Agg3H.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Agg3H.SetDefaultColor(Color.GREEN);
Agg3L.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Agg3L.SetDefaultColor(Color.RED);
Agg3C.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Agg3C.SetDefaultColor(Color.YELLOW);
 
Last edited:
U

Utajiri

New member
@Welkin Thanks a lot for giving this a shot. I would check it out.... I appreciate!
 
W

westgl

New member
The way I use the Daily High/Low that is in TOS. I put it on a 5Min chart, but switch the high/low to a 30min High/Low or an Hour High low on my 5min chart, as I want to know when the 5 min breaks above the 30 or Hour and Not have to watch the 30 min or Hour chart. I dont believe that this script version has selectable time frame that would be very Nice also alerts on it would be great. Is that Possible? I also use this on the Daily chart and have a weekly high low breakout on it, for Longer term momentum moves.
 
C

C4men

New member
@BenTen forgive me, I am fairly new.

Would there be a way to paint three horizontal lines on "non-trading" hours (mostly on intraday)?

  • Set a timeframe, such as 400pm to 915am, in the settings
  • Paint the High of that timeframe
  • Paint the Low of that timeframe
  • Paint the Median of that timeframe

Trying to measure some after-hours / premarket movement, but not sure how to get there. Would love to see things that went crazy overnight or are picking up steam heading into the open. Those three lines would get me headed in the right direction (I think).
 
D

divinci01

New member
@tomsk I tried to get this to work but doesn't want to pull up any results. Have you had any luck with this scan?
 
Top