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...
im not sure what time it is in london, but it appears to be plotting only on 1 day, you can comment ### out the plot you dont need.
I'm in the US and this is the code I"m referring to
Code:
#Draw 2 areas with user defined range for the areas
#Modified and created on 1-7-21 by TCB
input alertPeriodStart = 930;
input alertPeriodEnd = 1030;
def StartAlertPeriod = SecondstillTime(alertPeriodStart);
def EndAlertPeriod = SecondsTillTime(alertPeriodEnd);
def AlertPeriod = if (StartAlertPeriod <= 0 and EndAlertPeriod >0, close, 0);

input PutLevelStart =0.0;
Input CallLevelStart =0.0;
Input Range = 0.0;

input HideBoxLines = Yes;
input HideLabels = Yes;

def PutTopBox = PutLevelStart + range;
def CallBottomBox = CallLevelStart - range;

plot TopArea = HighestAll (if AlertPeriod then PutTopbox else Double.NaN);
TopArea.SetDefaultColor(Color.GRAY);
TopArea.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
TopArea.SetHiding(HideBoxLines);

plot BottomArea = HighestAll (if AlertPeriod then CallBottombox else Double.NaN);
BottomArea.SetDefaultColor(Color.GRAY);
BottomArea.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BottomArea.SetHiding(HideBoxLines);

plot PutBBox = LowestAll (if AlertPeriod then PutLevelStart else Double.NaN);
PutBBox.SetDefaultColor(Color.GRAY);
PutBBox.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PutBBox.SetHiding(HideBoxLines);

plot CallTBox = HighestAll (if AlertPeriod then CallLevelStart else Double.NaN);
CallTBox.SetDefaultColor(Color.GRAY);
CallTBox.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
CallTBox.SetHiding(HideBoxLines);

AddCloud(if AlertPeriod then TopArea else Double.NaN, if AlertPeriod then PutBBox else Double.NaN, Color.GRAY, Color.GRAY);
AddCloud(if AlertPeriod then BottomArea else Double.NaN, if AlertPeriod then CallTBox else Double.NaN, Color.GRAY, Color.GRAY);
 

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

The whole "get only the current day range and draw a box" is what the
Code:
def last24 = highestall(getTime()) - (86400 * 1000);
variable is for in the one I wrote. That was the most difficult part, getting just the data from the last day.

-mashume
 
@TCB
I'll try to walk you through the function I put together to retrieve only the last day. Here's a shorter version with only London.
Code:
# Opening hours and ranges of global markets
# for usethinkscript
# mashume
# 2021-01-07
declare upper;

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 last24 = highestall(getTime()) - (86400 * 1000);

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

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);

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);

Let's see...

First, we define some times, LondonOpen and LondonClose, then some constants for the number of seconds in a given period of time.

Eopch is defined with getTime() and that returns miliseconds so we divide by 1000 to get seconds.

GMT is calculated and the HalfHour second count is used so we can get 16.5 as a value (since we need half hours but no finer for this purpose).

The Last24 variable gives us the time (sort of -- it gives us the epoch time 24 hours ago) in miliiseconds, but we'll compare that to the current getTime value in a moment.

When we decide whether London is open or not, we look to see whether GMT is between our open and closed values, but ALSO whether the time period we're looking at is in the last24 hours by using the "AND GETTIME() >= LAST24" line. I broke out the conditions in the London def so it might be clearer.

The rest is decided from whether London == 1 or not. If it is, we read highs and lows into a data series and if not we put in double.nan(s). We then get the higestall and lowestall in the series, since they contain only data that was between open and close and within the last 24 hours.

Seems simple now that I've written it all, but sorting it out wasn't that straight forward and involved a great deal of investigations of how to determine whether data was within the last 24 hours.

Hope the code explanation helps. I haven't read through yours thoroughly enough to know what it's doing or not doing, but this was my solution to the request.

Happy Trading,
mashume
 
Last edited:
@mashume

Thank you for posting this code ...could you please explain as to why when I add the code and hit apply....the boxes only appear on the chart for a second and then disappear?

Thanks again
 
@mashume

Thank you for posting this code ...could you please explain as to why when I add the code and hit apply....the boxes only appear on the chart for a second and then disappear?

Thanks again
Nope. No Idea. Sorry. What time frame are you trying to apply it on? I did most of the development looking at 15 min charts of /ES.

-mashume
 
@mashume

I also using the code on the 15 min chart as well with extending trading hours on. Are you able to show a screen shot what it suppose to look like since I’m having a hard time getting the boxes to appear.

Greatly appreciate it.
 
So it seems to have some issues around working on weekends, as the last24 doesn't capture anything. I'll test it over the week, and see what it starts grabbing later today (when global markets have opened). but for now, a quick fix is this replacement based on the GetDayofWeek() function ... which the docs say may not give the right day for futures. So take this with the usual disclaimer and grain of salt:

Code:
def dayOfWeek = GetDayOfWeek(GETyyyyMmDd());
def day_mult = if dayOfWeek == 5 then 3 else if dayOfWeek == 4 then 2 else 1;
def last24 = highestall(getTime()) - (day_mult * 86400 * 1000);

On my display, it looks like this:

AdxTSkE.png


The code for bubbles is like this:

Code:
AddChartBubble("time condition" = GMT == LondonOpen and London[-1] == 1, "price location" = LondonHighest, text = "London Open", color = Color.GREEN);

Happy Trading,
mashume
 
came across this, you may find it interesting with a possible fix:


Code:
#TS Title = NY_LondonTimeLines

#hint:On a /ES futures, 15 min agg, 24 hour chart, plots time-related lines from the NY open and the London open. Chart settings need to be set to extended hours and your local timezone. 

 

input NYOpenTime = 0930;#hint NYOpenTime:NY market time open

input DurationHours = 14.5;#hint DurationHours:Duration NY open to end of 24 hr day

input LonOpenTime =0300;#hint LonOpenTime: Open of London market in NY time

input LonDurationHrs = 21.0;#hint LonDurationHrs:Duration London open to end of 24 hr day

 

########### line2 from NY open ###############

def durationSec2 = DurationHours * 60 * 60;

def secondsPassed2 = secondsFromTime(NYOpenTime);

def condition2 = if (secondsPassed2 >= 0 and secondsPassed2 <= durationSec2, 1, 0);

 

rec OpenAtLine2 = compoundValue(1, if condition2 then OpenAtLine2[1]  else close   , close[1]);

plot line2 = if (condition2, OpenAtLine2, double.nan);

Line2.SetDefaultColor(Color.green);

Line2.SetPaintingStrategy(PaintingStrategy.dashes);

########### line1 from London open ###############

def durationSec1 = LonDurationHrs * 60 * 60;

def secondsPassed1 = secondsFromTime(LonOpenTime);

def condition1 = if (secondsPassed1 >= 0 and secondsPassed1 <= durationSec1, 1, 0);

 

rec OpenAtLine1 = compoundValue(1, if condition1 then OpenAtLine1[1]  else close   , close[1]);

plot line1 = if (condition1, OpenAtLine1, double.nan);

Line1.SetDefaultColor(Color.red);

Line1.SetPaintingStrategy(PaintingStrategy.dashes);

 

AddLabel(yes,"US market",color.green);

AddLabel(yes,"London market",color.red);

 

#################### EOC ###########################

***************** 930 to 415 line ****************************

input OpenTime = 0930;#hint OpenTime:The  market time open

input DurationHours = 6.75;#hint DurationHours:Duration = open to end (can use 24 hr day also)

 

 

########### line2 from market open ###############

def durationSec2 = DurationHours * 60 * 60;

def secondsPassed2 = secondsFromTime(OpenTime);

def condition2 = if (secondsPassed2 >= 1 and secondsPassed2 <= durationSec2, 1, 0);

 

rec OpenAtLine2 = compoundValue(1, if condition2 then OpenAtLine2[1]  else close , close[0]);

plot line2 = if (condition2, OpenAtLine2, double.nan);

Line2.SetDefaultColor(Color.green);

Line2.SetPaintingStrategy(PaintingStrategy.dashes);

###########  EOC ##############
 
So it seems to have some issues around working on weekends, as the last24 doesn't capture anything. I'll test it over the week, and see what it starts grabbing later today (when global markets have opened). but for now, a quick fix is this replacement based on the GetDayofWeek() function ... which the docs say may not give the right day for futures. So take this with the usual disclaimer and grain of salt:

Code:
def dayOfWeek = GetDayOfWeek(GETyyyyMmDd());
def day_mult = if dayOfWeek == 5 then 3 else if dayOfWeek == 4 then 2 else 1;
def last24 = highestall(getTime()) - (day_mult * 86400 * 1000);

On my display, it looks like this:

AdxTSkE.png


The code for bubbles is like this:

Code:
AddChartBubble("time condition" = GMT == LondonOpen and London[-1] == 1, "price location" = LondonHighest, text = "London Open", color = Color.GREEN);

Happy Trading,
mashume
@mashume, Thank you for all that you do........Could you please post a link to this chart. I have been looking for a Tokyo breakout indicator. Here is a link to the strategy. watch
 
Last edited:
I'll see what I can find... what part of it are you looking for in particular?

-mashume
@mashume, I am looking for the link for the screenshot on post #30....It shows both the Tokyo session and the London session. I tried losing the script manualy but did not see anything....It may be because of the weekend issue ..I believe you mentioned.
 
@mashume, I am looking for the link for the screenshot on post #30....It shows both the Tokyo session and the London session. I tried losing the script manualy but did not see anything....It may be because of the weekend issue ..I believe you mentioned.
I will try to look into it today or tomorrow for you.

-mashume
 
@Chuck
Try this and let me know if it's not working correctly...
Code:
declare upper;

def Y = 31556926;
def M = 2629743;
def D = 86400;
def H = 3600;
def HalfHour = 1800;
def epoch = (getTime() / 1000);
def YMD = (epoch % Y) - (epoch / Y);
def month = (Floor(YMD / M) + 1);
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 dayOfWeek = GetDayOfWeek(GETyyyyMmDd());
def day_mult = if dayOfWeek == 5 then 3 else if dayOfWeek == 4 then 2 else 1;
def last24 = highestall(getTime()) - (1 * 86400 * 1000); # replaced day_mult with 1

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

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 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);
AddChartBubble("time condition" = GMT_plus9 == TokyoOpen and Tokyo[-1] == 1, "price location" = TokyoHighest, text = "Tokyo Open", color.cyan);

-mashume
 
@Chuck
Try this and let me know if it's not working correctly...
Code:
declare upper;

def Y = 31556926;
def M = 2629743;
def D = 86400;
def H = 3600;
def HalfHour = 1800;
def epoch = (getTime() / 1000);
def YMD = (epoch % Y) - (epoch / Y);
def month = (Floor(YMD / M) + 1);
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 dayOfWeek = GetDayOfWeek(GETyyyyMmDd());
def day_mult = if dayOfWeek == 5 then 3 else if dayOfWeek == 4 then 2 else 1;
def last24 = highestall(getTime()) - (1 * 86400 * 1000); # replaced day_mult with 1

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

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 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);
AddChartBubble("time condition" = GMT_plus9 == TokyoOpen and Tokyo[-1] == 1, "price location" = TokyoHighest, text = "Tokyo Open", color.cyan);

-mashume
@mashume,
Perhaps it is me, or my chart settings...But I don't see anything. I will wait till Monday and check it out then. Thank you for getting this to me. I appreciate it very much. You are awesome!!!!
 
This is my screen, /MNQ 15 minutes right now (Saturday night / Sunday morning):
wt01kak.png

I'd check your settings and make sure you're seeing the extended hours for whatever timeframe you're after. :)

-mashume
 
This is my screen, /MNQ 15 minutes right now (Saturday night / Sunday morning):
wt01kak.png

I'd check your settings and make sure you're seeing the extended hours for whatever timeframe you're after. :)

-mashume
Thanks for the reply. I have changed every setting I know how too. Is it possible to share your grid?
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
384 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