Draw a box around the overnight session on Futures Intraday charts

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
 

SimpleScript

New member
ok I have the code written to draw the box between the times being input, and set 2 test variables to plot the horizontals in the time period of interest. it appears to work.

now I just have to figure out how to capture the highest high and the lowest low for the desired period as set.

do I need to setup a loop of some kind, or is there a function like HighestAll that will return the value based on the AlertPeriod being True without the need for a loop?

here's the code:

Code:
# plot Data = close;
# ETH highlight
# dec DFKTMA == "SimpleScript";
# by DFK & Associates.  Copyright 2020. This code is distributed freely without restriction.  Use in any way absolves author of any and all liability.

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

def hhtest = 2750;
def lltest = 2500;
input HideBoxLines = Yes;
input HideLabels = Yes;

def StartAlertPeriod = SecondsFromTime(RTHClose);
def EndAlertPeriod = SecondsTillTime(RTHOpen);

def AlertPeriod = if StartAlertPeriod >= 0 or EndAlertPeriod >= 0 then 1 else 0;

#def HH = HighestAll(if alertPeriod = 1);
#def LL = LowestAll;

plot BoxHH = HighestAll (if alertPeriod then hhtest else Double.NaN);
BoxHH.SetDefaultColor(Color.GRAY);
BoxHH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BoxHH.SetHiding(HideBoxLines);

plot BoxLL = LowestAll (if alertPeriod then lltest else Double.NaN);
BoxLL.SetDefaultColor(Color.GRAY);
BoxLL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BoxLL.SetHiding(HideBoxLines);

AddCloud(if alertPeriod then BoxHH else Double.NaN, if alertPeriod then BoxLL else Double.NaN, Color.GRAY, Color.GRAY);
 

Shaishen

New member
TOS has a built in Cumulative ON Volume study - you can color the bars for Asia & EU to your liking - RTH IB and remainder of the RTH can also be colored - gives you a nice visual.
Bottom pane shows ONvol bars and average ON vol.
It is a well thought out indicator imo.
.
 

SimpleScript

New member
@Shaishen yes that is interesting ty for that. at this point, Im in it far enough to where I want to understand how to build the syntax to reach the goal of grabbing the hi and low in the time period of interest, and plotting a box around that. thinkscript is challenging due to how in some ways it is automagically recursive, and in others it is linear...
 

SimpleScript

New member
here's my latest trainwreck of an effort to get the hi and low in the as-input time period. it gets the box drawn at the correct start and stop time, but the hi's and low's aren't getting identified properly. and it seems to be a very intensive study. perhaps I need to limit how far back it can go?

I need to step away from it, let my mind clear... if anyone has any suggestions on getting the hi & low for the input time period, that would be hugely appreciated!

Code:
# plot Data = close;
# ETH highlight
# dec DFKTMA == "SimpleScript";
# by DFK & Associates.  Copyright 2020. This code is distributed freely without restriction.  Use in any way absolves author of any and all liability.

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

#def hhtest = 2750;
#def lltest = 2500;
input HideBoxLines = Yes;
input HideLabels = No;

def StartAlertPeriod = SecondsFromTime(RTHClose);
def EndAlertPeriod = SecondsTillTime(RTHOpen);

def AlertPeriod = if StartAlertPeriod >= 0 or EndAlertPeriod >= 0 then 1 else 0;

def period_type = AggregationPeriod.day;
#def period_type = getAggregationPeriod();

def begin = close(period = period_type)[1];
def end = close(period = period_type);

def LL = low (period = period_type[1]);
def HH = high (period = period_type[1]);
#def HH = HighestAll(period_type);
#def LL = LowestAll(period_type);

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

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

AddCloud(if AlertPeriod then BoxHH else Double.NaN, if AlertPeriod then BoxLL else Double.NaN, Color.GRAY, Color.GRAY);
 

Troy

New member
Hello all, yes I did do a search and found only 1 thread on this subject with no real follow-up. I am specifically looking for an indicator or if someone can code one that draws a color coded box from high to low, wick to wick from each desired time session. Example on my MT4 platform I use an isessions indicator, this indicator draws a rectangular box from high to low during Asia, 8-11 pm, then London 2-5am, then the US session 8-11am. 3 seperate boxes that I can adjust the time and color. I have searched all over the internet and the closest thing I've seen is some kind of breakout range which is not what I am looking for. Can someone please steer me in the right direction. I trade forex mostly, that why I need something that can draw individual boxes for times. I have inserted an image so you can see exactly what I am looking for. Thank you.

Uqb8Ern.png
 
Last edited:

Troy

New member
Hopefully someone sees this and would be willing to help me out here, even willing to pay money but I see that there seems to be not a lot of interest if anyone asks anything related to forex. Just looking for an indicators that draws a box from high to low, wick to wick from the times I set forth and colors being able to be changed. Example 8-11 pm blue box high to low wick to wick, 2 to 5 am yellow box high to low wick to wick 8 to 11am green box high to low wick to wick, or whatever color we desire.
 

TCB

Member
Hi, is it possible to create a script to draw a rectangular box or shaded area at user specific times and levels. For example you input the times to draw the rectangular box on the chart at start time 9:30 end time 11:30, and then also give it the price level to draw it at with a input to the value of height of the box ex. .50, .75, 1.00 or whatever price increment you input. I would post an image but when I use imgur it will not accept it. Thank you
 
Last edited:

mashume

Well-known member
VIP
Hopefully someone sees this and would be willing to help me out here, even willing to pay money but I see that there seems to be not a lot of interest if anyone asks anything related to forex. Just looking for an indicators that draws a box from high to low, wick to wick from the times I set forth and colors being able to be changed. Example 8-11 pm blue box high to low wick to wick, 2 to 5 am yellow box high to low wick to wick 8 to 11am green box high to low wick to wick, or whatever color we desire.
This is interesting. I may try to whip up something a little later on... :) I like the challenge of this one, and I've started getting into futures recently.
 

TCB

Member
I have tried to modify this script to draw two rectangular boxes with specific time entered and price levels. I can't get it to accept decimal points ex: 93.50, it rounds it to 93. Also, I can't seem to get it to go to the specific times that I enter. Any suggestions would be greatly welcomed. Here is the script below. Thanks
Code:
input ShowTodayOnly = yes;
input alertPeriodStart = 930;
input alertPeriodEnd = 1130;

input PutTopBox = 0;
input PutBottomBox = 0;
Input CallTopBox = 0;
Input CallBottomBox = 0;

input HideBoxLines = Yes;
input HideLabels = Yes;

def StartAlertPeriod = SecondsFromTime(alertPeriodStart);
def EndAlertPeriod = SecondsTillTime(alertPeriodEnd);

def AlertPeriod = if StartAlertPeriod >= 0 or EndAlertPeriod >= 0 then 1 else 0;

#def HH = HighestAll(if alertPeriod = 1);
#def LL = LowestAll;

plot PutTBox = HighestAll (if alertPeriodstart then PutTopBox else Double.NaN);
PutTBox.SetDefaultColor(Color.GRAY);
PutTBox.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PutTBox.SetHiding(HideBoxLines);

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

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

plot CallBBox = LowestAll (if alertPeriodstart then CallBottomBox else Double.NaN);
CallBBox.SetDefaultColor(Color.GRAY);
CallBBox.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
CallBBox.SetHiding(HideBoxLines);
 
Last edited:

rad14733

Well-known member
VIP
@TCB Edit your inputs to have a decimal point and then you should be able to enter decimals... 💡

Ruby:
input PutTopBox = 0.0;
input PutBottomBox = 0.0;
input CallTopBox = 0.0;
input CallBottomBox = 0.0;
 

TCB

Member
I finally figured it out, this will draw 2 zone areas, you can select the times and the range for the area. Thanks

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

mashume

Well-known member
VIP
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
 
Last edited:

TCB

Member
Hi, the script I posted above works and puts it across multiple days when scrolling back. How can I modify it to just show the current day only?
 

TCB

Member
I have a code that I want to be able to display it on today only. As it works now, it displays it on all the previous days. What else do I need to add to it to accomplish this. Thanks

Code:
input ShowTodayOnly={"No", default "Yes"};
input alertPeriodStart = 930;
input alertPeriodEnd = 1130;
def StartAlertPeriod = SecondsTillTime(alertPeriodStart);
def EndAlertPeriod = SecondsTillTime(alertPeriodEnd);
def AlertPeriod = If (StartAlertPeriod <= 0 and EndAlertPeriod > 0, close, 0);
 

TCB

Member
Here is the entire code. I want it to display only for today and not previous days
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);
 

Similar threads

Top