Levels Tokyo London New York Markets For ThinkOrSwim

SimpleScript

New member
The idea is to drawing the box around the overnight session, and another box to highlight the Europe or London session, to allow easy visual identification/exchange attribution for any identified support/resistance areas. Want this to work on any Intraday aggregation.

did a bunch of poking around tonite, and what Im thinking might work is to

1) input the start and stop times for the sessions (these below are just examples)

input EUOpen = 0100;
input RTHOpen = 0900;
input RTHClose = 1600;
input AsiaOpen = 1800;

2) use conditional logic to then allow addcloud to paint the boxes to the high and lo of those periods

am I on the right track here?
is there a better way to get RTH/ETH/exchange market hours?
do I need to use secondstilltime? to set the desired range?
what's the best way to capture the max hi and low for that specified time period? use High or HighestAll functions?
TIA
 
Solution
I would like to get someone's input in making TOS upper indicator for ES futures that marks:
1. Previous week high and low (shown as WL, WH)
2. London Range 2am to 5am (for 24 hr only; EST; shown as LRH, LRL)
3. Tokyo Range 8pm to midnight (for 24 hr only; EST; shown as TRH, TRL)
4. New york morning seeion 7am to 10am (for 24 hr only; EST; shown as NYH, NYL)
5. Prior 4 weeks opening gap - friday close and monday open (shown as WOG1, WOG2, WOG3, WOG4)
5. New day opening gap - price difference between 5pm and 6pm (for 24 hr only; EST; shown as DOGH, DOGL)

Thanks

this can be a starting point.
it is set up to pick 1 of 3 preset markets, US, UK, HK . a period of time within a day, that can span over midnight...
@mashume today, I see that London Open/Long Active High are showing incorrect values as shown in the below screen shot. It is showing $3886.7 as London Active High...but current session started from 3 AM EST and the high should have been $3848.. Also, may I know what the variables hrange and lrange represent here?

workspace link: http://tos.mx/oUxTLrV
Honestly, I have no idea. Could it be that it's picking up the high from the previous session somewhere... I don't really have a lot of time to debug at the moment. If I have some, I'll try to look into it but otherwise, at least the time boundary seems to be working and you can kinda eye-ball and know the range is off. Not ideal, but that's life.

-mashume
 
Honestly, I have no idea. Could it be that it's picking up the high from the previous session somewhere... I don't really have a lot of time to debug at the moment. If I have some, I'll try to look into it but otherwise, at least the time boundary seems to be working and you can kinda eye-ball and know the range is off. Not ideal, but that's life.

-mashume
yes..its looking the previous session...something to do with the time values.

sorry @NickC i forgot to post my code.

this draws lines and clouds, to identify possible reversal time periods,

for a time period, enter start and stop times. draws a cloud, (shaded region)
if stop = 0 then it draws just a line.

Ruby:
# 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);

#

LA9CXjf.jpg
@halcyonguy : I have added few more times that indicate UK Start time, EU Start time, Tokyo Start time and NY pre-market times. The vertical lines do not appear for pre-market/post market hours. May I know what is wrong here? Can you help, these reversals have improved my trading a lot better.


workspace link:http://tos.mx/msFxFdB

@halcyonguy : I have added few more times that indicate UK Start time, EU Start time, Tokyo Start time and NY pre-market times. The vertical lines do not appear for pre-market/post market hours. May I know what is wrong here? Can you help, these reversals have improved my trading a lot better.


workspace link:http://tos.mx/msFxFdB
@SleepyZ / @BenTen / @halcyonguy / @MerryDay : Anyone , please help on this. what am I doing wrong here. Code looks correct to me.
 
I would like to get someone's input in making TOS upper indicator for ES futures that marks:
1. Previous week high and low (shown as WL, WH)
2. London Range 2am to 5am (for 24 hr only; EST; shown as LRH, LRL)
3. Tokyo Range 8pm to midnight (for 24 hr only; EST; shown as TRH, TRL)
4. New york morning seeion 7am to 10am (for 24 hr only; EST; shown as NYH, NYL)
5. Prior 4 weeks opening gap - friday close and monday open (shown as WOG1, WOG2, WOG3, WOG4)
5. New day opening gap - price difference between 5pm and 6pm (for 24 hr only; EST; shown as DOGH, DOGL)

Thanks
 
I would like to get someone's input in making TOS upper indicator for ES futures that marks:
1. Previous week high and low (shown as WL, WH)
2. London Range 2am to 5am (for 24 hr only; EST; shown as LRH, LRL)
3. Tokyo Range 8pm to midnight (for 24 hr only; EST; shown as TRH, TRL)
4. New york morning seeion 7am to 10am (for 24 hr only; EST; shown as NYH, NYL)
5. Prior 4 weeks opening gap - friday close and monday open (shown as WOG1, WOG2, WOG3, WOG4)
5. New day opening gap - price difference between 5pm and 6pm (for 24 hr only; EST; shown as DOGH, DOGL)

Thanks

this can be a starting point.
it is set up to pick 1 of 3 preset markets, US, UK, HK . a period of time within a day, that can span over midnight.

https://usethinkscript.com/threads/average-daily-range-indicator-for-thinkorswim.244/#post-66296
 
Solution
Hi, does anyone know how to have this Do the following:
Keep a shade for custom time period high and low for renko and range bars. So when you look to the left they are showing.

For example one shade for US one for Asian, but ability to change the times. Thank you

See if this is more of what you want. I had to set the afterend to 1500 for an 1hr chart setting, when it would normally be 1600 for your requested end. Also, there is an extended lines option, which will extend the high/low lines to the next day.
Hi @SleepyZ i really like this.
Is it possible to show a Box Chanel/shade. for custom time period high and low to work on renko and range bars.

For example one shade for US one for Asian, but ability to change custom times. When you look to the left it is showing for previous days and weeks? I hope I am explaining well.
 
Last edited:
Ive ben going at this
https://usethinkscript.com/threads/...-open-of-day-atr-lines-for-thinkorswim.13139/
and two other scripts, for a while with my copy and paste programming expertise, as this one is the most Visually pleasing, but can seem to make a dent. So here is me tapping the p2p button, can we add defined times so I can target specific time zones ie London, NY, Asia or the respected over lap times.
 
Last edited by a moderator:
Hi @SleepyZ i really like this.
Is it possible to show a Box Chanel/shade. for custom time period high and low to work on renko and range bars.

For example one shade for US one for Asian, but ability to change custom times. When you look to the left it is showing for previous days and weeks? I hope I am explaining well.

Hi @SleepyZ do you have a code for this that would work with Range Bars?


For example one shade for US one for Asian, but ability to change custom times. When you look to the left it is showing for previous days and weeks? I hope I am explaining well.
 
Last edited by a moderator:
Hi @SleepyZ i really like this.
Is it possible to show a Box Chanel/shade. for custom time period high and low to work on renko and range bars.

For example one shade for US one for Asian, but ability to change custom times. When you look to the left it is showing for previous days and weeks? I hope I am explaining well.

Hi @SleepyZ do you have a code for this that would work with Range Bars?


For example one shade for US one for Asian, but ability to change custom times. When you look to the left it is showing for previous days and weeks? I hope I am explaining well.

This will plot 2 different timeframes High/Low, with optionally colored clouds for each. More timeframes can be added using the logic of the 2 timeframes.

This seems to work on time, range and renko charts.

Screenshot 2023-09-11 120040.png
Code:
#HL_Multiple_Time_Ranges

script R {
    input afterbegin = 1800;
    input afterend   = 1500;
    def sec1    = SecondsFromTime(afterbegin);
    def sec2    = SecondsFromTime(afterend);
    def isTime1 = (sec1 >= 0 and sec1[1] <= 0) or (sec1 < sec1[1] and sec1 >= 0);
    def isTime2 = (sec2 > 0 and sec2[1] <= 0) or (sec2 < sec2[1] and sec2 > 0);
    def aftermarket = CompoundValue(1, if isTime1 then 1 else if isTime2 then 0 else aftermarket[1], 0);

    def bars   = 10000;

    input pricePerRowHeightMode = { AUTOMATIC, default TICKSIZE, CUSTOM};
    input customRowHeight = 1.0;
    input timePerProfile = {default BAR};
    input onExpansion = no;
    input profiles = 1000;

    def period;

    switch (timePerProfile) {
    case BAR:
        period = BarNumber() - 1;
}


    def count = CompoundValue(1, if aftermarket and period != period[1] then (count[1] + period - period[1]) % bars else count[1], 0);
    def cond = count < count[1] + period - period[1];
    def height;
    switch (pricePerRowHeightMode) {
    case AUTOMATIC:
        height = PricePerRow.AUTOMATIC;
    case TICKSIZE:
        height = PricePerRow.TICKSIZE;
    case CUSTOM:
        height = customRowHeight;
}

    profile vol = VolumeProfile("startNewProfile" = cond, "onExpansion" = no, "numberOfProfiles" = 1000, "pricePerRow" = height, "value area percent" = 0);
    def con = CompoundValue(1, onExpansion, no);

    def hProfile = if aftermarket and IsNaN(vol.GetHighest()) and con then hProfile[1] else vol.GetHighest();
    def lProfile = if aftermarket and IsNaN(vol.GetLowest()) and con then lProfile[1] else vol.GetLowest();
    def plotsDomain = IsNaN(close) == onExpansion;
    def ProfileHigh = if aftermarket and plotsDomain then hProfile else Double.NaN;
    def ProfileLow  = if aftermarket and plotsDomain then lProfile else Double.NaN;

    plot hrange = ProfileHigh;
    plot lrange = ProfileLow;
    hrange.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
    lrange.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
    hrange.SetDefaultColor(Color.GREEN);
    lrange.SetDefaultColor(Color.RED);
    hrange.SetLineWeight(2);
    lrange.SetLineWeight(2);

    input extendedlines = yes;
    def PHighext   = if IsNaN(Max(hrange, lrange)) then PHighext[1] else hrange;
    def PLowext    = if IsNaN(Max(hrange, lrange)) then PLowext[1]  else lrange;
    plot hrangeext = if extendedlines then PHighext else Double.NaN;
    plot lrangeext = if extendedlines then PLowext else Double.NaN;
    hrangeext.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
    lrangeext.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
    hrangeext.SetDefaultColor(Color.GREEN);
    lrangeext.SetDefaultColor(Color.RED);
    hrangeext.SetLineWeight(2);
    lrangeext.SetLineWeight(2);
}

input start1 = 0930;
input end1   = 1600;

plot hr1 = R(start1, end1);
plot lr1 = R(start1, end1).lrange;

input bubblemover = 0;
def b  = bubblemover;
def b1 = b + 1;


input showbubbles = yes;
AddChartBubble(showbubbles and (IsNaN(hr1[b1]) and hr1[b]) , hr1, AsText(hr1), Color.LIGHT_GREEN);
AddChartBubble(showbubbles and (IsNaN(lr1[b1]) and lr1[b]) , lr1, AsText(lr1), Color.LIGHT_RED, up = no);

DefineGlobalColor("HL1", Color.GREEN);
AddCloud(hr1, lr1, GlobalColor("HL1"), GlobalColor("HL1"));

################################
input start2 = 2100;
input end2   = 0900;

plot hr2 = R(start2, end2).hrange;
plot lr2 = R(start2, end2).lrange;

AddChartBubble(showbubbles and (IsNaN(hr2[b1]) and hr2[b]) , hr2, AsText(hr2), Color.LIGHT_GREEN);
AddChartBubble(showbubbles and (IsNaN(lr2[b1]) and lr2[b]) , lr2, AsText(lr2), Color.LIGHT_RED, up = no);

DefineGlobalColor("HL2", Color.CYAN);
AddCloud(hr2, lr2, GlobalColor("HL2"), GlobalColor("HL2"));
 
This will plot 2 different timeframes High/Low, with optionally colored clouds for each. More timeframes can be added using the logic of the 2 timeframes.

This seems to work on time, range and renko charts.
Hi SleepyZ, I am not able to see the chart bubbles. what time frame should I change it to? I chose daily, 1min, 5min time frames but I don't see the chart bubble?
 
Another take on the same thing, slightly slower to get to the forum:
Code:
# Opening hours and ranges of global markets
# for usethinkscript
# mashume
# 2021-01-07
declare upper;

input EUOpen = 8;
input EUClose = 16.5;

input LondonOpen = 8;
input LondonClose = 16.5;

def D = 86400;
def HalfHour = 1800;
def epoch = (getTime() / 1000);

def GMT = Floor((epoch % D) / HalfHour) / 2;
def GMT_plus9 = if GMT > 15 then GMT - 15 else if GMT < 15 then (GMT + 24) - 15 else 0;

input TokyoOpen = 9;
input TokyoClose = 15;

def last24 = highestall(getTime()) - (86400 * 1000);

def EU = if GMT > EUOpen and GMT <= EUClose and gettime() >= last24 then 1 else 0;

def London = if (GMT > LondonOpen and gmt <= LondonClose and gettime() >= last24) then 1 else 0;

def Tokyo = if (GMT_plus9 > TokyoOpen and GMT_plus9 <= TokyoClose) and gettime() >= last24 then 1 else 0;

def EUHighs = if EU == 1 then high else double.nan;
def EULows = if EU == 1 then low else double.nan;
def EUHighest = highestAll(EUHighs);
def EULowest = lowestAll(EULows);

def LondonHighs = if London == 1 then high else double.nan;
def LondonLows = if London == 1 then low else double.nan;
def LondonHighest = highestAll(LondonHighs);
def LondonLowest = lowestAll(LondonLows);

def TokyoHighs = if Tokyo == 1 then high else double.nan;
def TokyoLows = if Tokyo == 1 then low else double.nan;
def TokyoHighest = highestAll(TokyoHighs);
def TokyoLowest = lowestAll(TokyoLows);

#plot EUActiveHigh = if EU == 1 then EUHighest else double.nan;
#plot EUActiveLow = if EU == 1 then EULowest else double.nan;
#AddCloud(EUActiveLow, EUActiveHigh, Color.BLUE, color.BLUE);

plot LondonActiveHigh = if London == 1 then LondonHighest else double.nan;
plot LondonActiveLow = if London == 1 then LondonLowest else double.nan;
AddCloud(LondonActiveLow, LondonActiveHigh, Color.LIME, color.LIME);

plot TokyoActiveHigh = if Tokyo == 1 then TokyoHighest else double.nan;
plot TokyoActiveLow = if Tokyo == 1 then TokyoLowest else double.nan;
AddCloud(TokyoActiveLow, TokyoActiveHigh, Color.Yellow, color.Yellow);

This one uses GMT for london, and sets a GMT+9 for tokyo and uses local times with hours in HH.5 format, where 16.5 is 4:30 pm.

-mashume
i changed nothing- pasted it into create study and get no result on chart. any ideas?
 
i changed nothing- pasted it into create study and get no result on chart. any ideas?
Could be several things

1. Something in the ThinkScript internals has changed since I wrote it and it will never work again. Possible, but not likely.
2. You have a chart setting that is not showing something. could be not having extended hours on, could bel you're looking at a ticker that does not have trades during the times it would otherwise display. Try looking at something like /ES and make sure extended hours is on and you are on an intraday (< 1 d, and preferably like 10m) timeframe.

-mashume
 
Hello,

I was trying to search through the threads here but was getting back too many results when trying to see how to correctly code this.

I was hoping someone could please help with the Thinkscript on how to plot a price line for the candle close of the London Stock Exchange (11:30am EST).

Any help is much appreciated! I was trying to pick through some existing price line code I have for other indicators, but couldn't figure out how to code it just for a specific candle close versus a time range.


Below is the code I was trying to tweak, which posts a price level for NYSE opening (9:30am EST).


Code:
input showOnlyLastPeriod = yes;
def label = yes;

def isOpen = GetTime() >= RegularTradingStart(GetYYYYMMDD()) and GetTime() <= RegularTradingEnd(GetYYYYMMDD());

def firstBarOpen = if isOpen and !isOpen[1] then open else if !isOpen then Double.NaN else firstBarOpen[1];

plot OpeningPrice;
OpeningPrice.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
OpeningPrice.SetDefaultColor(Color.BLUE);
OpeningPrice.SetLineWeight(2);

def shouldHidePlot = showOnlyLastPeriod and !IsNaN(close(period = AggregationPeriod.DAY)[-1]);

if shouldHidePlot {
    OpeningPrice = Double.NaN;
} else {
    OpeningPrice = firstBarOpen;
}

##AddLabel(label, "OP: " + AsDollars(OpeningPrice), Color.CYAN);
 
Hello,

I was trying to search through the threads here but was getting back too many results when trying to see how to correctly code this.

I was hoping someone could please help with the Thinkscript on how to plot a price line for the candle close of the London Stock Exchange (11:30am EST).

Any help is much appreciated! I was trying to pick through some existing price line code I have for other indicators, but couldn't figure out how to code it just for a specific candle close versus a time range.


Below is the code I was trying to tweak, which posts a price level for NYSE opening (9:30am EST).


Code:
input showOnlyLastPeriod = yes;
def label = yes;

def isOpen = GetTime() >= RegularTradingStart(GetYYYYMMDD()) and GetTime() <= RegularTradingEnd(GetYYYYMMDD());

def firstBarOpen = if isOpen and !isOpen[1] then open else if !isOpen then Double.NaN else firstBarOpen[1];

plot OpeningPrice;
OpeningPrice.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
OpeningPrice.SetDefaultColor(Color.BLUE);
OpeningPrice.SetLineWeight(2);

def shouldHidePlot = showOnlyLastPeriod and !IsNaN(close(period = AggregationPeriod.DAY)[-1]);

if shouldHidePlot {
    OpeningPrice = Double.NaN;
} else {
    OpeningPrice = firstBarOpen;
}

##AddLabel(label, "OP: " + AsDollars(OpeningPrice), Color.CYAN);

Here are some threads to get you started:
usethinkscript.com/threads/levels-tokyo-london-new-york-markets-for-thinkorswim.14520/
https://usethinkscript.com/threads/ny-london-asian-markets-ict-time-labels-for-thinkorswim.15632/
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
360 Online
Create Post

Similar threads

Similar threads

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