/ES Futures Quasi-Algo 1 Hour Out Prediction for ThinkorSwim

@mashume This looks very interesting...Do you happen to have /GC? Only thing I didn't see you posted.
Code:
#########################################################
#
#   Next Hour GC Trading Range
#     Algorithmic Prediction
#
#   Values Derived on Data from
#          2021-09-24 to
#          2021-12-02
#
#   @mashume at usethinkscript.com
#
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#
#  This Version /GC only
#  Functional on 1, 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.MIN then 60
    else double.nan;
 

def q1 =
    if HOUR == 0 then -1.1
    else if HOUR == 1 then -1.7
    else if HOUR == 2 then -2.3
    else if HOUR == 3 then -1.7
    else if HOUR == 4 then -1.8
    else if HOUR == 5 then -1.6
    else if HOUR == 6 then -1.5
    else if HOUR == 7 then -2.6
    else if HOUR == 8 then -3.55
    else if HOUR == 9 then -3.325
    else if HOUR == 10 then -2.3
    else if HOUR == 11 then -1.8
    else if HOUR == 12 then -1.7
    else if HOUR == 13 then -1.1
    else if HOUR == 14 then -1.2
    else if HOUR == 15 then -0.8
    else if HOUR == 16 then -0.8
    else if HOUR == 17 then -1.45
    else if HOUR == 18 then -0.8
    else if HOUR == 19 then -1.2
    else if HOUR == 20 then -1.2
    else if HOUR == 21 then -1.325
    else if HOUR == 22 then -1.3
    else -1.0;
def q3 =
    if HOUR == 0 then 1.4
    else if HOUR == 1 then 1.5
    else if HOUR == 2 then 1.925
    else if HOUR == 3 then 2.0
    else if HOUR == 4 then 1.9
    else if HOUR == 5 then 1.425
    else if HOUR == 6 then 2.0
    else if HOUR == 7 then 3.1
    else if HOUR == 8 then 2.9
    else if HOUR == 9 then 3.5
    else if HOUR == 10 then 2.5
    else if HOUR == 11 then 1.6
    else if HOUR == 12 then 1.0
    else if HOUR == 13 then 1.3
    else if HOUR == 14 then 1.1
    else if HOUR == 15 then 1.0
    else if HOUR == 16 then 0.8
    else if HOUR == 17 then -1.15
    else if HOUR == 18 then 0.9
    else if HOUR == 19 then 1.1
    else if HOUR == 20 then 1.9
    else if HOUR == 21 then 1.5
    else if HOUR == 22 then 0.925
    else 1.0;
def m2 =
    if HOUR == 0 then 0.1
    else if HOUR == 1 then -0.1
    else if HOUR == 2 then 0.2
    else if HOUR == 3 then 0.1
    else if HOUR == 4 then 0.1
    else if HOUR == 5 then 0.1
    else if HOUR == 6 then 0.5
    else if HOUR == 7 then 0.7
    else if HOUR == 8 then 0.3
    else if HOUR == 9 then 0.15
    else if HOUR == 10 then -0.1
    else if HOUR == 11 then 0.0
    else if HOUR == 12 then -0.4
    else if HOUR == 13 then 0.1
    else if HOUR == 14 then -0.25
    else if HOUR == 15 then 0.1
    else if HOUR == 16 then -0.1
    else if HOUR == 17 then -1.3
    else if HOUR == 18 then -0.2
    else if HOUR == 19 then -0.1
    else if HOUR == 20 then 0.4
    else if HOUR == 21 then 0.0
    else if HOUR == 22 then -0.2
    else -0.1;

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

EDIT:
This is showing some strangeness in the data at the 17:00 hour. See below:
The top plot is short holds, the second plot is medium holds.

2PfbrXu.png

I believe the data is accurate but be careful of it at that time until you see how it's behaving
 
Last edited:
Updated Values:

/ES

Code:
#########################################################
#
#   Next Hour ES Trading Range
#     Algorithmic Prediction
#
#   Values Derived on Data from
#          2021-09-13 to
#          2021-11-19
#
#   @mashume at usethinkscript.com
#
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#
#  This Version /ES only
#  Functional on 1, 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.MIN then 60
    else double.nan;
   

def q1 =
    if HOUR == 0 then -1.5
    else if HOUR == 1 then -2.5
    else if HOUR == 2 then -2.75
    else if HOUR == 3 then -2.25
    else if HOUR == 4 then -2.75
    else if HOUR == 5 then -2.5
    else if HOUR == 6 then -2.25
    else if HOUR == 7 then -2.812
    else if HOUR == 8 then -4.5
    else if HOUR == 9 then -9.5
    else if HOUR == 10 then -4.5
    else if HOUR == 11 then -4.25
    else if HOUR == 12 then -5.0
    else if HOUR == 13 then -2.75
    else if HOUR == 14 then -4.25
    else if HOUR == 15 then -6.5
    else if HOUR == 16 then -1.0
    else if HOUR == 17 then -3.375
    else if HOUR == 18 then -1.75
    else if HOUR == 19 then -2.562
    else if HOUR == 20 then -3.25
    else if HOUR == 21 then -3.0
    else if HOUR == 22 then -1.5
    else -1.25;
def q3 =
    if HOUR == 0 then 2.75
    else if HOUR == 1 then 2.5
    else if HOUR == 2 then 3.75
    else if HOUR == 3 then 4.5
    else if HOUR == 4 then 2.75
    else if HOUR == 5 then 2.5
    else if HOUR == 6 then 3.0
    else if HOUR == 7 then 3.312
    else if HOUR == 8 then 5.5
    else if HOUR == 9 then 10.5
    else if HOUR == 10 then 5.812
    else if HOUR == 11 then 4.812
    else if HOUR == 12 then 3.625
    else if HOUR == 13 then 6.062
    else if HOUR == 14 then 5.0
    else if HOUR == 15 then 4.625
    else if HOUR == 16 then 3.438
    else if HOUR == 17 then -0.75
    else if HOUR == 18 then 2.5
    else if HOUR == 19 then 3.75
    else if HOUR == 20 then 2.75
    else if HOUR == 21 then 2.25
    else if HOUR == 22 then 2.0
    else 2.0;
def m2 =
    if HOUR == 0 then 0.25
    else if HOUR == 1 then 0.25
    else if HOUR == 2 then 1.0
    else if HOUR == 3 then 1.375
    else if HOUR == 4 then 0.0
    else if HOUR == 5 then 0.0
    else if HOUR == 6 then 0.25
    else if HOUR == 7 then 0.0
    else if HOUR == 8 then 0.75
    else if HOUR == 9 then 1.5
    else if HOUR == 10 then 0.75
    else if HOUR == 11 then 0.5
    else if HOUR == 12 then -0.25
    else if HOUR == 13 then 1.5
    else if HOUR == 14 then 0.0
    else if HOUR == 15 then -0.5
    else if HOUR == 16 then 1.25
    else if HOUR == 17 then -2.25
    else if HOUR == 18 then 0.25
    else if HOUR == 19 then -0.375
    else if HOUR == 20 then -0.5
    else if HOUR == 21 then -0.5
    else if HOUR == 22 then 0.25
    else 0.25;

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

YM

Code:
#########################################################
#
#   Next Hour YM Trading Range
#     Algorithmic Prediction
#
#   Values Derived on Data from
#          2021-09-13 to
#          2021-11-19
#
#   @mashume at usethinkscript.com
#
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#
#  This Version /YM only
#  Functional on 1, 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.MIN then 60
    else double.nan;
   

def q1 =
    if HOUR == 0 then -13.0
    else if HOUR == 1 then -20.0
    else if HOUR == 2 then -19.0
    else if HOUR == 3 then -21.0
    else if HOUR == 4 then -20.0
    else if HOUR == 5 then -17.0
    else if HOUR == 6 then -17.75
    else if HOUR == 7 then -24.75
    else if HOUR == 8 then -28.0
    else if HOUR == 9 then -76.0
    else if HOUR == 10 then -47.0
    else if HOUR == 11 then -33.25
    else if HOUR == 12 then -41.0
    else if HOUR == 13 then -32.0
    else if HOUR == 14 then -30.0
    else if HOUR == 15 then -44.0
    else if HOUR == 16 then -8.0
    else if HOUR == 17 then 0.0
    else if HOUR == 18 then -14.0
    else if HOUR == 19 then -18.0
    else if HOUR == 20 then -23.0
    else if HOUR == 21 then -20.0
    else if HOUR == 22 then -12.25
    else -10.0;
def q3 =
    if HOUR == 0 then 19.0
    else if HOUR == 1 then 18.0
    else if HOUR == 2 then 25.0
    else if HOUR == 3 then 34.75
    else if HOUR == 4 then 20.0
    else if HOUR == 5 then 21.0
    else if HOUR == 6 then 26.0
    else if HOUR == 7 then 25.75
    else if HOUR == 8 then 48.0
    else if HOUR == 9 then 72.0
    else if HOUR == 10 then 42.25
    else if HOUR == 11 then 33.0
    else if HOUR == 12 then 24.0
    else if HOUR == 13 then 42.0
    else if HOUR == 14 then 38.0
    else if HOUR == 15 then 32.0
    else if HOUR == 16 then 21.75
    else if HOUR == 17 then 0.0
    else if HOUR == 18 then 20.0
    else if HOUR == 19 then 27.0
    else if HOUR == 20 then 20.75
    else if HOUR == 21 then 17.5
    else if HOUR == 22 then 17.0
    else 14.0;
def m2 =
    if HOUR == 0 then 1.0
    else if HOUR == 1 then 2.0
    else if HOUR == 2 then 6.0
    else if HOUR == 3 then 8.0
    else if HOUR == 4 then 0.0
    else if HOUR == 5 then 2.0
    else if HOUR == 6 then 3.0
    else if HOUR == 7 then 0.0
    else if HOUR == 8 then 5.0
    else if HOUR == 9 then -3.0
    else if HOUR == 10 then 5.0
    else if HOUR == 11 then 3.0
    else if HOUR == 12 then -7.0
    else if HOUR == 13 then 4.0
    else if HOUR == 14 then 0.5
    else if HOUR == 15 then -4.0
    else if HOUR == 16 then 6.0
    else if HOUR == 17 then 0.0
    else if HOUR == 18 then 2.0
    else if HOUR == 19 then -2.0
    else if HOUR == 20 then -3.0
    else if HOUR == 21 then -4.0
    else if HOUR == 22 then 2.0
    else 2.0;

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

NQ

Code:
#########################################################
#
#   Next Hour NQ Trading Range
#     Algorithmic Prediction
#
#   Values Derived on Data from
#          2021-09-13 to
#          2021-11-19
#
#   @mashume at usethinkscript.com
#
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#
#  This Version /NQ only
#  Functional on 1, 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.MIN then 60
    else double.nan;
   

def q1 =
    if HOUR == 0 then -5.0
    else if HOUR == 1 then -11.688
    else if HOUR == 2 then -12.5
    else if HOUR == 3 then -9.0
    else if HOUR == 4 then -11.438
    else if HOUR == 5 then -11.188
    else if HOUR == 6 then -10.562
    else if HOUR == 7 then -13.0
    else if HOUR == 8 then -23.938
    else if HOUR == 9 then -39.812
    else if HOUR == 10 then -23.062
    else if HOUR == 11 then -23.5
    else if HOUR == 12 then -23.75
    else if HOUR == 13 then -8.812
    else if HOUR == 14 then -18.0
    else if HOUR == 15 then -25.25
    else if HOUR == 16 then -6.75
    else if HOUR == 17 then 11.0
    else if HOUR == 18 then -5.5
    else if HOUR == 19 then -9.75
    else if HOUR == 20 then -14.0
    else if HOUR == 21 then -11.0
    else if HOUR == 22 then -7.5
    else -5.75;
def q3 =
    if HOUR == 0 then 10.562
    else if HOUR == 1 then 11.0
    else if HOUR == 2 then 16.75
    else if HOUR == 3 then 19.25
    else if HOUR == 4 then 10.688
    else if HOUR == 5 then 9.688
    else if HOUR == 6 then 11.5
    else if HOUR == 7 then 15.0
    else if HOUR == 8 then 22.25
    else if HOUR == 9 then 49.5
    else if HOUR == 10 then 34.5
    else if HOUR == 11 then 26.312
    else if HOUR == 12 then 18.5
    else if HOUR == 13 then 28.062
    else if HOUR == 14 then 23.938
    else if HOUR == 15 then 20.812
    else if HOUR == 16 then 14.25
    else if HOUR == 17 then 11.0
    else if HOUR == 18 then 9.688
    else if HOUR == 19 then 12.75
    else if HOUR == 20 then 10.75
    else if HOUR == 21 then 9.5
    else if HOUR == 22 then 7.5
    else 8.938;
def m2 =
    if HOUR == 0 then 2.25
    else if HOUR == 1 then 0.75
    else if HOUR == 2 then 4.25
    else if HOUR == 3 then 6.5
    else if HOUR == 4 then 0.0
    else if HOUR == 5 then 0.375
    else if HOUR == 6 then 0.25
    else if HOUR == 7 then 0.125
    else if HOUR == 8 then 0.0
    else if HOUR == 9 then 3.625
    else if HOUR == 10 then 4.5
    else if HOUR == 11 then 3.125
    else if HOUR == 12 then -0.5
    else if HOUR == 13 then 10.625
    else if HOUR == 14 then -0.125
    else if HOUR == 15 then -0.25
    else if HOUR == 16 then 2.625
    else if HOUR == 17 then 11.0
    else if HOUR == 18 then 2.0
    else if HOUR == 19 then 1.0
    else if HOUR == 20 then -1.75
    else if HOUR == 21 then -2.0
    else if HOUR == 22 then 1.0
    else 1.5;

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

CL

Code:
#########################################################
#
#   Next Hour CL Trading Range
#     Algorithmic Prediction
#
#   Values Derived on Data from
#          2021-09-13 to
#          2021-11-19
#
#   @mashume at usethinkscript.com
#
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#
#  This Version /CL only
#  Functional on 1, 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.MIN then 60
    else double.nan;
   

def q1 =
    if HOUR == 0 then -0.07
    else if HOUR == 1 then -0.14
    else if HOUR == 2 then -0.16
    else if HOUR == 3 then -0.17
    else if HOUR == 4 then -0.19
    else if HOUR == 5 then -0.14
    else if HOUR == 6 then -0.14
    else if HOUR == 7 then -0.21
    else if HOUR == 8 then -0.235
    else if HOUR == 9 then -0.35
    else if HOUR == 10 then -0.34
    else if HOUR == 11 then -0.22
    else if HOUR == 12 then -0.15
    else if HOUR == 13 then -0.17
    else if HOUR == 14 then -0.11
    else if HOUR == 15 then -0.08
    else if HOUR == 16 then -0.09
    else if HOUR == 17 then 0.47
    else if HOUR == 18 then -0.1
    else if HOUR == 19 then -0.11
    else if HOUR == 20 then -0.16
    else if HOUR == 21 then -0.17
    else if HOUR == 22 then -0.07
    else -0.05;
def q3 =
    if HOUR == 0 then 0.12
    else if HOUR == 1 then 0.1
    else if HOUR == 2 then 0.14
    else if HOUR == 3 then 0.25
    else if HOUR == 4 then 0.12
    else if HOUR == 5 then 0.145
    else if HOUR == 6 then 0.15
    else if HOUR == 7 then 0.23
    else if HOUR == 8 then 0.4
    else if HOUR == 9 then 0.33
    else if HOUR == 10 then 0.29
    else if HOUR == 11 then 0.28
    else if HOUR == 12 then 0.25
    else if HOUR == 13 then 0.22
    else if HOUR == 14 then 0.12
    else if HOUR == 15 then 0.08
    else if HOUR == 16 then 0.18
    else if HOUR == 17 then 0.47
    else if HOUR == 18 then 0.07
    else if HOUR == 19 then 0.15
    else if HOUR == 20 then 0.15
    else if HOUR == 21 then 0.12
    else if HOUR == 22 then 0.11
    else 0.1;
def m2 =
    if HOUR == 0 then 0.03
    else if HOUR == 1 then -0.02
    else if HOUR == 2 then -0.02
    else if HOUR == 3 then 0.05
    else if HOUR == 4 then -0.02
    else if HOUR == 5 then 0.01
    else if HOUR == 6 then -0.02
    else if HOUR == 7 then 0.0
    else if HOUR == 8 then 0.06
    else if HOUR == 9 then -0.02
    else if HOUR == 10 then -0.02
    else if HOUR == 11 then 0.04
    else if HOUR == 12 then 0.05
    else if HOUR == 13 then 0.01
    else if HOUR == 14 then 0.0
    else if HOUR == 15 then 0.0
    else if HOUR == 16 then 0.03
    else if HOUR == 17 then 0.47
    else if HOUR == 18 then -0.02
    else if HOUR == 19 then 0.01
    else if HOUR == 20 then -0.01
    else if HOUR == 21 then -0.035
    else if HOUR == 22 then 0.01
    else 0.03;

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);
Just came across this thread... though it has not been updated in a while I am assuming the coefficients are still accurate. Accurate as in do not need an update.

I am going to pick up the ES and NQ studies. I primarily use ES and NQ to trade SPY and QQQ. My current set up uses the Consensus Confirmation Candles and the Hull turning points upper and lower study (Awesome work by the way) . I am using these on the 10m as well as a 4181t chart. Between the 2 of these setups, they give a reasonably good guidance.

Definitely adding this to my watch board. Will update with what I see.... My analysis is not very scientific as some others on this thread and this forum but I will provide what every inputs I can.

Thanks once again for your hard work and contributions

/Baba
 
Just came across this thread... though it has not been updated in a while I am assuming the coefficients are still accurate. Accurate as in do not need an update.

I am going to pick up the ES and NQ studies. I primarily use ES and NQ to trade SPY and QQQ. My current set up uses the Consensus Confirmation Candles and the Hull turning points upper and lower study (Awesome work by the way) . I am using these on the 10m as well as a 4181t chart. Between the 2 of these setups, they give a reasonably good guidance.

Definitely adding this to my watch board. Will update with what I see.... My analysis is not very scientific as some others on this thread and this forum but I will provide what every inputs I can.

Thanks once again for your hard work and contributions

/Baba
I'll be happy to run you new versions of ES and NQ later today. I honestly have no idea how the coefficients have changed over time. I just do updates as people request them.

Thanks for your kind words, and look forward to your updates with use.

mashume
 
new indicator coefficients by request. 2022-02-20 ES and NQ

ES

Code:
#########################################################
#
#   Next Hour ES Trading Range
#     Algorithmic Prediction
#
#   Values Derived on Data from
#          2021-12-10 to
#          2022-02-20
#
#   @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 -1.750000
    else if HOUR == 1 then -3.750000
    else if HOUR == 2 then -5.500000
    else if HOUR == 3 then -4.750000
    else if HOUR == 4 then -3.500000
    else if HOUR == 5 then -4.250000
    else if HOUR == 6 then -4.750000
    else if HOUR == 7 then -6.500000
    else if HOUR == 8 then -10.062500
    else if HOUR == 9 then -14.500000
    else if HOUR == 10 then -10.500000
    else if HOUR == 11 then -7.312500
    else if HOUR == 12 then -7.250000
    else if HOUR == 13 then -8.250000
    else if HOUR == 14 then -11.500000
    else if HOUR == 15 then -9.875000
    else if HOUR == 16 then -3.250000
    else if HOUR == 17 then -0.875000
    else if HOUR == 18 then -5.250000
    else if HOUR == 19 then -4.250000
    else if HOUR == 20 then -4.500000
    else if HOUR == 21 then -2.250000
    else if HOUR == 22 then -1.250000
    else -2.312500;
def q3 =
    if HOUR == 0 then 3.750000
    else if HOUR == 1 then 4.500000
    else if HOUR == 2 then 5.562500
    else if HOUR == 3 then 6.312500
    else if HOUR == 4 then 5.250000
    else if HOUR == 5 then 3.750000
    else if HOUR == 6 then 4.250000
    else if HOUR == 7 then 4.250000
    else if HOUR == 8 then 5.250000
    else if HOUR == 9 then 7.250000
    else if HOUR == 10 then 9.500000
    else if HOUR == 11 then 7.500000
    else if HOUR == 12 then 6.750000
    else if HOUR == 13 then 8.500000
    else if HOUR == 14 then 9.875000
    else if HOUR == 15 then 10.750000
    else if HOUR == 16 then 5.500000
    else if HOUR == 17 then 3.875000
    else if HOUR == 18 then 3.250000
    else if HOUR == 19 then 3.000000
    else if HOUR == 20 then 2.812500
    else if HOUR == 21 then 3.000000
    else if HOUR == 22 then 3.125000
    else 2.750000;
def m2 =
    if HOUR == 0 then 0.750000
    else if HOUR == 1 then 0.000000
    else if HOUR == 2 then 0.500000
    else if HOUR == 3 then 0.875000
    else if HOUR == 4 then 1.250000
    else if HOUR == 5 then -0.250000
    else if HOUR == 6 then 0.125000
    else if HOUR == 7 then -1.250000
    else if HOUR == 8 then -1.125000
    else if HOUR == 9 then -3.250000
    else if HOUR == 10 then -1.125000
    else if HOUR == 11 then 0.500000
    else if HOUR == 12 then 1.000000
    else if HOUR == 13 then 2.125000
    else if HOUR == 14 then 2.000000
    else if HOUR == 15 then 1.000000
    else if HOUR == 16 then 1.000000
    else if HOUR == 17 then 1.500000
    else if HOUR == 18 then -1.375000
    else if HOUR == 19 then -0.500000
    else if HOUR == 20 then -0.750000
    else if HOUR == 21 then 0.500000
    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);

NQ

Code:
#########################################################
#
#   Next Hour NQ Trading Range
#     Algorithmic Prediction
#
#   Values Derived on Data from
#          2021-12-10 to
#          2022-02-20
#
#   @mashume at usethinkscript.com
#
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#
#  This Version /NQ 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 -7.062500
    else if HOUR == 1 then -14.000000
    else if HOUR == 2 then -28.000000
    else if HOUR == 3 then -21.500000
    else if HOUR == 4 then -14.125000
    else if HOUR == 5 then -19.250000
    else if HOUR == 6 then -22.500000
    else if HOUR == 7 then -33.500000
    else if HOUR == 8 then -52.062500
    else if HOUR == 9 then -77.687500
    else if HOUR == 10 then -66.812500
    else if HOUR == 11 then -39.812500
    else if HOUR == 12 then -34.562500
    else if HOUR == 13 then -33.937500
    else if HOUR == 14 then -47.750000
    else if HOUR == 15 then -42.000000
    else if HOUR == 16 then -15.750000
    else if HOUR == 17 then -21.625000
    else if HOUR == 18 then -23.000000
    else if HOUR == 19 then -16.750000
    else if HOUR == 20 then -19.937500
    else if HOUR == 21 then -10.312500
    else if HOUR == 22 then -7.875000
    else -9.562500;
def q3 =
    if HOUR == 0 then 18.500000
    else if HOUR == 1 then 20.062500
    else if HOUR == 2 then 24.812500
    else if HOUR == 3 then 29.125000
    else if HOUR == 4 then 23.062500
    else if HOUR == 5 then 16.000000
    else if HOUR == 6 then 21.312500
    else if HOUR == 7 then 19.000000
    else if HOUR == 8 then 28.312500
    else if HOUR == 9 then 38.937500
    else if HOUR == 10 then 50.000000
    else if HOUR == 11 then 31.375000
    else if HOUR == 12 then 27.562500
    else if HOUR == 13 then 37.250000
    else if HOUR == 14 then 48.250000
    else if HOUR == 15 then 40.250000
    else if HOUR == 16 then 26.000000
    else if HOUR == 17 then 40.625000
    else if HOUR == 18 then 14.375000
    else if HOUR == 19 then 13.250000
    else if HOUR == 20 then 12.562500
    else if HOUR == 21 then 11.312500
    else if HOUR == 22 then 13.250000
    else 11.312500;
def m2 =
    if HOUR == 0 then 3.500000
    else if HOUR == 1 then 0.875000
    else if HOUR == 2 then -1.625000
    else if HOUR == 3 then 4.625000
    else if HOUR == 4 then 7.250000
    else if HOUR == 5 then -3.250000
    else if HOUR == 6 then -0.250000
    else if HOUR == 7 then -4.750000
    else if HOUR == 8 then -9.500000
    else if HOUR == 9 then -16.375000
    else if HOUR == 10 then -7.875000
    else if HOUR == 11 then -2.000000
    else if HOUR == 12 then 2.750000
    else if HOUR == 13 then 4.625000
    else if HOUR == 14 then 7.500000
    else if HOUR == 15 then 3.500000
    else if HOUR == 16 then 3.000000
    else if HOUR == 17 then 27.625000
    else if HOUR == 18 then -7.250000
    else if HOUR == 19 then -1.000000
    else if HOUR == 20 then -2.250000
    else if HOUR == 21 then 1.250000
    else if HOUR == 22 then 1.750000
    else 1.500000;

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);
 
new indicator coefficients by request. 2022-02-20 ES and NQ

ES

Code:
#########################################################
#
#   Next Hour ES Trading Range
#     Algorithmic Prediction
#
#   Values Derived on Data from
#          2021-12-10 to
#          2022-02-20
#
#   @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 -1.750000
    else if HOUR == 1 then -3.750000
    else if HOUR == 2 then -5.500000
    else if HOUR == 3 then -4.750000
    else if HOUR == 4 then -3.500000
    else if HOUR == 5 then -4.250000
    else if HOUR == 6 then -4.750000
    else if HOUR == 7 then -6.500000
    else if HOUR == 8 then -10.062500
    else if HOUR == 9 then -14.500000
    else if HOUR == 10 then -10.500000
    else if HOUR == 11 then -7.312500
    else if HOUR == 12 then -7.250000
    else if HOUR == 13 then -8.250000
    else if HOUR == 14 then -11.500000
    else if HOUR == 15 then -9.875000
    else if HOUR == 16 then -3.250000
    else if HOUR == 17 then -0.875000
    else if HOUR == 18 then -5.250000
    else if HOUR == 19 then -4.250000
    else if HOUR == 20 then -4.500000
    else if HOUR == 21 then -2.250000
    else if HOUR == 22 then -1.250000
    else -2.312500;
def q3 =
    if HOUR == 0 then 3.750000
    else if HOUR == 1 then 4.500000
    else if HOUR == 2 then 5.562500
    else if HOUR == 3 then 6.312500
    else if HOUR == 4 then 5.250000
    else if HOUR == 5 then 3.750000
    else if HOUR == 6 then 4.250000
    else if HOUR == 7 then 4.250000
    else if HOUR == 8 then 5.250000
    else if HOUR == 9 then 7.250000
    else if HOUR == 10 then 9.500000
    else if HOUR == 11 then 7.500000
    else if HOUR == 12 then 6.750000
    else if HOUR == 13 then 8.500000
    else if HOUR == 14 then 9.875000
    else if HOUR == 15 then 10.750000
    else if HOUR == 16 then 5.500000
    else if HOUR == 17 then 3.875000
    else if HOUR == 18 then 3.250000
    else if HOUR == 19 then 3.000000
    else if HOUR == 20 then 2.812500
    else if HOUR == 21 then 3.000000
    else if HOUR == 22 then 3.125000
    else 2.750000;
def m2 =
    if HOUR == 0 then 0.750000
    else if HOUR == 1 then 0.000000
    else if HOUR == 2 then 0.500000
    else if HOUR == 3 then 0.875000
    else if HOUR == 4 then 1.250000
    else if HOUR == 5 then -0.250000
    else if HOUR == 6 then 0.125000
    else if HOUR == 7 then -1.250000
    else if HOUR == 8 then -1.125000
    else if HOUR == 9 then -3.250000
    else if HOUR == 10 then -1.125000
    else if HOUR == 11 then 0.500000
    else if HOUR == 12 then 1.000000
    else if HOUR == 13 then 2.125000
    else if HOUR == 14 then 2.000000
    else if HOUR == 15 then 1.000000
    else if HOUR == 16 then 1.000000
    else if HOUR == 17 then 1.500000
    else if HOUR == 18 then -1.375000
    else if HOUR == 19 then -0.500000
    else if HOUR == 20 then -0.750000
    else if HOUR == 21 then 0.500000
    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);

NQ

Code:
#########################################################
#
#   Next Hour NQ Trading Range
#     Algorithmic Prediction
#
#   Values Derived on Data from
#          2021-12-10 to
#          2022-02-20
#
#   @mashume at usethinkscript.com
#
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#
#  This Version /NQ 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 -7.062500
    else if HOUR == 1 then -14.000000
    else if HOUR == 2 then -28.000000
    else if HOUR == 3 then -21.500000
    else if HOUR == 4 then -14.125000
    else if HOUR == 5 then -19.250000
    else if HOUR == 6 then -22.500000
    else if HOUR == 7 then -33.500000
    else if HOUR == 8 then -52.062500
    else if HOUR == 9 then -77.687500
    else if HOUR == 10 then -66.812500
    else if HOUR == 11 then -39.812500
    else if HOUR == 12 then -34.562500
    else if HOUR == 13 then -33.937500
    else if HOUR == 14 then -47.750000
    else if HOUR == 15 then -42.000000
    else if HOUR == 16 then -15.750000
    else if HOUR == 17 then -21.625000
    else if HOUR == 18 then -23.000000
    else if HOUR == 19 then -16.750000
    else if HOUR == 20 then -19.937500
    else if HOUR == 21 then -10.312500
    else if HOUR == 22 then -7.875000
    else -9.562500;
def q3 =
    if HOUR == 0 then 18.500000
    else if HOUR == 1 then 20.062500
    else if HOUR == 2 then 24.812500
    else if HOUR == 3 then 29.125000
    else if HOUR == 4 then 23.062500
    else if HOUR == 5 then 16.000000
    else if HOUR == 6 then 21.312500
    else if HOUR == 7 then 19.000000
    else if HOUR == 8 then 28.312500
    else if HOUR == 9 then 38.937500
    else if HOUR == 10 then 50.000000
    else if HOUR == 11 then 31.375000
    else if HOUR == 12 then 27.562500
    else if HOUR == 13 then 37.250000
    else if HOUR == 14 then 48.250000
    else if HOUR == 15 then 40.250000
    else if HOUR == 16 then 26.000000
    else if HOUR == 17 then 40.625000
    else if HOUR == 18 then 14.375000
    else if HOUR == 19 then 13.250000
    else if HOUR == 20 then 12.562500
    else if HOUR == 21 then 11.312500
    else if HOUR == 22 then 13.250000
    else 11.312500;
def m2 =
    if HOUR == 0 then 3.500000
    else if HOUR == 1 then 0.875000
    else if HOUR == 2 then -1.625000
    else if HOUR == 3 then 4.625000
    else if HOUR == 4 then 7.250000
    else if HOUR == 5 then -3.250000
    else if HOUR == 6 then -0.250000
    else if HOUR == 7 then -4.750000
    else if HOUR == 8 then -9.500000
    else if HOUR == 9 then -16.375000
    else if HOUR == 10 then -7.875000
    else if HOUR == 11 then -2.000000
    else if HOUR == 12 then 2.750000
    else if HOUR == 13 then 4.625000
    else if HOUR == 14 then 7.500000
    else if HOUR == 15 then 3.500000
    else if HOUR == 16 then 3.000000
    else if HOUR == 17 then 27.625000
    else if HOUR == 18 then -7.250000
    else if HOUR == 19 then -1.000000
    else if HOUR == 20 then -2.250000
    else if HOUR == 21 then 1.250000
    else if HOUR == 22 then 1.750000
    else 1.500000;

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);
I tried loading this into Think or Swim but it gives the error Addlabel is not allowed in this context. I have no idea why that error is occurring so I thought I would ask.

Thank you

Sincerely,
HP
 
I tried loading this into Think or Swim but it gives the error Addlabel is not allowed in this context. I have no idea why that error is occurring so I thought I would ask.

Thank you

Sincerely,
HP
Did you add it as a study? If you added it as a strategy or as a scan, it may throw errors. It's not intended as either of those things.

-mashume
 
Couldn't get it to work after all. I was able to add the script alright but it was confusing as all thunder. The white arrows showed at the bottom of the trench where I guess it indicated you should take a profit but, it didn't coorelate with the bar chart. In fact it was opposite the bar chart all together. (everyone says...it was opposite the bar chart all together)

Then the red arrows didn't show. I even adjusted the zero line to 10 from .01 like someone did earlier and still no red arrows and the white arrows still indicated selling at the bottom of the price. (regardless of the time setting).

Finally, the Doctor had put some grey labels in his script and when I added that instead of the TP script, I got a grey label with a week and day number but nothing else. No lines, arrows or bars. So, I ended up taking that out and trying to add it to the original script and that didn't run either. :-(
 
Couldn't get it to work after all. I was able to add the script alright but it was confusing as all thunder. The white arrows showed at the bottom of the trench where I guess it indicated you should take a profit but, it didn't coorelate with the bar chart. In fact it was opposite the bar chart all together. (everyone says...it was opposite the bar chart all together)

Then the red arrows didn't show. I even adjusted the zero line to 10 from .01 like someone did earlier and still no red arrows and the white arrows still indicated selling at the bottom of the price. (regardless of the time setting).

Finally, the Doctor had put some grey labels in his script and when I added that instead of the TP script, I got a grey label with a week and day number but nothing else. No lines, arrows or bars. So, I ended up taking that out and trying to add it to the original script and that didn't run either. :-(
I'm not sure what indicator or study you're referring to... This one has no arrows and no zero line. Please check that you're post of in the correct thread. 😁
 
@mashume can you please post /RTY
Code:
#########################################################
#
#   Next Hour RTY Trading Range
#     Algorithmic Prediction
#
#   Values Derived on Data from
#          2021-12-30 to
#          2022-03-11
#
#   @mashume at usethinkscript.com
#
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#
#  This Version /RTY 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 -1.300049
    else if HOUR == 1 then -2.600098
    else if HOUR == 2 then -4.825043
    else if HOUR == 3 then -3.000000
    else if HOUR == 4 then -3.200195
    else if HOUR == 5 then -3.699951
    else if HOUR == 6 then -2.500000
    else if HOUR == 7 then -4.400024
    else if HOUR == 8 then -4.925018
    else if HOUR == 9 then -12.000000
    else if HOUR == 10 then -9.400146
    else if HOUR == 11 then -6.200073
    else if HOUR == 12 then -6.624878
    else if HOUR == 13 then -7.099854
    else if HOUR == 14 then -8.799805
    else if HOUR == 15 then -7.700104
    else if HOUR == 16 then -2.799927
    else if HOUR == 17 then 0.000000
    else if HOUR == 18 then -4.099976
    else if HOUR == 19 then -3.800049
    else if HOUR == 20 then -3.300049
    else if HOUR == 21 then -2.000000
    else if HOUR == 22 then -1.400024
    else -1.599976;
def q3 =
    if HOUR == 0 then 2.600098
    else if HOUR == 1 then 3.400024
    else if HOUR == 2 then 5.500000
    else if HOUR == 3 then 5.174988
    else if HOUR == 4 then 4.199951
    else if HOUR == 5 then 2.200073
    else if HOUR == 6 then 3.900024
    else if HOUR == 7 then 4.099976
    else if HOUR == 8 then 6.724976
    else if HOUR == 9 then 10.425110
    else if HOUR == 10 then 8.199982
    else if HOUR == 11 then 6.625061
    else if HOUR == 12 then 5.300049
    else if HOUR == 13 then 6.000000
    else if HOUR == 14 then 6.299866
    else if HOUR == 15 then 5.049988
    else if HOUR == 16 then 3.500000
    else if HOUR == 17 then 0.000000
    else if HOUR == 18 then 2.125061
    else if HOUR == 19 then 2.049927
    else if HOUR == 20 then 2.199951
    else if HOUR == 21 then 1.925110
    else if HOUR == 22 then 2.500000
    else 2.200073;
def m2 =
    if HOUR == 0 then 0.500000
    else if HOUR == 1 then -0.300049
    else if HOUR == 2 then 0.450073
    else if HOUR == 3 then 1.100098
    else if HOUR == 4 then 0.350037
    else if HOUR == 5 then -0.800049
    else if HOUR == 6 then 0.450073
    else if HOUR == 7 then 0.100098
    else if HOUR == 8 then 0.749939
    else if HOUR == 9 then -1.549988
    else if HOUR == 10 then -0.799988
    else if HOUR == 11 then 0.500000
    else if HOUR == 12 then -0.549927
    else if HOUR == 13 then -0.349976
    else if HOUR == 14 then -1.500000
    else if HOUR == 15 then -1.199951
    else if HOUR == 16 then 0.100098
    else if HOUR == 17 then 0.000000
    else if HOUR == 18 then -1.199951
    else if HOUR == 19 then -0.900146
    else if HOUR == 20 then -0.500000
    else if HOUR == 21 then 0.199951
    else if HOUR == 22 then 0.900024
    else 0.300049;

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);
 
I think this is a wonderful piece of math/stats/probability put into one. Unfortunately (for me), it doesn't do what I was looking for. To explain a little further...

So, my objective was to look at 5/10 min charts and have this hourly projection study to help assess where the market might head in the next hour or so. This, at least for me, was an additional indicator that would help me stay in the trade or exit based on other factors along with this indicator. I was unable to spot reversals from this indicator and it did not do what I was expecting/hoping it might. Now, it is perfectly possible that I didn't know what to do or look for or I was using the indicator for the wrong purpose.

There is also the distinct possibility that the moves and reversals have been fairly violent in the recent past given the global market conditions. I am not giving up on this as yet but I am putting it on the back burner and will take another look in a couple of months once the markets return to saner times...

Thanks @mashume for the excellent work that you have done and continue to do. You are pillar of this community..... may god bless you with the most and more....


/Baba
 
I think the unprecedented events in eastern Europe have certainly introduced additional volatility to the markets. It might actually be interesting to run a copy of the study with data from only the last 20 ish days and see how different the coefficients are... hmmm...

-mashume
 
I think the unprecedented events in eastern Europe have certainly introduced additional volatility to the markets. It might actually be interesting to run a copy of the study with data from only the last 20 ish days and see how different the coefficients are... hmmm...

-mashume
So on the notion of some visualization of the change in volatility, I present the following. They are normalized against the mean price for recent data ranges, and the central price (datewise middle of the range) for the older set.

es range:
qxdsh0u.png


es median change:
w30oZSs.png



cl range:
2BfN2CK.png


cl median change:
xFClehe.png


There is a very clear change in the ranges and expected movements for both of these. It is interesting, but I'm a bit pressed for time.

-mashume
 
So on the notion of some visualization of the change in volatility, I present the following. They are normalized against the mean price for recent data ranges, and the central price (datewise middle of the range) for the older set.

es range:
qxdsh0u.png


es median change:
w30oZSs.png



cl range:
2BfN2CK.png


cl median change:
xFClehe.png


There is a very clear change in the ranges and expected movements for both of these. It is interesting, but I'm a bit pressed for time.

-mashume
I believe that was to be expected but thanks for taking the time to run these simulations.

The market is not going anywhere and neither are we (hopefully). Will come back to this once the markets have stabilized a bit...


/Baba
 
So on the notion of some visualization of the change in volatility, I present the following. They are normalized against the mean price for recent data ranges, and the central price (datewise middle of the range) for the older set.

es range:
qxdsh0u.png


es median change:
w30oZSs.png



cl range:
2BfN2CK.png


cl median change:
xFClehe.png


There is a very clear change in the ranges and expected movements for both of these. It is interesting, but I'm a bit pressed for time.

-mashume
Thank you @mashume for your hard work and sharing your study. I am wondering if such code can be applicable to specific tickers such as AFRM, RBLX or SNAP? Thanks again for your contribution.
 
Thank you @mashume for your hard work and sharing your study. I am wondering if such code can be applicable to specific tickers such as AFRM, RBLX or SNAP? Thanks again for your contribution.
I can throw them together for you, assuming my API calls are still working (they fail from time to time until the upstream package manager fixes whatever got changed).

EDIT
I ran the script to generate these. I have not imported them and have no idea how well they will work. I have done these before for securities that don't trade round-the-clock (as futures do), but don't know how well they ended up working.

-mashume
 
Last edited:

AFRM

Code:
#########################################################
#
#   Next Hour AFRM Trading Range
#     Algorithmic Prediction
#
#   Values Derived on Data from
#          2022-03-24 to
#          2022-06-17
#
#   @mashume at usethinkscript.com
#
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#
#  This Version /AFRM 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 0.000000
    else if HOUR == 1 then 0.000000
    else if HOUR == 2 then 0.000000
    else if HOUR == 3 then 0.000000
    else if HOUR == 4 then -0.220000
    else if HOUR == 5 then -0.240000
    else if HOUR == 6 then -0.290000
    else if HOUR == 7 then -0.210000
    else if HOUR == 8 then -0.650000
    else if HOUR == 9 then -1.016000
    else if HOUR == 10 then -0.624000
    else if HOUR == 11 then -0.460000
    else if HOUR == 12 then -0.360000
    else if HOUR == 13 then -0.310000
    else if HOUR == 14 then -0.286000
    else if HOUR == 15 then -0.186000
    else if HOUR == 16 then -0.070000
    else if HOUR == 17 then -0.070000
    else if HOUR == 18 then -0.060000
    else if HOUR == 19 then -0.355000
    else if HOUR == 20 then 0.000000
    else if HOUR == 21 then 0.000000
    else if HOUR == 22 then 0.000000
    else 0.000000;
def q3 =
    if HOUR == 0 then 0.000000
    else if HOUR == 1 then 0.000000
    else if HOUR == 2 then 0.000000
    else if HOUR == 3 then 0.000000
    else if HOUR == 4 then 0.120000
    else if HOUR == 5 then 0.120000
    else if HOUR == 6 then 0.077500
    else if HOUR == 7 then 0.110000
    else if HOUR == 8 then 0.456250
    else if HOUR == 9 then 0.630650
    else if HOUR == 10 then 0.299999
    else if HOUR == 11 then 0.289999
    else if HOUR == 12 then 0.302000
    else if HOUR == 13 then 0.356228
    else if HOUR == 14 then 0.357752
    else if HOUR == 15 then 0.260000
    else if HOUR == 16 then 0.108500
    else if HOUR == 17 then 0.100000
    else if HOUR == 18 then 0.120000
    else if HOUR == 19 then 0.320000
    else if HOUR == 20 then 0.000000
    else if HOUR == 21 then 0.000000
    else if HOUR == 22 then 0.000000
    else 0.000000;
def m2 =
    if HOUR == 0 then 0.000000
    else if HOUR == 1 then 0.000000
    else if HOUR == 2 then 0.000000
    else if HOUR == 3 then 0.000000
    else if HOUR == 4 then -0.040000
    else if HOUR == 5 then -0.040000
    else if HOUR == 6 then -0.105000
    else if HOUR == 7 then -0.028000
    else if HOUR == 8 then -0.050000
    else if HOUR == 9 then -0.263000
    else if HOUR == 10 then -0.172000
    else if HOUR == 11 then -0.050000
    else if HOUR == 12 then -0.029000
    else if HOUR == 13 then -0.015000
    else if HOUR == 14 then -0.009000
    else if HOUR == 15 then 0.040000
    else if HOUR == 16 then 0.020000
    else if HOUR == 17 then 0.010000
    else if HOUR == 18 then 0.030000
    else if HOUR == 19 then -0.010000
    else if HOUR == 20 then 0.000000
    else if HOUR == 21 then 0.000000
    else if HOUR == 22 then 0.000000
    else 0.000000;

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

RBLX

Code:
#########################################################
#
#   Next Hour RBLX Trading Range
#     Algorithmic Prediction
#
#   Values Derived on Data from
#          2022-03-24 to
#          2022-06-17
#
#   @mashume at usethinkscript.com
#
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#
#  This Version /RBLX 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 0.000000
    else if HOUR == 1 then 0.000000
    else if HOUR == 2 then 0.000000
    else if HOUR == 3 then 0.000000
    else if HOUR == 4 then -0.150000
    else if HOUR == 5 then -0.120000
    else if HOUR == 6 then -0.180000
    else if HOUR == 7 then -0.190000
    else if HOUR == 8 then -0.880000
    else if HOUR == 9 then -0.900000
    else if HOUR == 10 then -0.608000
    else if HOUR == 11 then -0.440000
    else if HOUR == 12 then -0.301000
    else if HOUR == 13 then -0.269000
    else if HOUR == 14 then -0.260000
    else if HOUR == 15 then -0.201000
    else if HOUR == 16 then -0.043000
    else if HOUR == 17 then -0.050000
    else if HOUR == 18 then -0.060000
    else if HOUR == 19 then -0.330000
    else if HOUR == 20 then 0.000000
    else if HOUR == 21 then 0.000000
    else if HOUR == 22 then 0.000000
    else 0.000000;
def q3 =
    if HOUR == 0 then 0.000000
    else if HOUR == 1 then 0.000000
    else if HOUR == 2 then 0.000000
    else if HOUR == 3 then 0.000000
    else if HOUR == 4 then 0.110000
    else if HOUR == 5 then 0.080000
    else if HOUR == 6 then 0.125000
    else if HOUR == 7 then 0.130000
    else if HOUR == 8 then 0.440300
    else if HOUR == 9 then 0.732500
    else if HOUR == 10 then 0.392451
    else if HOUR == 11 then 0.310301
    else if HOUR == 12 then 0.289999
    else if HOUR == 13 then 0.315474
    else if HOUR == 14 then 0.255049
    else if HOUR == 15 then 0.190401
    else if HOUR == 16 then 0.070000
    else if HOUR == 17 then 0.070000
    else if HOUR == 18 then 0.070000
    else if HOUR == 19 then 0.450000
    else if HOUR == 20 then 0.000000
    else if HOUR == 21 then 0.000000
    else if HOUR == 22 then 0.000000
    else 0.000000;
def m2 =
    if HOUR == 0 then 0.000000
    else if HOUR == 1 then 0.000000
    else if HOUR == 2 then 0.000000
    else if HOUR == 3 then 0.000000
    else if HOUR == 4 then -0.040000
    else if HOUR == 5 then -0.010000
    else if HOUR == 6 then -0.030000
    else if HOUR == 7 then -0.030000
    else if HOUR == 8 then -0.160000
    else if HOUR == 9 then -0.179000
    else if HOUR == 10 then -0.129000
    else if HOUR == 11 then -0.040000
    else if HOUR == 12 then -0.030000
    else if HOUR == 13 then 0.029000
    else if HOUR == 14 then -0.037000
    else if HOUR == 15 then 0.000000
    else if HOUR == 16 then 0.010000
    else if HOUR == 17 then 0.010000
    else if HOUR == 18 then 0.000000
    else if HOUR == 19 then 0.095000
    else if HOUR == 20 then 0.000000
    else if HOUR == 21 then 0.000000
    else if HOUR == 22 then 0.000000
    else 0.000000;

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

SNAP

Code:
#########################################################
#
#   Next Hour SNAP Trading Range
#     Algorithmic Prediction
#
#   Values Derived on Data from
#          2022-03-24 to
#          2022-06-17
#
#   @mashume at usethinkscript.com
#
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#
#  This Version /SNAP 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 0.000000
    else if HOUR == 1 then 0.000000
    else if HOUR == 2 then 0.000000
    else if HOUR == 3 then 0.000000
    else if HOUR == 4 then -0.150000
    else if HOUR == 5 then -0.120000
    else if HOUR == 6 then -0.120000
    else if HOUR == 7 then -0.140000
    else if HOUR == 8 then -0.410000
    else if HOUR == 9 then -0.526000
    else if HOUR == 10 then -0.335000
    else if HOUR == 11 then -0.245000
    else if HOUR == 12 then -0.205000
    else if HOUR == 13 then -0.180000
    else if HOUR == 14 then -0.195000
    else if HOUR == 15 then -0.120000
    else if HOUR == 16 then -0.040000
    else if HOUR == 17 then -0.040000
    else if HOUR == 18 then -0.040000
    else if HOUR == 19 then -0.150000
    else if HOUR == 20 then 0.000000
    else if HOUR == 21 then 0.000000
    else if HOUR == 22 then 0.000000
    else 0.000000;
def q3 =
    if HOUR == 0 then 0.000000
    else if HOUR == 1 then 0.000000
    else if HOUR == 2 then 0.000000
    else if HOUR == 3 then 0.000000
    else if HOUR == 4 then 0.060000
    else if HOUR == 5 then 0.080000
    else if HOUR == 6 then 0.090000
    else if HOUR == 7 then 0.080000
    else if HOUR == 8 then 0.235000
    else if HOUR == 9 then 0.320050
    else if HOUR == 10 then 0.205001
    else if HOUR == 11 then 0.192200
    else if HOUR == 12 then 0.154850
    else if HOUR == 13 then 0.155000
    else if HOUR == 14 then 0.145000
    else if HOUR == 15 then 0.135000
    else if HOUR == 16 then 0.050000
    else if HOUR == 17 then 0.041700
    else if HOUR == 18 then 0.040000
    else if HOUR == 19 then 0.260000
    else if HOUR == 20 then 0.000000
    else if HOUR == 21 then 0.000000
    else if HOUR == 22 then 0.000000
    else 0.000000;
def m2 =
    if HOUR == 0 then 0.000000
    else if HOUR == 1 then 0.000000
    else if HOUR == 2 then 0.000000
    else if HOUR == 3 then 0.000000
    else if HOUR == 4 then -0.030000
    else if HOUR == 5 then -0.020000
    else if HOUR == 6 then -0.010000
    else if HOUR == 7 then -0.010000
    else if HOUR == 8 then -0.050000
    else if HOUR == 9 then -0.133000
    else if HOUR == 10 then -0.050000
    else if HOUR == 11 then -0.020000
    else if HOUR == 12 then -0.030000
    else if HOUR == 13 then -0.011000
    else if HOUR == 14 then -0.040000
    else if HOUR == 15 then 0.006000
    else if HOUR == 16 then 0.000000
    else if HOUR == 17 then 0.000000
    else if HOUR == 18 then 0.000000
    else if HOUR == 19 then 0.060000
    else if HOUR == 20 then 0.000000
    else if HOUR == 21 then 0.000000
    else if HOUR == 22 then 0.000000
    else 0.000000;

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);
 
@mashume hi there, I was wondering if you thought the es/nq are still valid with recent market moves?
Thanks for your help and ongoing support. If I'm asking too much, just tell me, thanks again
 

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
242 Online
Create Post

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