# prev_hour_exceed_00e
# https://usethinkscript.com/threads/buy-side-or-sell-side-liquidity-sweep.14735/
#Buy side or sell side liquidity sweep
# acom mar 5, 2023
#Looking for custom tos indicator which can alert with chart highlight upon buyside or sellside liquidity sweep on 2 min chart. Consideration should be taken for break of wick in prior 1 hour price action. This will be used for ES chart primarily. Can someone help in making this custom indicator?
#wick exceeding prior 1 hour price action range
def na = double.nan;
def bn = barnumber();
input sym2 = "/ES:XCME";
#---------------------------------
# get chart agg time
def chartagg = getaggregationperiod();
def chartmin = chartagg/(1000*60);
#---------------------------------
# pick an agg time for the longer time period
input agg = AggregationPeriod.HOUR;
def aggmin = agg/60000;
#---------------------------------
def data = close(period = agg);
def aggratio = aggmin/chartmin;
def daybars = 390 / chartmin;
def dayaggbars = 390/aggmin;
#---------------------------------
input agg_labels = yes;
addlabel(agg_labels, " ", color.black);
addlabel(agg_labels, "chart min " + chartmin, color.yellow);
addlabel(agg_labels, "day bars " + daybars, color.yellow);
addlabel(agg_labels, " ", color.black);
addlabel(agg_labels, "agg min " + aggmin, color.yellow);
addlabel(agg_labels, "agg day bars " + dayaggbars, color.yellow);
addlabel(agg_labels, " ", color.black);
addlabel(agg_labels, "agg ratio " + aggratio, color.yellow);
addlabel(agg_labels, " ", color.black);
#---------------------------------
def start3 = 0000;
def tminoff = if getsymbol() == sym2 then 0 else 30;
# if normal trading hours, add offset so an hour period starts at xx:30
def start3_min = (secondsfromTime(start3)/60) + tminoff;
def t1 = (start3_min % aggmin);
def t2 = if t1 == 0 then 1 else 0;
def t3 = if bn == 1 then 1
else if t2 then t3[1] + 1
else t3[1];
# find hi and lo of a time period,
def big = 99999;
def thi;
def tlo;
if t2 then {
thi = fold i1 = 0 to 200
with p1
while getvalue(t3, -i1) == t3
do if getvalue(high, -i1) > p1 then getvalue(high, -i1) else p1;
tlo = fold i2 = 0 to 200
with p2 = big
while getvalue(t3, -i2) == t3
do if getvalue(low, -i2) < p2 then getvalue(low, -i2) else p2;
} else {
thi = thi[1];
tlo = tlo[1];
}
# current period lines
input show_current_period_lines = no;
plot z1 = if show_current_period_lines then thi else na;
plot z2 = if show_current_period_lines then tlo else na;
z1.SetDefaultColor(Color.green);
z2.SetDefaultColor(Color.red);
z1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#------------------------------
# prev period lines
def t2hi = getvalue(thi, aggratio);
def t2lo = getvalue(tlo, aggratio);
input show_previous_period_lines = yes;
plot z3 = if show_previous_period_lines then t2hi else na;
plot z4 = if show_previous_period_lines then t2lo else na;
z3.SetDefaultColor(Color.cyan);
z4.SetDefaultColor(Color.yellow);
z3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#-----------------------------
def xup = if high crosses above t2hi then 1 else 0;
def xdwn = if low crosses below t2lo then 1 else 0;
def vert = 0.0004;
plot z2u = if xup then (low*(1-vert)) else na;
z2u.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
z2u.SetDefaultColor(Color.green);
z2u.setlineweight(3);
z2u.hidebubble();
plot z2d = if xdwn then (high*(1+vert)) else na;
z2d.SetPaintingStrategy(PaintingStrategy.ARROW_down);
z2d.SetDefaultColor(Color.red);
z2d.setlineweight(2);
z2d.hidebubble();
alert(xup, "crossed up" ,alert.BAR, sound.DING);
alert(xdwn, "crossed down" ,alert.BAR, sound.bell);
#-------------------------------------------
input test1 = no;
addchartbubble(test1, low*0.996,
#start2_min + "\n" +
#start2_hr + "\n" +
(secondsfromTime(start3)/60) + "\n" +
start3_min + "\n" +
t1 + "\n" +
t2 + "\n" +
t3 + "\n" +
(start3_min / aggmin)
, color.yellow, no);
#, (if x > 0 then color.yellow else color.gray), no);
# used this to get actual symbol for /es
input test2 = no;
addlabel(test2, tminoff );
addlabel(test2, getsymbol());
#
#