The code for the indicator is generated by a python script somewhere in this thread. It works on 2min I think (depends on the version... I think I updated it, but perhaps not... I'll check sometime).Few questions.
Does the code have to updated to get /es levels? How often does the code have to be updated? 60 days?
Can the code used on lower time frame? 2 min chart?
There is no facility in ThinkOrSwim to generate the statistics that are hard coded into the indicator. That's why the python code exists. Python downloads the 5m data from YFinance, does some statistical magic, and then spits out ThinkScript code that you paste into the code editor in ThinkOrSwim and you have an updated indicator.
I'll run off a new /ES for 'yall ... just a moment.
FYI, if you're happy with the performance of the indicator as you're using it, there is no need to update. Updates are useful for seasonal changes, or just market mood changes. There is a post in here about volatility before and after some event or other... it makes for some interesting statistics. If you're into that sort of thing.
Code:
#########################################################
#
# Next Hour ES Trading Range
# Algorithmic Prediction
#
# Values Derived on Data from
# 2022-07-06 to
# 2022-09-13
#
# @mashume at usethinkscript.com
#
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#
# This Version /ES only
# Functional on 1, 2, 3, 5, 10, 15, 20, 30, 60 minute charts
#
#########################################################
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) / H);
def HOUR = if GMT > 4 then GMT - 4 else if GMT < 4 then (GMT + 24) - 4 else 0;
def tf = getAggregationPeriod();
def barsPerHour = if tf == AggregationPeriod.HOUR then 1
else if tf == AggregationPeriod.THIRTY_MIN then 2
else if tf == AggregationPeriod.TWENTY_MIN then 3
else if tf == AggregationPeriod.FIFTEEN_MIN then 4
else if tf == AggregationPeriod.TEN_MIN then 6
else if tf == AggregationPeriod.FIVE_MIN then 12
else if tf == AggregationPeriod.THREE_MIN then 20
else if tf == AggregationPeriod.TWO_MIN then 30
else if tf == AggregationPeriod.MIN then 60
else double.nan;
def q1 =
if HOUR == 0 then -2.562000
else if HOUR == 1 then -3.250000
else if HOUR == 2 then -4.188000
else if HOUR == 3 then -5.250000
else if HOUR == 4 then -3.750000
else if HOUR == 5 then -3.500000
else if HOUR == 6 then -4.250000
else if HOUR == 7 then -5.000000
else if HOUR == 8 then -7.750000
else if HOUR == 9 then -9.500000
else if HOUR == 10 then -7.250000
else if HOUR == 11 then -7.250000
else if HOUR == 12 then -6.750000
else if HOUR == 13 then -7.312000
else if HOUR == 14 then -4.500000
else if HOUR == 15 then -6.750000
else if HOUR == 16 then -4.500000
else if HOUR == 17 then -9.375000
else if HOUR == 18 then -2.500000
else if HOUR == 19 then -4.250000
else if HOUR == 20 then -3.250000
else if HOUR == 21 then -1.750000
else if HOUR == 22 then -1.500000
else -2.000000;
def q3 =
if HOUR == 0 then 2.500000
else if HOUR == 1 then 3.000000
else if HOUR == 2 then 5.750000
else if HOUR == 3 then 5.750000
else if HOUR == 4 then 4.250000
else if HOUR == 5 then 4.500000
else if HOUR == 6 then 3.500000
else if HOUR == 7 then 5.000000
else if HOUR == 8 then 8.312500
else if HOUR == 9 then 13.750000
else if HOUR == 10 then 12.750000
else if HOUR == 11 then 7.500000
else if HOUR == 12 then 9.250000
else if HOUR == 13 then 7.500000
else if HOUR == 14 then 8.062500
else if HOUR == 15 then 6.750000
else if HOUR == 16 then 2.250000
else if HOUR == 17 then -6.125000
else if HOUR == 18 then 2.000000
else if HOUR == 19 then 2.000000
else if HOUR == 20 then 3.500000
else if HOUR == 21 then 3.500000
else if HOUR == 22 then 3.000000
else 1.812000;
def m2 =
if HOUR == 0 then -0.500000
else if HOUR == 1 then -0.250000
else if HOUR == 2 then 0.500000
else if HOUR == 3 then -0.125000
else if HOUR == 4 then -0.250000
else if HOUR == 5 then 0.000000
else if HOUR == 6 then -0.250000
else if HOUR == 7 then 0.500000
else if HOUR == 8 then 0.500000
else if HOUR == 9 then 1.250000
else if HOUR == 10 then 3.250000
else if HOUR == 11 then 0.750000
else if HOUR == 12 then 2.375000
else if HOUR == 13 then 0.250000
else if HOUR == 14 then 2.250000
else if HOUR == 15 then 0.250000
else if HOUR == 16 then -1.250000
else if HOUR == 17 then -8.000000
else if HOUR == 18 then -0.250000
else if HOUR == 19 then -1.250000
else if HOUR == 20 then 0.500000
else if HOUR == 21 then 1.000000
else if HOUR == 22 then 0.750000
else 0.250000;
def midline = hl2(period = AggregationPeriod.HOUR)[1];
def median = hl2(period = AggregationPeriod.HOUR)[1] + m2;
def upper = median + (q3);
def lower = median + (q1);
plot c = midline;
c.setStyle(CURve.SHORT_DASH);
c.setDefaultColor(getColor(7));
plot median_line = median[barsPerHour];
median_line.SetPaintingStrategy(PaintingStrategy.DASHES);
median_line.SetDefaultColor(getColor(3));
plot expected_upper = upper[barsPerHour];
expected_upper.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
expected_upper.SetDefaultColor(getColor(1));
plot expected_lower = lower[barsPerHour];
expected_lower.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
expected_lower.SetDefaultColor(getColor(5));
addcloud(expected_upper, expected_lower, color.white, color.white);
def upside = (expected_upper[(-1 * barsPerHour)] - close);
def downside = (close - expected_lower[(-1 * barsPerHour)]);
addLabel(yes, "current upside: " + upside + " current downside: " + downside, if upside > downside then color.dark_green else if downside > upside then color.dark_red else color.dark_gray);
def dist_to_median = (median_line[(-1 * barsPerHour)] - close);
addLabel(yes, "Distance to Median: " + dist_to_median,
if dist_to_median > 5 then color.green
else if dist_to_median > 1 then color.dark_green
else if dist_to_median < -5 then color.red
else if dist_to_median < -1 then color.dark_red
else color.gray);
happy trading,
mashume