# reversals_06a_study
# 2019-01-19
# halcyonguy
# draw vertical lines, at possible price reversals
# shade areas near timeProfile periods
# https://www.tradermentality.com/2016/02/intraday-reversal-times.html
# --------------------------------------------------------------
# reversal times EST
# ranges est
# 9:30-9:35 --- major
# 9:50-10:10 --- major
# 10:25-10:35
# times est
# 11:15
# 12:00
# 12:45
# 1:30 --- major
# 2:15 --- major
# 3:00 --- major
# 3:30
# 4:01 --- major
# make sure all ranges have a start and stop time
# if stop time =0 then stop = start +1
# -- reference links ------------------------------------------------------------
# http://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Date---Time/SecondsFromTime.html
# http://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Look---Feel/AddVerticalLine.html
# http://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Look---Feel/GetColor.html
# -----------------------------------------------------------
#color = getcolor(colnum)
# 0=magenta, 1=cyan, 2=pink, 3=gray, 4=orange
# 5=red, 6=green, 7=dark gray, 8=yellow, 9=white
# time input data
# HHMM EST 1200 = noon est 1020 = 10:20 est
# a value used if data is not able to be plotted
def na = Double.NaN;
input display_vertical_lines = yes;
input display_shading = yes;
input line_color_0to9 = 1;
# 1=cyan
input shade_color_0to9 = 8;
# 8=yellow
# make shorter var names
def disvl = display_vertical_lines;
def diss = display_shading;
def linecol = line_color_0to9;
def shcol = shade_color_0to9;
input shade_width_minutes = 4;
input shade_ht = 4;
# shade_ht is a % of price. 3 become 0.003 , or 0.3% , times the price, for a vertical offset, added to high or subtracted from low
# convert shade width min to sec
def sh_wsec = shade_width_minutes * 60;
# devide shade ht/1000
def sh_ht = shade_ht / 1000;
input enter_times_in_24hour_est_hhmm = 0;
# ranges of time est
input rng01_start = 0930;
input rng01_stop = 0935;
input rng02_start = 0950;
input rng02_stop = 1010;
input rng03_start = 1025;
input rng03_stop = 1035;
input rng04_start = 1115;
input rng04_stop = 0;
input rng05_start = 1200;
input rng05_stop = 0;
input rng06_start = 1245;
input rng06_stop = 0;
input rng07_start = 1330;
input rng07_stop = 0;
input rng08_start = 1415;
input rng08_stop = 0;
input rng09_start = 1500;
input rng09_stop = 0;
input rng10_start = 1530;
input rng10_stop = 0;
input rng11_start = 1601;
input rng11_stop = 0;
input rng12_start = 0;
input rng12_stop = 0;
input rng13_start = 0;
input rng13_stop = 0;
input rng14_start = 0;
input rng14_stop = 0;
input rng15_start = 0;
input rng15_stop = 0;
# convert start times from 24 to 12 hr , for displaying as text on start vertical lines
def r01starttxt = if rng01_start >= 1300 then rng01_start - 1200 else rng01_start;
def r02starttxt = if rng02_start >= 1300 then rng02_start - 1200 else rng02_start;
def r03starttxt = if rng03_start >= 1300 then rng03_start - 1200 else rng03_start;
def r04starttxt = if rng04_start >= 1300 then rng04_start - 1200 else rng04_start;
def r05starttxt = if rng05_start >= 1300 then rng05_start - 1200 else rng05_start;
def r06starttxt = if rng06_start >= 1300 then rng06_start - 1200 else rng06_start;
def r07starttxt = if rng07_start >= 1300 then rng07_start - 1200 else rng07_start;
def r08starttxt = if rng08_start >= 1300 then rng08_start - 1200 else rng08_start;
def r09starttxt = if rng09_start >= 1300 then rng09_start - 1200 else rng09_start;
def r10starttxt = if rng10_start >= 1300 then rng10_start - 1200 else rng10_start;
def r11starttxt = if rng11_start >= 1300 then rng11_start - 1200 else rng11_start;
def r12starttxt = if rng12_start >= 1300 then rng12_start - 1200 else rng12_start;
def r13starttxt = if rng13_start >= 1300 then rng13_start - 1200 else rng13_start;
def r14starttxt = if rng14_start >= 1300 then rng14_start - 1200 else rng14_start;
def r15starttxt = if rng15_start >= 1300 then rng15_start - 1200 else rng15_start;
# verify stop numbers HHMM
def r01stop2 = if rng01_stop == 0 then rng01_start else rng01_stop;
def r02stop2 = if rng02_stop == 0 then rng02_start else rng02_stop;
def r03stop2 = if rng03_stop == 0 then rng03_start else rng03_stop;
def r04stop2 = if rng04_stop == 0 then rng04_start else rng04_stop;
def r05stop2 = if rng05_stop == 0 then rng05_start else rng05_stop;
def r06stop2 = if rng06_stop == 0 then rng06_start else rng06_stop;
def r07stop2 = if rng07_stop == 0 then rng07_start else rng07_stop;
def r08stop2 = if rng08_stop == 0 then rng08_start else rng08_stop;
def r09stop2 = if rng09_stop == 0 then rng09_start else rng09_stop;
def r10stop2 = if rng10_stop == 0 then rng10_start else rng10_stop;
def r11stop2 = if rng11_stop == 0 then rng11_start else rng11_stop;
def r12stop2 = if rng12_stop == 0 then rng12_start else rng12_stop;
def r13stop2 = if rng13_stop == 0 then rng13_start else rng13_stop;
def r14stop2 = if rng14_stop == 0 then rng14_start else rng14_stop;
def r15stop2 = if rng15_stop == 0 then rng15_start else rng15_stop;
# true/false , r01sh , display shading if within (time period +- shade width seconds )
# add shading around time of reversal
def r01sh = if ( diss and ( secondstillTime(rng01_start) <= sh_wsec) and ( secondsfromTime(r01stop2) <= sh_wsec )) then 1 else 0;
def r01hi = if r01sh then high + (close * sh_ht) else na;
def r01lo = if r01sh then low - (close * sh_ht) else na;
addcloud(r01hi,r01lo,getcolor(shcol),getcolor(shcol));
def r02sh = if ( diss and ( secondstillTime(rng02_start) <= sh_wsec) and ( secondsfromTime(r02stop2) <= sh_wsec )) then 1 else 0;
def r02hi = if r02sh then high + (close * sh_ht) else na;
def r02lo = if r02sh then low - (close * sh_ht) else na;
addcloud(r02hi,r02lo,getcolor(shcol),getcolor(shcol));
def r03sh = if ( diss and ( secondstillTime(rng03_start) <= sh_wsec) and ( secondsfromTime(r03stop2) <= sh_wsec )) then 1 else 0;
def r03hi = if r03sh then high + (close * sh_ht) else na;
def r03lo = if r03sh then low - (close * sh_ht) else na;
addcloud(r03hi,r03lo,getcolor(shcol),getcolor(shcol));
def r04sh = if ( diss and ( secondstillTime(rng04_start) <= sh_wsec) and ( secondsfromTime(r04stop2) <= sh_wsec )) then 1 else 0;
def r04hi = if r04sh then high + (close * sh_ht) else na;
def r04lo = if r04sh then low - (close * sh_ht) else na;
addcloud(r04hi,r04lo,getcolor(shcol),getcolor(shcol));
def r05sh = if ( diss and ( secondstillTime(rng05_start) <= sh_wsec) and ( secondsfromTime(r05stop2) <= sh_wsec )) then 1 else 0;
def r05hi = if r05sh then high + (close * sh_ht) else na;
def r05lo = if r05sh then low - (close * sh_ht) else na;
addcloud(r05hi,r05lo,getcolor(shcol),getcolor(shcol));
def r06sh = if ( diss and ( secondstillTime(rng06_start) <= sh_wsec) and ( secondsfromTime(r06stop2) <= sh_wsec )) then 1 else 0;
def r06hi = if r06sh then high + (close * sh_ht) else na;
def r06lo = if r06sh then low - (close * sh_ht) else na;
addcloud(r06hi,r06lo,getcolor(shcol),getcolor(shcol));
def r07sh = if ( diss and ( secondstillTime(rng07_start) <= sh_wsec) and ( secondsfromTime(r07stop2) <= sh_wsec )) then 1 else 0;
def r07hi = if r07sh then high + (close * sh_ht) else na;
def r07lo = if r07sh then low - (close * sh_ht) else na;
addcloud(r07hi,r07lo,getcolor(shcol),getcolor(shcol));
def r08sh = if ( diss and ( secondstillTime(rng08_start) <= sh_wsec) and ( secondsfromTime(r08stop2) <= sh_wsec )) then 1 else 0;
def r08hi = if r08sh then high + (close * sh_ht) else na;
def r08lo = if r08sh then low - (close * sh_ht) else na;
addcloud(r08hi,r08lo,getcolor(shcol),getcolor(shcol));
def r09sh = if ( diss and ( secondstillTime(rng09_start) <= sh_wsec) and ( secondsfromTime(r09stop2) <= sh_wsec )) then 1 else 0;
def r09hi = if r09sh then high + (close * sh_ht) else na;
def r09lo = if r09sh then low - (close * sh_ht) else na;
addcloud(r09hi,r09lo,getcolor(shcol),getcolor(shcol));
# 10-15
def r10sh = if ( diss and ( secondstillTime(rng10_start) <= sh_wsec) and ( secondsfromTime(r10stop2) <= sh_wsec )) then 1 else 0;
def r10hi = if r10sh then high + (close * sh_ht) else na;
def r10lo = if r10sh then low - (close * sh_ht) else na;
addcloud(r10hi,r10lo,getcolor(shcol),getcolor(shcol));
def r11sh = if ( diss and ( secondstillTime(rng11_start) <= sh_wsec) and ( secondsfromTime(r11stop2) <= sh_wsec )) then 1 else 0;
def r11hi = if r11sh then high + (close * sh_ht) else na;
def r11lo = if r11sh then low - (close * sh_ht) else na;
addcloud(r11hi,r11lo,getcolor(shcol),getcolor(shcol));
def r12sh = if ( diss and ( secondstillTime(rng12_start) <= sh_wsec) and ( secondsfromTime(r12stop2) <= sh_wsec )) then 1 else 0;
def r12hi = if r12sh then high + (close * sh_ht) else na;
def r12lo = if r12sh then low - (close * sh_ht) else na;
addcloud(r12hi,r12lo,getcolor(shcol),getcolor(shcol));
def r13sh = if ( diss and ( secondstillTime(rng13_start) <= sh_wsec) and ( secondsfromTime(r13stop2) <= sh_wsec )) then 1 else 0;
def r13hi = if r13sh then high + (close * sh_ht) else na;
def r13lo = if r13sh then low - (close * sh_ht) else na;
addcloud(r13hi,r13lo,getcolor(shcol),getcolor(shcol));
def r14sh = if ( diss and ( secondstillTime(rng14_start) <= sh_wsec) and ( secondsfromTime(r14stop2) <= sh_wsec )) then 1 else 0;
def r14hi = if r14sh then high + (close * sh_ht) else na;
def r14lo = if r14sh then low - (close * sh_ht) else na;
addcloud(r14hi,r14lo,getcolor(shcol),getcolor(shcol));
def r15sh = if ( diss and ( secondstillTime(rng15_start) <= sh_wsec) and ( secondsfromTime(r15stop2) <= sh_wsec )) then 1 else 0;
def r15hi = if r15sh then high + (close * sh_ht) else na;
def r15lo = if r15sh then low - (close * sh_ht) else na;
addcloud(r15hi,r15lo,getcolor(shcol),getcolor(shcol));
# ======== vertical lines ===================================================
#def linecol = line_color_0to9;
# ex getcolor(linecol)
#def disvl = display_vertical_lines; true/false master control
# display a line at start time, with the time listed as EST
# display a line at stop time, if stop is not =0
# stroke = curve.___ firm , long_dash , medium_dash , short_dash , points
# ------ vertical line at start time , with start time ------------------------------------
# true/false enable, draw vertical lines start
def r01st = secondsFromTime(rng01_start)==0;
def r02st = secondsFromTime(rng02_start)==0;
def r03st = secondsFromTime(rng03_start)==0;
def r04st = secondsFromTime(rng04_start)==0;
def r05st = secondsFromTime(rng05_start)==0;
def r06st = secondsFromTime(rng06_start)==0;
def r07st = secondsFromTime(rng07_start)==0;
def r08st = secondsFromTime(rng08_start)==0;
def r09st = secondsFromTime(rng09_start)==0;
def r10st = secondsFromTime(rng10_start)==0;
def r11st = secondsFromTime(rng11_start)==0;
def r12st = secondsFromTime(rng12_start)==0;
def r13st = secondsFromTime(rng13_start)==0;
def r14st = secondsFromTime(rng14_start)==0;
def r15st = secondsFromTime(rng15_start)==0;
# draw vertical line at start time , with start time
AddVerticalLine(disvl and r01st, "TIME EST - " + r01starttxt, color = getcolor(linecol), stroke = Curve.short_dash);
AddVerticalLine(disvl and r02st, "TIME EST - " + r02starttxt, color = getcolor(linecol), stroke = Curve.short_dash);
AddVerticalLine(disvl and r03st, "TIME EST - " + r03starttxt, color = getcolor(linecol), stroke = Curve.short_dash);
AddVerticalLine(disvl and r04st, "TIME EST - " + r04starttxt, color = getcolor(linecol), stroke = Curve.short_dash);
AddVerticalLine(disvl and r05st, "TIME EST - " + r05starttxt, color = getcolor(linecol), stroke = Curve.short_dash);
AddVerticalLine(disvl and r06st, "TIME EST - " + r06starttxt, color = getcolor(linecol), stroke = Curve.short_dash);
AddVerticalLine(disvl and r07st, "TIME EST - " + r07starttxt, color = getcolor(linecol), stroke = Curve.short_dash);
AddVerticalLine(disvl and r08st, "TIME EST - " + r08starttxt, color = getcolor(linecol), stroke = Curve.short_dash);
AddVerticalLine(disvl and r09st, "TIME EST - " + r09starttxt, color = getcolor(linecol), stroke = Curve.short_dash);
AddVerticalLine(disvl and r10st, "TIME EST - " + r10starttxt, color = getcolor(linecol), stroke = Curve.short_dash);
AddVerticalLine(disvl and r11st, "TIME EST - " + r11starttxt, color = getcolor(linecol), stroke = Curve.short_dash);
AddVerticalLine(disvl and r12st, "TIME EST - " + r12starttxt, color = getcolor(linecol), stroke = Curve.short_dash);
AddVerticalLine(disvl and r13st, "TIME EST - " + r13starttxt, color = getcolor(linecol), stroke = Curve.short_dash);
AddVerticalLine(disvl and r14st, "TIME EST - " + r14starttxt, color = getcolor(linecol), stroke = Curve.short_dash);
AddVerticalLine(disvl and r15st, "TIME EST - " + r15starttxt, color = getcolor(linecol), stroke = Curve.short_dash);
# ------ vertical line at stop time ------------------------------------
# true/false enable , draw vertical line at stop time
def r01sp = if rng01_stop > 0 and secondsFromTime(rng01_stop)==0 then 1 else 0;
def r02sp = if rng02_stop > 0 and secondsFromTime(rng02_stop)==0 then 1 else 0;
def r03sp = if rng03_stop > 0 and secondsFromTime(rng03_stop)==0 then 1 else 0;
def r04sp = if rng04_stop > 0 and secondsFromTime(rng04_stop)==0 then 1 else 0;
def r05sp = if rng05_stop > 0 and secondsFromTime(rng05_stop)==0 then 1 else 0;
def r06sp = if rng06_stop > 0 and secondsFromTime(rng06_stop)==0 then 1 else 0;
def r07sp = if rng07_stop > 0 and secondsFromTime(rng07_stop)==0 then 1 else 0;
def r08sp = if rng08_stop > 0 and secondsFromTime(rng08_stop)==0 then 1 else 0;
def r09sp = if rng09_stop > 0 and secondsFromTime(rng09_stop)==0 then 1 else 0;
def r10sp = if rng10_stop > 0 and secondsFromTime(rng10_stop)==0 then 1 else 0;
def r11sp = if rng11_stop > 0 and secondsFromTime(rng11_stop)==0 then 1 else 0;
def r12sp = if rng12_stop > 0 and secondsFromTime(rng12_stop)==0 then 1 else 0;
def r13sp = if rng13_stop > 0 and secondsFromTime(rng13_stop)==0 then 1 else 0;
def r14sp = if rng14_stop > 0 and secondsFromTime(rng14_stop)==0 then 1 else 0;
def r15sp = if rng15_stop > 0 and secondsFromTime(rng15_stop)==0 then 1 else 0;
# draw vertical line at stop
AddVerticalLine(disvl and r01sp, "", color = getcolor(linecol), stroke = Curve.POINTS);
AddVerticalLine(disvl and r02sp, "", color = getcolor(linecol), stroke = Curve.POINTS);
AddVerticalLine(disvl and r03sp, "", color = getcolor(linecol), stroke = Curve.POINTS);
AddVerticalLine(disvl and r04sp, "", color = getcolor(linecol), stroke = Curve.POINTS);
AddVerticalLine(disvl and r05sp, "", color = getcolor(linecol), stroke = Curve.POINTS);
AddVerticalLine(disvl and r06sp, "", color = getcolor(linecol), stroke = Curve.POINTS);
AddVerticalLine(disvl and r07sp, "", color = getcolor(linecol), stroke = Curve.POINTS);
AddVerticalLine(disvl and r08sp, "", color = getcolor(linecol), stroke = Curve.POINTS);
AddVerticalLine(disvl and r09sp, "", color = getcolor(linecol), stroke = Curve.POINTS);
AddVerticalLine(disvl and r10sp, "", color = getcolor(linecol), stroke = Curve.POINTS);
AddVerticalLine(disvl and r11sp, "", color = getcolor(linecol), stroke = Curve.POINTS);
AddVerticalLine(disvl and r12sp, "", color = getcolor(linecol), stroke = Curve.POINTS);
AddVerticalLine(disvl and r13sp, "", color = getcolor(linecol), stroke = Curve.POINTS);
AddVerticalLine(disvl and r14sp, "", color = getcolor(linecol), stroke = Curve.POINTS);
AddVerticalLine(disvl and r15sp, "", color = getcolor(linecol), stroke = Curve.POINTS);
#