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...
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?
to enable values for only the current day, add the true/false variable istoday , to your formulas,
they don't have to be if then's. i just got in the habit of writing formulas that way.
Code:
def istoday = if GetLastDay() == GetDay() then 1 else 0;
def isweek = if GetLastweek() == Getweek() then 1 else 0;
def ismonth = if GetLastmonth() == Getmonth() then 1 else 0;
def isyear = if GetLastYear() == GetYear() then 1 else 0;
 
here is my version of a study, to specify a repeating time period, that i made a few months ago.
this doesn't use highestall(), as it can cause a script to become complex, and slow down TOS.

find the high and low, over some specified time period, every 24 hours
# hilolines_07a
http://tos.mx/ggTL45x
# 2020-07-17
# halcyonguy
# time periods work over midnight
# can choose wicks or body
# draw shading, bounded by start/stop times and highest/lowest levels
# enter start and end times, (24 hour EST), for a period < 24 hours
# can choose to show several parameters , labels, lines, shading
# pick /es for testing. trades most of the day

ulgOaLg.jpg


Code:
# hilolines_07

# abandon ver06
# start with a copy of ver05, not 05b. this works over midnight
#  add , wicks or body


# hilolines_06
#  removed too much in v05b. doesn't work over midnight
#   wicks or body


# hilolines_05
# 2020-07-17
# halcyonguy
# draw shading, bounded by start/stop times and highest/lowest levels
#  enter start and end times, (24 hour EST), for a period < 24 hours
#  can choose to show several parameters , labels, lines, shading
#   pick  /es  for testing.  trades most of day

declare hide_on_daily;

input candle_levels = {default "wick" , "body" };

input market = { default "U.S." , "EU" , "Asian" , "-"};

input start1_est = 0930;
input end1_est = 1600;
def start1 = start1_EST;
def end1 = end1_est;

input show_start_end_vertical_lines = yes;
def ssevl = show_start_end_vertical_lines;
input show_midnight_vertical_line = yes;
def smvl = show_midnight_vertical_line;
input show_current_period_labels = yes;
def scpl = show_current_period_labels;

def na = Double.NaN;
#def hi = high;
#def lo = low;
def bn = BarNumber();


# chg
def wickht = high - low;


# ---- wicks or body -------------------
#input candle_levels = {default "wick" , "body" };
def highx;
def lowx;
switch (candle_levels) {
case "wick":
  highx = high;
  lowx = low;
case "body":
  highx = max( open, close);
  lowx = min( open, close);
}

# reassign hi lo  to new vars
def hi = highx;
def lo = lowx;

# ----------------------------------------



# color alts  gray 90,90,90    tan 70,70,70    grn 70,110,20
input show_shading = yes;
#input color_numbers_0to255 = yes;
#shading color is created by entering RGB color numbers, 0-255 , for red,green,blue
input shade_color_red_num0to255 = 70;
def cred = shade_color_red_num0to255;
input shade_color_green_num0to255 = 110;
def cgrn = shade_color_green_num0to255;
input shade_color_blue_num0to255 = 20;
def cblu = shade_color_blue_num0to255;

# show test data in labels and bubbles
input showtest = no;
def lastbar = !isnan(close[0]) and isnan(close[-1]);

# define the shading color
DefineGlobalColor( "shade1" , CreateColor(cred, cgrn, cblu));
addlabel(yes, market, GlobalColor( "shade1" ));

# -----------------------------------------------

#  calc total minutes , from midnight , to each time
def start1hr = Floor(start1 / 100);
def start1min = start1 - (start1hr * 100);
def start1minttl = (start1hr * 60) + start1min;
AddLabel(showtest, start1 + ".." + "st hrs=" + start1hr + ".." + start1min + ".." + start1minttl, Color.CYAN);

def end1hr = Floor(end1 / 100);
def end1min = end1 - (end1hr * 100);
def end1minttl = (end1hr * 60) + end1min;
AddLabel(showtest, end1 + ".." + "end hrs=" + end1hr + ".." + end1min + ".." + end1minttl, Color.RED);

# ===========================>>>>>>>>>>>>>>>>>>>>

#  elapsed min in current period
def stmin2 = SecondsFromTime(start1);
def stmin = stmin2 / (60);
AddLabel(showtest, "period min=" + stmin , Color.GREEN);

# ===========================>>>>>>>>>>>>>>>>>>>

#  is bar in a time period? , minutes in a day , 24 x 60 = 1440
def daymin = 1440;
def endz = 2359;
def startz = 0000;
def  first1 = if SecondsTillTime(start1) == 0 then 1 else 0;
def  last1 = if SecondsFromTime(end1) == 0 then 1 else 0;

def period1min;
def period1;
if start1minttl > end1minttl
then {
   # spans midnight , period=(24-start)+end , end to start
    period1min = (daymin - start1minttl) + end1minttl;
    period1 = if ((SecondsFromTime(start1) >= 0 and SecondsTillTime(endz) > 0) or ( SecondsFromTime(startz) >= 0 and SecondsTillTime(end1) > 0)) then 1 else 0;
} else {
   # ok , period=end-start , start to end
    period1min = (end1minttl - start1minttl);
    period1 = if SecondsFromTime(start1) >= 0 and SecondsTillTime(end1) > 0 then 1 else 0;
}

# ====================================

AddVerticalLine(ssevl and first1, "Start " + start1 , Color.GREEN, Curve.MEDIUM_DASH);
AddVerticalLine(ssevl and last1, "End " + end1 , Color.ORANGE, Curve.MEDIUM_DASH);

#  display time as hr:min ,  but trailing 0 not shown
#AddVerticalLine(ssevl and first1, "start " + start1hr + ":" + start1min , Color.GREEN, Curve.MEDIUM_DASH);
#AddVerticalLine(ssevl and last1, "end " + end1hr + ":" + end1min , Color.ORANGE, Curve.MEDIUM_DASH);
AddChartBubble(showtest, low - 1, period1, if period1 then Color.GREEN else Color.CYAN, no);

# midnight
def midn = 0000;
def midnite = if (smvl and SecondsTillTime(midn) == 0) then 1 else 0;
AddVerticalLine(midnite, "midnight" , Color.BLUE, Curve.MEDIUM_DASH);
AddLabel(showtest, "daymin=" + daymin + "  end1minttl=" + end1minttl + "  start1minttl=" + start1minttl, Color.GREEN);

AddLabel(showtest, "period1 min=" + period1min, Color.YELLOW);
AddLabel(scpl and period1, "hrs: " + round((period1min/60),1), GlobalColor("shade1"));

# -----------------------------------------------

# get chart agg minutes
def chagg = GetAggregationPeriod();
def aggmin = chagg / (1000 * 60);
AddLabel(showtest, "agg=" + aggmin, Color.CYAN);

# calc qty of bars of period1, for the current chart time
def period1bars = period1min / aggmin;
AddLabel(showtest, "period1 bars=" + period1bars, Color.YELLOW);

# ex. trade session = 6.5 hrs = 390 min
# 5 min chart = 390/5 = 78 bars  over 6.5 hours
# def len = 78;

# =====================<<<<<<<<<<<<<<<<<<<<<<

#  add check if in period and if last bar
def currentperiodbars = if (period1 and lastbar) then (stmin / aggmin) else 0;
AddLabel(showtest, "current period bars=" + currentperiodbars, Color.magenta);
AddLabel(scpl and period1, "bars " + currentperiodbars + "/" + period1bars, GlobalColor("shade1"));


#  find the high of active period, only on last bar
def xhi = fold xi = 0 to currentperiodbars
    with n = hi
    do Max(n, GetValue(hi, xi));

AddLabel(scpl and period1, "highest: " + xhi , GlobalColor("shade1"));

#  find the low of active period, only on last bar
def xlo = fold xj = 0 to currentperiodbars
    with m = lo
    do Min(m, GetValue(lo, xj));

AddLabel(scpl and period1, "lowest: " + xlo , GlobalColor("shade1"));

def len = period1bars - 1;

# ---------------------------------------------

# find high value for previous/complete time period, draw a line
def hi2 = if first1 then Highest(hi[-len], len + 1)
   else if last1 then na
   else if period1 then hi2[1]
   else na;

plot hiline = hi2;
hiline.SetDefaultColor(Color.WHITE);
#hiline.SetStyle(Curve.MEDIUM_DASH);
hiline.SetLineWeight(1);
hiline.HideBubble();

# ------------------------------------------------
# find low value for previous/complete time period, draw a line

def lo2 = if first1 then Lowest(lo[-len], len + 1)
   else if last1 then na
   else if period1 then lo2[1]
   else na;

plot loline = lo2;
loline.SetDefaultColor(Color.WHITE);
#loline.SetStyle(Curve.MEDIUM_DASH);
loline.SetLineWeight(1);
loline.HideBubble();

# ---------------------------------------------

# shading
def hiline2 = if show_shading then hiline else na;
def loline2 = if show_shading then loline else na;

#addcloud(hiline,loline,color.light_gray,color.light_gray);
AddCloud(hiline2, loline2, GlobalColor( "shade1" ), GlobalColor( "shade1" ) );
#
 
Simple problem. I'm looking to draw a box around a candle using its high and low values. I know about the boolean plots and draw wedges, arrows etc, but I'd really like a box.
The addcloud function is close but I can't control the width.
Any help would be appreciated.
 
My indicator marks every third new high candle. I've scripted a boolean wedge above it but would visually prefer a box. The last line is my latest attempt to draw it with addcloud.

Code:
def IsUp = close > open;
def IsDown = close < open;
def IsDoji = IsDoji();
def avgRange = 0.05 * Average(high - low, 20);
def PatternPlot =
    if ((Sum(IsUp, 1)[3] >= 0)) and
    ((Sum(IsUp, 1)[2] >= 0)) and
    ((Sum(IsUp, 1)[1] >= 0)) and
    ((Sum(IsUp, 1)[0] >= 0)) and
    Highest(high[3], 1) < Highest(high[2], 1) and
    Highest(high[2], 1) < Highest(high[1], 1) and
    Highest(high[1], 1) < Highest(high[0], 1) then 1 else 0;
def cancelPatternPlot = if PatternPlot[1] ==1 then 1 else 0;

plot pattern = PatternPlot==1 and cancelPatternPlot==0;
pattern.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
pattern.SetDefaultColor(Color.LIGHT_RED);
pattern.SetLineWeight(2);

AddCloud(if pattern then high else Double.NaN, if pattern then low else Double.NaN, Color.RED);
 
@redart1021 Hopefully this is what you're looking for:

Code:
def IsUp = close > open;
def IsDown = close < open;
def IsDoji = IsDoji();
def avgRange = 0.05 * Average(high - low, 20);
def PatternPlot =
    if ((Sum(IsUp, 1)[3] >= 0)) and
    ((Sum(IsUp, 1)[2] >= 0)) and
    ((Sum(IsUp, 1)[1] >= 0)) and
    ((Sum(IsUp, 1)[0] >= 0)) and
    Highest(high[3], 1) < Highest(high[2], 1) and
    Highest(high[2], 1) < Highest(high[1], 1) and
    Highest(high[1], 1) < Highest(high[0], 1) then 1 else 0;
def cancelPatternPlot = if PatternPlot[1] ==1 then 1 else 0;

plot pattern = PatternPlot==1 and cancelPatternPlot==0;
pattern.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
pattern.SetDefaultColor(Color.LIGHT_RED);
pattern.SetLineWeight(2);

def b_high = if pattern then high else b_high[1];
def b_low = if pattern then low  else b_low[1];

plot hh = b_high;
plot ll = b_low;

hh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ll.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
hh.SetDefaultColor(Color.YELLOW);
ll.SetDefaultColor(Color.YELLOW);
 
My indicator marks every third new high candle. I've scripted a boolean wedge above it but would visually prefer a box. The last line is my latest attempt to draw it with addcloud.
Code:
def IsUp = close > open;
def IsDown = close < open;
def IsDoji = IsDoji();
def avgRange = 0.05 * Average(high - low, 20);
def PatternPlot =
    if ((Sum(IsUp, 1)[3] >= 0)) and
    ((Sum(IsUp, 1)[2] >= 0)) and
    ((Sum(IsUp, 1)[1] >= 0)) and
    ((Sum(IsUp, 1)[0] >= 0)) and
    Highest(high[3], 1) < Highest(high[2], 1) and
    Highest(high[2], 1) < Highest(high[1], 1) and
    Highest(high[1], 1) < Highest(high[0], 1) then 1 else 0;
def cancelPatternPlot = if PatternPlot[1] ==1 then 1 else 0;

plot pattern = PatternPlot==1 and cancelPatternPlot==0;
pattern.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
pattern.SetDefaultColor(Color.LIGHT_RED);
pattern.SetLineWeight(2);

AddCloud(if pattern then high else Double.NaN, if pattern then low else Double.NaN, Color.RED);

Here is another workaround to TOS's limitation to draw boxes with code and to color the box without distorting the underlying candle. The code allows you to have a 'box'/border around the candle that you can adjust the size at the input tickoffset. You can also opt to color the candle to match the 'box'/border.
Code:
# Example Using Addchart to draw a 'Box' around each candle meeting a condition. The 'box' can be extended by the number of ticks entered at the input, tickoffset

# Sleepyz

input tickoffset = 5;
input charttype  = ChartType.CANDLE;
def o = open;
def h = high;
def l = low;
def c = close;
def nan = Double.NaN;

def IsUp = close > open;
def IsDown = close < open;
def IsDoji = IsDoji();
def avgRange = 0.05 * Average(high - low, 20);
def PatternPlot =
    if ((Sum(IsUp, 1)[3] >= 0)) and
    ((Sum(IsUp, 1)[2] >= 0)) and
    ((Sum(IsUp, 1)[1] >= 0)) and
    ((Sum(IsUp, 1)[0] >= 0)) and
    Highest(high[3], 1) < Highest(high[2], 1) and
    Highest(high[2], 1) < Highest(high[1], 1) and
    Highest(high[1], 1) < Highest(high[0], 1) then 1 else 0;
def cancelPatternPlot = if PatternPlot[1] ==1 then 1 else 0;

def condition = PatternPlot==1 and cancelPatternPlot==0;

def o1 = if condition then h + TickSize() * tickoffset else nan;
def c1 = if condition then l - TickSize() * tickoffset else nan;
def h1 = if condition then h + TickSize() * tickoffset else nan;
def l1 = if condition then l - TickSize() * tickoffset else nan;

DefineGlobalColor(color = Color.YELLOW, name = "Box");
input usepricecolor = yes;
assignpriceColor(if usepricecolor and condition then globalcolor("Box") else color.CURRENT);
AddChart(growcolor = GlobalColor("Box"), high = h1, low = l1, open = c1, close = o1, type = charttype);
Capture.jpg
 
Last edited:
Hi, Is there a way to have indicator that highlights certain times of the day known as key potential reversal times? Wondering if someone could guide me on how to code something up like this.

Trading view has this and it's call TS2_intraday_times

https://www.tradingview.com/x/J93BmkFK/

Major Reversal Times: 9:30-9:35, 9:50-10:10, 1:30PM, 2:15PM, 3:00PM, 4:01Pm

Notable Reversal Times - Optional - 10:25-10:35, 11:15, 12:00, 3:30pm
 
here is my version of a study, to specify a repeating time period, that i made a few months ago.
this doesn't use highestall(), as it can cause a script to become complex, and slow down TOS.

find the high and low, over some specified time period, every 24 hours
# hilolines_07a
http://tos.mx/ggTL45x
# 2020-07-17
# halcyonguy
# time periods work over midnight
# can choose wicks or body
# draw shading, bounded by start/stop times and highest/lowest levels
# enter start and end times, (24 hour EST), for a period < 24 hours
# can choose to show several parameters , labels, lines, shading
# pick /es for testing. trades most of the day

ulgOaLg.jpg


Code:
# hilolines_07

# abandon ver06
# start with a copy of ver05, not 05b. this works over midnight
#  add , wicks or body


# hilolines_06
#  removed too much in v05b. doesn't work over midnight
#   wicks or body


# hilolines_05
# 2020-07-17
# halcyonguy
# draw shading, bounded by start/stop times and highest/lowest levels
#  enter start and end times, (24 hour EST), for a period < 24 hours
#  can choose to show several parameters , labels, lines, shading
#   pick  /es  for testing.  trades most of day

declare hide_on_daily;

input candle_levels = {default "wick" , "body" };

input market = { default "U.S." , "EU" , "Asian" , "-"};

input start1_est = 0930;
input end1_est = 1600;
def start1 = start1_EST;
def end1 = end1_est;

input show_start_end_vertical_lines = yes;
def ssevl = show_start_end_vertical_lines;
input show_midnight_vertical_line = yes;
def smvl = show_midnight_vertical_line;
input show_current_period_labels = yes;
def scpl = show_current_period_labels;

def na = Double.NaN;
#def hi = high;
#def lo = low;
def bn = BarNumber();


# chg
def wickht = high - low;


# ---- wicks or body -------------------
#input candle_levels = {default "wick" , "body" };
def highx;
def lowx;
switch (candle_levels) {
case "wick":
  highx = high;
  lowx = low;
case "body":
  highx = max( open, close);
  lowx = min( open, close);
}

# reassign hi lo  to new vars
def hi = highx;
def lo = lowx;

# ----------------------------------------



# color alts  gray 90,90,90    tan 70,70,70    grn 70,110,20
input show_shading = yes;
#input color_numbers_0to255 = yes;
#shading color is created by entering RGB color numbers, 0-255 , for red,green,blue
input shade_color_red_num0to255 = 70;
def cred = shade_color_red_num0to255;
input shade_color_green_num0to255 = 110;
def cgrn = shade_color_green_num0to255;
input shade_color_blue_num0to255 = 20;
def cblu = shade_color_blue_num0to255;

# show test data in labels and bubbles
input showtest = no;
def lastbar = !isnan(close[0]) and isnan(close[-1]);

# define the shading color
DefineGlobalColor( "shade1" , CreateColor(cred, cgrn, cblu));
addlabel(yes, market, GlobalColor( "shade1" ));

# -----------------------------------------------

#  calc total minutes , from midnight , to each time
def start1hr = Floor(start1 / 100);
def start1min = start1 - (start1hr * 100);
def start1minttl = (start1hr * 60) + start1min;
AddLabel(showtest, start1 + ".." + "st hrs=" + start1hr + ".." + start1min + ".." + start1minttl, Color.CYAN);

def end1hr = Floor(end1 / 100);
def end1min = end1 - (end1hr * 100);
def end1minttl = (end1hr * 60) + end1min;
AddLabel(showtest, end1 + ".." + "end hrs=" + end1hr + ".." + end1min + ".." + end1minttl, Color.RED);

# ===========================>>>>>>>>>>>>>>>>>>>>

#  elapsed min in current period
def stmin2 = SecondsFromTime(start1);
def stmin = stmin2 / (60);
AddLabel(showtest, "period min=" + stmin , Color.GREEN);

# ===========================>>>>>>>>>>>>>>>>>>>

#  is bar in a time period? , minutes in a day , 24 x 60 = 1440
def daymin = 1440;
def endz = 2359;
def startz = 0000;
def  first1 = if SecondsTillTime(start1) == 0 then 1 else 0;
def  last1 = if SecondsFromTime(end1) == 0 then 1 else 0;

def period1min;
def period1;
if start1minttl > end1minttl
then {
   # spans midnight , period=(24-start)+end , end to start
    period1min = (daymin - start1minttl) + end1minttl;
    period1 = if ((SecondsFromTime(start1) >= 0 and SecondsTillTime(endz) > 0) or ( SecondsFromTime(startz) >= 0 and SecondsTillTime(end1) > 0)) then 1 else 0;
} else {
   # ok , period=end-start , start to end
    period1min = (end1minttl - start1minttl);
    period1 = if SecondsFromTime(start1) >= 0 and SecondsTillTime(end1) > 0 then 1 else 0;
}

# ====================================

AddVerticalLine(ssevl and first1, "Start " + start1 , Color.GREEN, Curve.MEDIUM_DASH);
AddVerticalLine(ssevl and last1, "End " + end1 , Color.ORANGE, Curve.MEDIUM_DASH);

#  display time as hr:min ,  but trailing 0 not shown
#AddVerticalLine(ssevl and first1, "start " + start1hr + ":" + start1min , Color.GREEN, Curve.MEDIUM_DASH);
#AddVerticalLine(ssevl and last1, "end " + end1hr + ":" + end1min , Color.ORANGE, Curve.MEDIUM_DASH);
AddChartBubble(showtest, low - 1, period1, if period1 then Color.GREEN else Color.CYAN, no);

# midnight
def midn = 0000;
def midnite = if (smvl and SecondsTillTime(midn) == 0) then 1 else 0;
AddVerticalLine(midnite, "midnight" , Color.BLUE, Curve.MEDIUM_DASH);
AddLabel(showtest, "daymin=" + daymin + "  end1minttl=" + end1minttl + "  start1minttl=" + start1minttl, Color.GREEN);

AddLabel(showtest, "period1 min=" + period1min, Color.YELLOW);
AddLabel(scpl and period1, "hrs: " + round((period1min/60),1), GlobalColor("shade1"));

# -----------------------------------------------

# get chart agg minutes
def chagg = GetAggregationPeriod();
def aggmin = chagg / (1000 * 60);
AddLabel(showtest, "agg=" + aggmin, Color.CYAN);

# calc qty of bars of period1, for the current chart time
def period1bars = period1min / aggmin;
AddLabel(showtest, "period1 bars=" + period1bars, Color.YELLOW);

# ex. trade session = 6.5 hrs = 390 min
# 5 min chart = 390/5 = 78 bars  over 6.5 hours
# def len = 78;

# =====================<<<<<<<<<<<<<<<<<<<<<<

#  add check if in period and if last bar
def currentperiodbars = if (period1 and lastbar) then (stmin / aggmin) else 0;
AddLabel(showtest, "current period bars=" + currentperiodbars, Color.magenta);
AddLabel(scpl and period1, "bars " + currentperiodbars + "/" + period1bars, GlobalColor("shade1"));


#  find the high of active period, only on last bar
def xhi = fold xi = 0 to currentperiodbars
    with n = hi
    do Max(n, GetValue(hi, xi));

AddLabel(scpl and period1, "highest: " + xhi , GlobalColor("shade1"));

#  find the low of active period, only on last bar
def xlo = fold xj = 0 to currentperiodbars
    with m = lo
    do Min(m, GetValue(lo, xj));

AddLabel(scpl and period1, "lowest: " + xlo , GlobalColor("shade1"));

def len = period1bars - 1;

# ---------------------------------------------

# find high value for previous/complete time period, draw a line
def hi2 = if first1 then Highest(hi[-len], len + 1)
   else if last1 then na
   else if period1 then hi2[1]
   else na;

plot hiline = hi2;
hiline.SetDefaultColor(Color.WHITE);
#hiline.SetStyle(Curve.MEDIUM_DASH);
hiline.SetLineWeight(1);
hiline.HideBubble();

# ------------------------------------------------
# find low value for previous/complete time period, draw a line

def lo2 = if first1 then Lowest(lo[-len], len + 1)
   else if last1 then na
   else if period1 then lo2[1]
   else na;

plot loline = lo2;
loline.SetDefaultColor(Color.WHITE);
#loline.SetStyle(Curve.MEDIUM_DASH);
loline.SetLineWeight(1);
loline.HideBubble();

# ---------------------------------------------

# shading
def hiline2 = if show_shading then hiline else na;
def loline2 = if show_shading then loline else na;

#addcloud(hiline,loline,color.light_gray,color.light_gray);
AddCloud(hiline2, loline2, GlobalColor( "shade1" ), GlobalColor( "shade1" ) );
#

Thanks for sharing this. I'm trying to figure out how to extend high and low lines defined in the start and end times out to the end of the 24 hour period. IE: start time 1800 EST end time 0400 EST, high and low lines from this timeframe extended out to current bar, ending at 1759. Can you or anyone else help me out? Thanks
 
@marlin777 Thanks for sharing this. I'm trying to figure out how to extend high and low lines defined in the start and end times out to the end of the 24 hour period. IE: start time 1800 EST end time 0400 EST, high and low lines from this timeframe extended out to current bar, ending at 1759. Can you or anyone else help me out? Thanks

Hopefully, this works how you wanted. It is supposed to keep moving the high/low from the openingtime at the highest/lowest values, end those values changing at the closingtime and extend those until the next openingtime.

Screenshot-2021-08-25-160830.jpg
Code:
input openingTime = 1800;
input closingTime = 1600;

def sec1    = SecondsFromTime(openingTime);
def sec2    = SecondsFromTime(closingTime);
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 inRange = CompoundValue(1, if isTime1 then 1 else if isTime2 then 0 else inRange[1], 0);

def rhi        = if inRange and !inRange[1]
                 then high
                 else if inRange[1] and high > rhi[1]
                 then high else rhi[1];
def rHighBar   = if inRange and high == rhi then BarNumber() else Double.NaN;
def rHighest   = if BarNumber() == HighestAll(rHighBar)  then rhi else rHighest[1];

plot rangehigh = if rhighest>=0 or secondstillTime(openingtime)>=0 then rHighest else Double.NaN;
rangehigh.setpaintingStrategy(paintingStrategy.HORIZONTAL);
rangehigh.setlineWeight(2);

def rlow       = if inRange and !inRange[1]
                 then low
                 else if inRange[1] and low < rlow[1]
                 then low else rlow[1];
def rLowBar    = if inRange and low == rlow then BarNumber() else Double.NaN;
def rlowest    = if BarNumber() == HighestAll(rLowBar) then rlow else rlowest[1];

plot rangelow  = if rlowest >=0 or secondstillTime(openingtime)>=0 then rlowest else Double.NaN;
rangelow.setpaintingStrategy(paintingStrategy.HORIZONTAL);
rangelow.setlineWeight(2);
 
Hopefully, this works how you wanted. It is supposed to keep moving the high/low from the openingtime at the highest/lowest values, end those values changing at the closingtime and extend those until the next openingtime.
Thanks for this. I'm basically trying to merge this with the script I posted from @halcyonguy. This script from tradingview is what I'm trying to recreate in TOS: The blue session range box, with the session high/low extended through the end of session.
joGsCX0.jpg
 
Hi, Is there a way to have indicator that highlights certain times of the day known as key potential reversal times? Wondering if someone could guide me on how to code something up like this.

Trading view has this and it's call TS2_intraday_times

https://www.tradingview.com/x/J93BmkFK/

Major Reversal Times: 9:30-9:35, 9:50-10:10, 1:30PM, 2:15PM, 3:00PM, 4:01Pm

Notable Reversal Times - Optional - 10:25-10:35, 11:15, 12:00, 3:30pm

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
 
Thanks for this. I'm basically trying to merge this with the script I posted from @halcyonguy. This script from tradingview is what I'm trying to recreate in TOS: The blue session range box, with the session high/low extended through the end of session.
joGsCX0.jpg

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.

Screenshot-2021-08-26-075015.jpg
Ruby:
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   = 2000;

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 bubblemover = 0;
def b  = bubblemover;
def b1 = b + 1;


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

input showverticalline = yes;
AddVerticalLine(showverticalline and hrange != hrange[1], "", Color.BLUE, stroke = Curve.FIRM);
 
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
Thank you @mashume
i think i have a diferent my chart setting, because a tried to run the code but doesn´t run, i opened shared item and i saw is diferent.
i don´t know if you use a diferent kind of config in yours charts.

thank you for you help.
 
@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
Can you post the newest copy of london you have please?
 

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
288 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