# prevday_levels_onalldays_01
# halcyonguy
# 21-08-12
#
# find high and low , of 2 previous periods, day and week.
# draw a horizontal line across the chart, at the 4 price levels.
# can change the offset , to look at older periods.
# 2 yellow lines, identify the 2 time periods.
# bubbles on the right, identify the lines.
# the bubbles list the offset.
# Modifications by Tim G
#Sept 14, 2021
#Show/hide aggregation periods
input show1hr = no;
input show2hr = no;
input show4hr = no;
input show1d = yes;
input show1dOp = yes;
input show1w = yes;
input show1WOp = yes;
input show1mo = yes;
input show1MOp = yes;
input show1q = no;
input offset = 1;
# place bubbles after last bar, to id the lines
def futurebar = 6;
def x = (!IsNaN(close[futurebar]) and IsNaN(close[futurebar - 1]));
def futurebary = 3;
def y = (!IsNaN(close[futurebary]) and IsNaN(close[futurebary - 1]));
def futurebarz = 9;
def z = (!IsNaN(close[futurebarz]) and IsNaN(close[futurebarz - 1]));
### 1H timeframe ###
def tf1h = AggregationPeriod.HOUR;
def valid1h = GetAggregationPeriod() <= AggregationPeriod.HOUR;
def h1h;
def l1h;
def o1h;
def o1hc;
def c1h;
def D1h = Round(c1h - o1h);
if valid1h and show1hr {
h1h = high (period = tf1h)[offset];
l1h = low (period = tf1h)[offset];
o1h = open (period = tf1h)[offset];
o1hc = open (period = tf1h);
c1h = close(period = tf1h)[offset];
} else {
h1h = Double.NaN;
l1h = Double.NaN;
o1h = Double.NaN;
o1hc = Double.NaN;
c1h = Double.NaN;
}
plot hourlow = HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) then l1h else Double.NaN);
plot hourhigh = HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) then h1h else Double.NaN);
plot houropen = HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) then o1hc else Double.NaN);
plot houropen2 = HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) then o1hc else Double.NaN);
hourlow.SetDefaultColor(Color.MAGENTA);
hourhigh.SetDefaultColor(Color.LIGHT_GREEN);
houropen.SetDefaultColor(Color.GREEN);
houropen.SetStyle(Curve.SHORT_DASH);
houropen2.SetDefaultColor(Color.LIGHT_RED);
houropen.SetLineWeight(2);
houropen2.SetLineWeight(2);
# place bubbles after last bar, to id the lines
AddChartBubble(x, hourlow, "H[" + offset + "]", Color.MAGENTA, yes);
AddChartBubble(x, hourhigh, "H[" + offset + "]", Color.GREEN, yes);
AddChartBubble(x, houropen, "H O", Color.CYAN, yes);
### 2H timeframe ###
def tf2h = AggregationPeriod.TWO_HOURS;
def valid2h = GetAggregationPeriod() <= AggregationPeriod.TWO_HOURS;
def h2h;
def l2h;
def o2h;
def o2hc;
def c2h;
def D2h = Round(c2h - o2h);
if valid2h and show2hr {
h2h = high (period = tf2h)[offset];
l2h = low (period = tf2h)[offset];
o2h = open (period = tf2h)[offset];
o2hc = open (period = tf2h);
c2h = close(period = tf2h)[offset];
} else {
h2h = Double.NaN;
l2h = Double.NaN;
o2h = Double.NaN;
o2hc = Double.NaN;
c2h = Double.NaN;
}
plot twohourlow = HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) then l2h else Double.NaN);
plot twohourhigh = HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) then h2h else Double.NaN);
plot twohouropen = HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) then o2hc else Double.NaN);
plot twohouropen2 = HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) then o2hc else Double.NaN);
twohourlow.SetDefaultColor(Color.MAGENTA);
twohourhigh.SetDefaultColor(Color.LIGHT_GREEN);
twohouropen.SetDefaultColor(Color.GREEN);
twohouropen.SetStyle(Curve.SHORT_DASH);
twohouropen2.SetDefaultColor(Color.LIGHT_RED);
twohouropen.SetLineWeight(2);
twohouropen2.SetLineWeight(2);
# place bubbles after last bar, to id the lines
AddChartBubble(x, twohourlow, "2H[" + offset + "]", Color.MAGENTA, yes);
AddChartBubble(x, twohourhigh, "2H[" + offset + "]", Color.GREEN, yes);
AddChartBubble(x, twohouropen, "2H O", Color.CYAN, yes);
### 4h timeframe ###
def tf4h = AggregationPeriod.FOUR_HOURS;
def valid4h = GetAggregationPeriod() <= AggregationPeriod.FOUR_HOURS;
def h4h;
def l4h;
def o4h;
def o4hc;
def c4h;
def D4h = Round(c4h - o4h);
if valid4h and show4hr {
h4h = high (period = tf4h)[offset];
l4h = low (period = tf4h)[offset];
o4h = open (period = tf4h)[offset];
o4hc = open (period = tf4h);
c4h = close(period = tf4h)[offset];
} else {
h4h = Double.NaN;
l4h = Double.NaN;
o4h = Double.NaN;
o4hc = Double.NaN;
c4h = Double.NaN;
}
plot fourhourlow = HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) then l4h else Double.NaN);
plot fourhourhigh = HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) then h4h else Double.NaN);
plot fourhouropen = HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) then o4hc else Double.NaN);
;
plot fourhouropen2 = HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) then o4hc else Double.NaN);
fourhourlow.SetDefaultColor(Color.MAGENTA);
fourhouropen.SetDefaultColor(Color.GREEN);
fourhouropen.SetStyle(Curve.SHORT_DASH);
fourhouropen2.SetDefaultColor(Color.LIGHT_RED);
fourhouropen.SetLineWeight(2);
fourhouropen2.SetLineWeight(2);
# place bubbles after last bar, to id the lines
AddChartBubble(x, fourhourlow, "4H[" + offset + "]", Color.MAGENTA, yes);
AddChartBubble(x, fourhourhigh, "4H[" + offset + "]", Color.GREEN, yes);
AddChartBubble(x, fourhouropen, "4H O", Color.CYAN, yes);
### 1d timeframe ###
def tf1d = AggregationPeriod.DAY;
def valid1d = GetAggregationPeriod() <= AggregationPeriod.DAY;
def h1d;
def l1d;
def o1d;
def o1dc;
def c1d;
def D1d = Round(c1d - o1d);
if valid1d and show1d {
h1d = high (period = tf1d)[offset];
l1d = low (period = tf1d)[offset];
o1d = open (period = tf1d)[offset];
o1dc = open (period = tf1d);
c1d = close(period = tf1d)[offset];
} else {
h1d = Double.NaN;
l1d = Double.NaN;
o1d = Double.NaN;
o1dc = Double.NaN;
c1d = Double.NaN;
}
plot daylow = HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) then l1d else Double.NaN);
plot dayhigh = HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) then h1d else Double.NaN);
plot daylow2 = HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) then l1d else Double.NaN);
plot dayhigh2 = HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) then h1d else Double.NaN);
plot dayopen = HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) and show1dOp then o1dc else Double.NaN);
plot dayopen2 = HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) and show1dOp then o1dc else Double.NaN);
dayhigh.SetDefaultColor(Color.YELLOW);
dayhigh.SetStyle(Curve.SHORT_DASH);
dayhigh.SetLineWeight(1);
dayhigh2.SetDefaultColor(Color.CYAN);
dayhigh2.SetLineWeight(1);
daylow.SetDefaultColor(Color.YELLOW);
daylow.SetStyle(Curve.SHORT_DASH);
daylow.SetLineWeight(1);
daylow2.SetDefaultColor(Color.CYAN);
daylow2.SetLineWeight(1);
dayopen.SetDefaultColor(Color.DARK_GREEN);
dayopen.SetStyle(Curve.SHORT_DASH);
dayopen2.SetDefaultColor(Color.DARK_RED);
dayopen.SetLineWeight(1);
dayopen2.SetLineWeight(1);
AddChartBubble(x, daylow, "D[" + offset + "]", Color.MAGENTA, yes);
AddChartBubble(y, dayhigh, "D[" + offset + "]", Color.GREEN, yes);
AddChartBubble(z, dayopen, "D O", Color.CYAN, yes);
### 1w timeframe ###
def tf1w = AggregationPeriod.WEEK;
def valid1w = GetAggregationPeriod() <= AggregationPeriod.WEEK;
def h1w;
def l1w;
def o1w;
def o1wc;
def c1w;
def D1w = Round(c1w - o1w);
if valid1w and show1w {
h1w = high (period = tf1w)[offset];
l1w = low (period = tf1w)[offset];
o1w = open (period = tf1w)[offset];
o1wc = open (period = tf1w);
c1w = close(period = tf1w)[offset];
} else {
h1w = Double.NaN;
l1w = Double.NaN;
o1w = Double.NaN;
o1wc = Double.NaN;
c1w = Double.NaN;
}
plot weeklow = HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) then l1w else Double.NaN);
plot weekhigh = HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) then h1w else Double.NaN);
plot weeklow2 = HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) then l1w else Double.NaN);
plot weekhigh2 = HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) then h1w else Double.NaN);
plot weekopen = HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) and show1WOp then o1wc else Double.NaN);
plot weekopen2 = HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) and show1WOp then o1wc else Double.NaN);
weekhigh.SetDefaultColor(Color.WHITE);
weekhigh.SetStyle(Curve.SHORT_DASH);
weekhigh.SetLineWeight(1);
weekhigh2.SetDefaultColor(Color.PLUM);
weekhigh2.SetLineWeight(1);
weeklow.SetDefaultColor(Color.WHITE);
weeklow.SetStyle(Curve.SHORT_DASH);
weeklow.SetLineWeight(1);
weeklow2.SetDefaultColor(Color.PLUM);
weeklow2.SetLineWeight(1);
weekopen.SetDefaultColor(Color.DARK_GREEN);
weekopen.SetStyle(Curve.SHORT_DASH);
weekopen2.SetDefaultColor(Color.DARK_RED);
weekopen.SetLineWeight(2);
weekopen2.SetLineWeight(2);
# place bubbles after last bar, to id the lines
AddChartBubble(z, weeklow, "W[" + offset + "]", Color.MAGENTA, yes);
AddChartBubble(x, weekhigh, "W[" + offset + "]", Color.GREEN, yes);
AddChartBubble(y, weekopen, "W O", Color.CYAN, yes);
### 1month timeframe ###
def tf1m = AggregationPeriod.MONTH;
def valid1m = GetAggregationPeriod() <= AggregationPeriod.MONTH;
def h1m;
def l1m;
def o1m;
def o1mc;
def c1m;
def D1m = Round(c1m - o1m);
if valid1m and show1mo {
h1m = high (period = tf1m)[offset];
l1m = low (period = tf1m)[offset];
o1m = open (period = tf1m)[offset];
o1mc = open (period = tf1m);
c1m = close(period = tf1m)[offset];
} else {
h1m = Double.NaN;
l1m = Double.NaN;
o1m = Double.NaN;
o1mc = Double.NaN;
c1m = Double.NaN;
}
plot monthlow = HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) then l1m else Double.NaN);
plot monthhigh = HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) then h1m else Double.NaN);
plot monthopen = HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) and show1MOp then o1mc else Double.NaN);
plot monthopen2 = HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) and show1MOp then o1mc else Double.NaN);
monthlow.SetDefaultColor(Color.CYAN);
monthhigh.SetDefaultColor(Color.CYAN);
monthopen.SetDefaultColor(Color.DARK_GREEN);
monthopen.SetStyle(Curve.SHORT_DASH);
monthopen2.SetDefaultColor(Color.DARK_RED);
monthopen.SetLineWeight(2);
monthopen2.SetLineWeight(2);
# place bubbles after last bar, to id the lines
AddChartBubble(y, monthlow, "M[" + offset + "]", Color.MAGENTA, yes);
AddChartBubble(z, monthhigh, "M[" + offset + "]", Color.GREEN, yes);
AddChartBubble(x, monthopen, "M O", Color.CYAN, yes);
### 1quarter timeframe ###
def tf1q = AggregationPeriod.QUARTER;
def valid1q = GetAggregationPeriod() <= AggregationPeriod.QUARTER;
def h1q;
def l1q;
def o1q;
def o1qc;
def c1q;
def D1q = Round(c1q - o1q);
if valid1q and show1q {
h1q = high (period = tf1q)[offset];
l1q = low (period = tf1q)[offset];
o1q = open (period = tf1q)[offset];
o1qc = open (period = tf1q);
c1q = close(period = tf1q)[offset];
} else {
h1q = Double.NaN;
l1q = Double.NaN;
o1q = Double.NaN;
o1qc = Double.NaN;
c1q = Double.NaN;
}
plot quarterlow = HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) then l1q else Double.NaN);
plot quarterhigh = HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) then h1q else Double.NaN);
plot quarteropen = HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) then o1qc else Double.NaN);
plot quarteropen2 = HighestAll( if (!IsNaN(close) and IsNaN(close[-1])) then o1qc else Double.NaN);
quarterlow.SetDefaultColor(Color.MAGENTA);
quarterhigh.SetDefaultColor(Color.LIGHT_GREEN);
quarteropen.SetDefaultColor(Color.GREEN);
quarteropen.SetStyle(Curve.SHORT_DASH);
quarteropen2.SetDefaultColor(Color.LIGHT_RED);
quarteropen.SetLineWeight(2);
quarteropen2.SetLineWeight(2);
# place bubbles after last bar, to id the lines
AddChartBubble(y, quarterlow, "Q[" + offset + "]", Color.MAGENTA, yes);
AddChartBubble(y, quarterhigh, "Q[" + offset + "]", Color.GREEN, yes);
AddChartBubble(y, quarteropen, "Q O", Color.CYAN, yes);
def cond1 = (h1w - h1d) + c1d;
plot cond2 = if c1d * 1.05 >= cond1 then 1 else 0;