MES and ES, NQ and MNQYou ask, and tell me which instrument you'd like updated and I'll post the code here.
-mashume
MES and ES, NQ and MNQYou ask, and tell me which instrument you'd like updated and I'll post the code here.
-mashume
Thank you @mashume for updating the /ES. I use your study on my 15 min /ES chart and find it very helpful. If you have the time to do so, could you update the SPX study also? For my trading style, I always watch the 15min, 30 min, and 60 min SPX charts. (when trading the /ES).
#########################################################
#
#   Next Hour SPX Trading Range
#     Algorithmic Prediction
#
#   Values Derived on Data from
#          2023-03-06 to
#          2023-05-30
#
#   mashume at usethinkscript.com
#
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#
#  This Version SPX 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.0
    else if HOUR == 1 then 0.0
    else if HOUR == 2 then 0.0
    else if HOUR == 3 then 0.0
    else if HOUR == 4 then 0.0
    else if HOUR == 5 then 0.0
    else if HOUR == 6 then 0.0
    else if HOUR == 7 then 0.0
    else if HOUR == 8 then 0.0
    else if HOUR == 9 then -10.152
    else if HOUR == 10 then -6.15
    else if HOUR == 11 then -6.373
    else if HOUR == 12 then -4.853
    else if HOUR == 13 then -6.06
    else if HOUR == 14 then -4.15
    else if HOUR == 15 then -6.773
    else if HOUR == 16 then -14.0
    else if HOUR == 17 then -17.06
    else if HOUR == 18 then 34.205
    else if HOUR == 19 then 0.0
    else if HOUR == 20 then 0.0
    else if HOUR == 21 then 0.0
    else if HOUR == 22 then 0.0
    else 0.0;
def q3 =
    if HOUR == 0 then 0.0
    else if HOUR == 1 then 0.0
    else if HOUR == 2 then 0.0
    else if HOUR == 3 then 0.0
    else if HOUR == 4 then 0.0
    else if HOUR == 5 then 0.0
    else if HOUR == 6 then 0.0
    else if HOUR == 7 then 0.0
    else if HOUR == 8 then 0.0
    else if HOUR == 9 then 8.165
    else if HOUR == 10 then 6.368
    else if HOUR == 11 then 5.883
    else if HOUR == 12 then 5.823
    else if HOUR == 13 then 6.155
    else if HOUR == 14 then 7.26
    else if HOUR == 15 then 9.282
    else if HOUR == 16 then 16.157
    else if HOUR == 17 then 12.865
    else if HOUR == 18 then 57.875
    else if HOUR == 19 then 0.0
    else if HOUR == 20 then 0.0
    else if HOUR == 21 then 0.0
    else if HOUR == 22 then 0.0
    else 0.0;
def m2 =
    if HOUR == 0 then 0.0
    else if HOUR == 1 then 0.0
    else if HOUR == 2 then 0.0
    else if HOUR == 3 then 0.0
    else if HOUR == 4 then 0.0
    else if HOUR == 5 then 0.0
    else if HOUR == 6 then 0.0
    else if HOUR == 7 then 0.0
    else if HOUR == 8 then 0.0
    else if HOUR == 9 then -1.59
    else if HOUR == 10 then 0.24
    else if HOUR == 11 then -0.04
    else if HOUR == 12 then 1.895
    else if HOUR == 13 then 0.445
    else if HOUR == 14 then 1.91
    else if HOUR == 15 then 2.115
    else if HOUR == 16 then 1.745
    else if HOUR == 17 then -4.52
    else if HOUR == 18 then 46.04
    else if HOUR == 19 then 0.0
    else if HOUR == 20 then 0.0
    else if HOUR == 21 then 0.0
    else if HOUR == 22 then 0.0
    else 0.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);
	/MES will work with the /ES above, and both NQ and MNQ will work with this one:MES and ES, NQ and MNQ
#########################################################
#
#   Next Hour /NQ and maybe /MNQ Trading Range
#     Algorithmic Prediction
#
#   Values Derived on Data from
#          2023-03-21 to
#          2023-05-30
#
#   mashume at usethinkscript.com
#
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#
#  This Version /NQ and maybe /MNQ 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 -5.25
    else if HOUR == 1 then -8.5
    else if HOUR == 2 then -13.812
    else if HOUR == 3 then -14.75
    else if HOUR == 4 then -7.5
    else if HOUR == 5 then -11.75
    else if HOUR == 6 then -9.562
    else if HOUR == 7 then -14.0
    else if HOUR == 8 then -19.25
    else if HOUR == 9 then -39.125
    else if HOUR == 10 then -22.875
    else if HOUR == 11 then -18.625
    else if HOUR == 12 then -9.5
    else if HOUR == 13 then -17.75
    else if HOUR == 14 then -13.75
    else if HOUR == 15 then -11.812
    else if HOUR == 16 then -12.75
    else if HOUR == 17 then 0.0
    else if HOUR == 18 then -3.812
    else if HOUR == 19 then -7.5
    else if HOUR == 20 then -6.5
    else if HOUR == 21 then -5.75
    else if HOUR == 22 then -3.25
    else -4.75;
def q3 =
    if HOUR == 0 then 5.5
    else if HOUR == 1 then 12.5
    else if HOUR == 2 then 12.5
    else if HOUR == 3 then 13.5
    else if HOUR == 4 then 13.0
    else if HOUR == 5 then 8.0
    else if HOUR == 6 then 13.25
    else if HOUR == 7 then 10.25
    else if HOUR == 8 then 23.75
    else if HOUR == 9 then 31.312
    else if HOUR == 10 then 33.25
    else if HOUR == 11 then 23.75
    else if HOUR == 12 then 26.25
    else if HOUR == 13 then 25.625
    else if HOUR == 14 then 30.5
    else if HOUR == 15 then 26.5
    else if HOUR == 16 then 7.0
    else if HOUR == 17 then 0.0
    else if HOUR == 18 then 7.75
    else if HOUR == 19 then 7.75
    else if HOUR == 20 then 7.0
    else if HOUR == 21 then 6.0
    else if HOUR == 22 then 6.25
    else 5.062;
def m2 =
    if HOUR == 0 then -0.75
    else if HOUR == 1 then 1.5
    else if HOUR == 2 then -0.75
    else if HOUR == 3 then -0.75
    else if HOUR == 4 then 2.75
    else if HOUR == 5 then -1.0
    else if HOUR == 6 then 2.75
    else if HOUR == 7 then -3.25
    else if HOUR == 8 then 0.875
    else if HOUR == 9 then -0.75
    else if HOUR == 10 then 4.875
    else if HOUR == 11 then 5.0
    else if HOUR == 12 then 10.5
    else if HOUR == 13 then 5.25
    else if HOUR == 14 then 8.25
    else if HOUR == 15 then 2.75
    else if HOUR == 16 then -5.75
    else if HOUR == 17 then 0.0
    else if HOUR == 18 then 1.75
    else if HOUR == 19 then 0.125
    else if HOUR == 20 then -0.125
    else if HOUR == 21 then 0.25
    else if HOUR == 22 then 1.25
    else -0.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);
	Thank You kind sir!SPX
Code:######################################################### # # Next Hour SPX Trading Range # Algorithmic Prediction # # Values Derived on Data from # 2023-03-06 to # 2023-05-30 # # mashume at usethinkscript.com # #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- # # This Version SPX 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.0 else if HOUR == 1 then 0.0 else if HOUR == 2 then 0.0 else if HOUR == 3 then 0.0 else if HOUR == 4 then 0.0 else if HOUR == 5 then 0.0 else if HOUR == 6 then 0.0 else if HOUR == 7 then 0.0 else if HOUR == 8 then 0.0 else if HOUR == 9 then -10.152 else if HOUR == 10 then -6.15 else if HOUR == 11 then -6.373 else if HOUR == 12 then -4.853 else if HOUR == 13 then -6.06 else if HOUR == 14 then -4.15 else if HOUR == 15 then -6.773 else if HOUR == 16 then -14.0 else if HOUR == 17 then -17.06 else if HOUR == 18 then 34.205 else if HOUR == 19 then 0.0 else if HOUR == 20 then 0.0 else if HOUR == 21 then 0.0 else if HOUR == 22 then 0.0 else 0.0; def q3 = if HOUR == 0 then 0.0 else if HOUR == 1 then 0.0 else if HOUR == 2 then 0.0 else if HOUR == 3 then 0.0 else if HOUR == 4 then 0.0 else if HOUR == 5 then 0.0 else if HOUR == 6 then 0.0 else if HOUR == 7 then 0.0 else if HOUR == 8 then 0.0 else if HOUR == 9 then 8.165 else if HOUR == 10 then 6.368 else if HOUR == 11 then 5.883 else if HOUR == 12 then 5.823 else if HOUR == 13 then 6.155 else if HOUR == 14 then 7.26 else if HOUR == 15 then 9.282 else if HOUR == 16 then 16.157 else if HOUR == 17 then 12.865 else if HOUR == 18 then 57.875 else if HOUR == 19 then 0.0 else if HOUR == 20 then 0.0 else if HOUR == 21 then 0.0 else if HOUR == 22 then 0.0 else 0.0; def m2 = if HOUR == 0 then 0.0 else if HOUR == 1 then 0.0 else if HOUR == 2 then 0.0 else if HOUR == 3 then 0.0 else if HOUR == 4 then 0.0 else if HOUR == 5 then 0.0 else if HOUR == 6 then 0.0 else if HOUR == 7 then 0.0 else if HOUR == 8 then 0.0 else if HOUR == 9 then -1.59 else if HOUR == 10 then 0.24 else if HOUR == 11 then -0.04 else if HOUR == 12 then 1.895 else if HOUR == 13 then 0.445 else if HOUR == 14 then 1.91 else if HOUR == 15 then 2.115 else if HOUR == 16 then 1.745 else if HOUR == 17 then -4.52 else if HOUR == 18 then 46.04 else if HOUR == 19 then 0.0 else if HOUR == 20 then 0.0 else if HOUR == 21 then 0.0 else if HOUR == 22 then 0.0 else 0.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);
#########################################################
#
#   Next Hour /CL Trading Range
#     Algorithmic Prediction
#
#   Values Derived on Data from
#          2023-10-01 to
#          2023-12-08
#
#   mashume at usethinkscript.com
#
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#
#  This Version /CL 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.1
    else if HOUR == 1 then -0.1
    else if HOUR == 2 then -0.16
    else if HOUR == 3 then -0.205
    else if HOUR == 4 then -0.2
    else if HOUR == 5 then -0.25
    else if HOUR == 6 then -0.24
    else if HOUR == 7 then -0.29
    else if HOUR == 8 then -0.43
    else if HOUR == 9 then -0.38
    else if HOUR == 10 then -0.483
    else if HOUR == 11 then -0.355
    else if HOUR == 12 then -0.428
    else if HOUR == 13 then -0.34
    else if HOUR == 14 then -0.11
    else if HOUR == 15 then -0.09
    else if HOUR == 16 then -0.11
    else if HOUR == 17 then 0.0
    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.13
    else if HOUR == 22 then -0.09
    else -0.09;
def q3 =
    if HOUR == 0 then 0.09
    else if HOUR == 1 then 0.14
    else if HOUR == 2 then 0.24
    else if HOUR == 3 then 0.33
    else if HOUR == 4 then 0.31
    else if HOUR == 5 then 0.18
    else if HOUR == 6 then 0.17
    else if HOUR == 7 then 0.29
    else if HOUR == 8 then 0.17
    else if HOUR == 9 then 0.355
    else if HOUR == 10 then 0.3
    else if HOUR == 11 then 0.33
    else if HOUR == 12 then 0.24
    else if HOUR == 13 then 0.2
    else if HOUR == 14 then 0.18
    else if HOUR == 15 then 0.1
    else if HOUR == 16 then 0.13
    else if HOUR == 17 then 0.0
    else if HOUR == 18 then 0.09
    else if HOUR == 19 then 0.14
    else if HOUR == 20 then 0.11
    else if HOUR == 21 then 0.09
    else if HOUR == 22 then 0.09
    else 0.08;
def m2 =
    if HOUR == 0 then 0.0
    else if HOUR == 1 then 0.015
    else if HOUR == 2 then 0.02
    else if HOUR == 3 then 0.12
    else if HOUR == 4 then 0.07
    else if HOUR == 5 then -0.02
    else if HOUR == 6 then -0.02
    else if HOUR == 7 then -0.03
    else if HOUR == 8 then -0.12
    else if HOUR == 9 then -0.03
    else if HOUR == 10 then -0.08
    else if HOUR == 11 then 0.03
    else if HOUR == 12 then -0.065
    else if HOUR == 13 then -0.1
    else if HOUR == 14 then 0.05
    else if HOUR == 15 then 0.0
    else if HOUR == 16 then 0.01
    else if HOUR == 17 then 0.0
    else if HOUR == 18 then 0.0
    else if HOUR == 19 then 0.0
    else if HOUR == 20 then -0.01
    else if HOUR == 21 then -0.02
    else if HOUR == 22 then -0.02
    else -0.01;
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);
	#########################################################
#
#   Next Hour SOXL Trading Range
#     Algorithmic Prediction
#
#   Values Derived on Data from
#          2023-09-21 to
#          2023-12-14
#
#   mashume at usethinkscript.com
#
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#
#  This Version SOXL 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.0
    else if HOUR == 1 then 0.0
    else if HOUR == 2 then 0.0
    else if HOUR == 3 then 0.0
    else if HOUR == 4 then -0.06
    else if HOUR == 5 then -0.045
    else if HOUR == 6 then -0.05
    else if HOUR == 7 then -0.09
    else if HOUR == 8 then -0.212
    else if HOUR == 9 then -0.208
    else if HOUR == 10 then -0.145
    else if HOUR == 11 then -0.132
    else if HOUR == 12 then -0.175
    else if HOUR == 13 then -0.132
    else if HOUR == 14 then -0.1
    else if HOUR == 15 then -0.14
    else if HOUR == 16 then -0.04
    else if HOUR == 17 then -0.03
    else if HOUR == 18 then -0.03
    else if HOUR == 19 then -0.076
    else if HOUR == 20 then 0.0
    else if HOUR == 21 then 0.0
    else if HOUR == 22 then 0.0
    else 0.0;
def q3 =
    if HOUR == 0 then 0.0
    else if HOUR == 1 then 0.0
    else if HOUR == 2 then 0.0
    else if HOUR == 3 then 0.0
    else if HOUR == 4 then 0.081
    else if HOUR == 5 then 0.045
    else if HOUR == 6 then 0.06
    else if HOUR == 7 then 0.11
    else if HOUR == 8 then 0.25
    else if HOUR == 9 then 0.326
    else if HOUR == 10 then 0.239
    else if HOUR == 11 then 0.155
    else if HOUR == 12 then 0.142
    else if HOUR == 13 then 0.135
    else if HOUR == 14 then 0.131
    else if HOUR == 15 then 0.079
    else if HOUR == 16 then 0.02
    else if HOUR == 17 then 0.02
    else if HOUR == 18 then 0.1
    else if HOUR == 19 then 0.23
    else if HOUR == 20 then 0.0
    else if HOUR == 21 then 0.0
    else if HOUR == 22 then 0.0
    else 0.0;
def m2 =
    if HOUR == 0 then 0.0
    else if HOUR == 1 then 0.0
    else if HOUR == 2 then 0.0
    else if HOUR == 3 then 0.0
    else if HOUR == 4 then 0.02
    else if HOUR == 5 then 0.0
    else if HOUR == 6 then 0.01
    else if HOUR == 7 then 0.0
    else if HOUR == 8 then 0.011
    else if HOUR == 9 then 0.05
    else if HOUR == 10 then 0.04
    else if HOUR == 11 then 0.005
    else if HOUR == 12 then 0.0
    else if HOUR == 13 then 0.02
    else if HOUR == 14 then 0.015
    else if HOUR == 15 then -0.03
    else if HOUR == 16 then -0.01
    else if HOUR == 17 then 0.0
    else if HOUR == 18 then 0.02
    else if HOUR == 19 then 0.058
    else if HOUR == 20 then 0.0
    else if HOUR == 21 then 0.0
    else if HOUR == 22 then 0.0
    else 0.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);
	#########################################################
#
#   Next Hour /RTY Trading Range
#     Algorithmic Prediction
#
#   Values Derived on Data from
#          2023-10-08 to
#          2023-12-15
#
#   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 -0.9
    else if HOUR == 1 then -1.4
    else if HOUR == 2 then -1.7
    else if HOUR == 3 then -1.7
    else if HOUR == 4 then -1.65
    else if HOUR == 5 then -1.7
    else if HOUR == 6 then -2.0
    else if HOUR == 7 then -1.5
    else if HOUR == 8 then -4.825
    else if HOUR == 9 then -6.125
    else if HOUR == 10 then -4.1
    else if HOUR == 11 then -4.575
    else if HOUR == 12 then -4.7
    else if HOUR == 13 then -1.625
    else if HOUR == 14 then -2.4
    else if HOUR == 15 then -2.4
    else if HOUR == 16 then -1.3
    else if HOUR == 17 then 0.0
    else if HOUR == 18 then -1.0
    else if HOUR == 19 then -1.05
    else if HOUR == 20 then -0.9
    else if HOUR == 21 then -0.9
    else if HOUR == 22 then -0.8
    else -0.7;
def q3 =
    if HOUR == 0 then 0.8
    else if HOUR == 1 then 1.175
    else if HOUR == 2 then 2.3
    else if HOUR == 3 then 3.4
    else if HOUR == 4 then 2.7
    else if HOUR == 5 then 1.325
    else if HOUR == 6 then 2.0
    else if HOUR == 7 then 2.9
    else if HOUR == 8 then 4.625
    else if HOUR == 9 then 8.225
    else if HOUR == 10 then 5.1
    else if HOUR == 11 then 2.0
    else if HOUR == 12 then 2.7
    else if HOUR == 13 then 2.9
    else if HOUR == 14 then 3.3
    else if HOUR == 15 then 1.4
    else if HOUR == 16 then 1.7
    else if HOUR == 17 then 0.0
    else if HOUR == 18 then 1.4
    else if HOUR == 19 then 1.0
    else if HOUR == 20 then 1.3
    else if HOUR == 21 then 1.075
    else if HOUR == 22 then 0.9
    else 0.6;
def m2 =
    if HOUR == 0 then -0.1
    else if HOUR == 1 then -0.1
    else if HOUR == 2 then 0.4
    else if HOUR == 3 then 0.8
    else if HOUR == 4 then 0.4
    else if HOUR == 5 then 0.0
    else if HOUR == 6 then 0.0
    else if HOUR == 7 then 0.7
    else if HOUR == 8 then -0.1
    else if HOUR == 9 then 0.5
    else if HOUR == 10 then 0.4
    else if HOUR == 11 then -0.75
    else if HOUR == 12 then -0.8
    else if HOUR == 13 then 0.9
    else if HOUR == 14 then 0.4
    else if HOUR == 15 then -0.7
    else if HOUR == 16 then -0.2
    else if HOUR == 17 then 0.0
    else if HOUR == 18 then 0.3
    else if HOUR == 19 then 0.1
    else if HOUR == 20 then 0.2
    else if HOUR == 21 then 0.1
    else if HOUR == 22 then 0.1
    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);
	Thanks!Wow this is awesome just found it. Is there a new post showing updates? I just trade SPY only.
#########################################################
#
#   Next Hour SPY Trading Range
#     Algorithmic Prediction
#
#   Values Derived on Data from
#          2023-11-29 to
#          2024-02-26
#
#   mashume at usethinkscript.com
#
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#
#  This Version SPY 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.0
    else if HOUR == 1 then 0.0
    else if HOUR == 2 then 0.0
    else if HOUR == 3 then 0.0
    else if HOUR == 4 then -0.21
    else if HOUR == 5 then -0.19
    else if HOUR == 6 then -0.17
    else if HOUR == 7 then -0.26
    else if HOUR == 8 then -0.52
    else if HOUR == 9 then -0.546
    else if HOUR == 10 then -0.486
    else if HOUR == 11 then -0.474
    else if HOUR == 12 then -0.286
    else if HOUR == 13 then -0.413
    else if HOUR == 14 then -0.346
    else if HOUR == 15 then -0.43
    else if HOUR == 16 then -0.1
    else if HOUR == 17 then -0.1
    else if HOUR == 18 then -0.323
    else if HOUR == 19 then 0.0
    else if HOUR == 20 then 0.0
    else if HOUR == 21 then 0.0
    else if HOUR == 22 then 0.0
    else 0.0;
def q3 =
    if HOUR == 0 then 0.0
    else if HOUR == 1 then 0.0
    else if HOUR == 2 then 0.0
    else if HOUR == 3 then 0.0
    else if HOUR == 4 then 0.21
    else if HOUR == 5 then 0.153
    else if HOUR == 6 then 0.3
    else if HOUR == 7 then 0.38
    else if HOUR == 8 then 0.55
    else if HOUR == 9 then 0.838
    else if HOUR == 10 then 0.54
    else if HOUR == 11 then 0.549
    else if HOUR == 12 then 0.531
    else if HOUR == 13 then 0.631
    else if HOUR == 14 then 0.55
    else if HOUR == 15 then 0.604
    else if HOUR == 16 then 0.13
    else if HOUR == 17 then 0.17
    else if HOUR == 18 then 0.783
    else if HOUR == 19 then 0.0
    else if HOUR == 20 then 0.0
    else if HOUR == 21 then 0.0
    else if HOUR == 22 then 0.0
    else 0.0;
def m2 =
    if HOUR == 0 then 0.0
    else if HOUR == 1 then 0.0
    else if HOUR == 2 then 0.0
    else if HOUR == 3 then 0.0
    else if HOUR == 4 then -0.02
    else if HOUR == 5 then -0.01
    else if HOUR == 6 then 0.08
    else if HOUR == 7 then 0.08
    else if HOUR == 8 then 0.04
    else if HOUR == 9 then 0.18
    else if HOUR == 10 then 0.05
    else if HOUR == 11 then 0.087
    else if HOUR == 12 then 0.142
    else if HOUR == 13 then 0.18
    else if HOUR == 14 then 0.13
    else if HOUR == 15 then 0.059
    else if HOUR == 16 then -0.01
    else if HOUR == 17 then 0.03
    else if HOUR == 18 then 0.297
    else if HOUR == 19 then 0.0
    else if HOUR == 20 then 0.0
    else if HOUR == 21 then 0.0
    else if HOUR == 22 then 0.0
    else 0.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);
	Does this code work now during 2024 for ES?Updated the indicator to include a "distance to the median" line label. Compares the current close to the projected median. If you're below the median, the theory goes, the median may pull you up. if you're above the next median, the median may pull you down.
PS I did not update the first post with this script, as the coefficients have changed with time and new data. the version for any of these studies is to look at the date range in the header.
-mashume
Code:######################################################### # # Next Hour ES Trading Range # Algorithmic Prediction # Values Derived on Data from # 2021-02-03 to # 2021-04-15 # # @mashume at usethinkscript.com # #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- # # This Version /ES (and maybe /MES) 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 -2.25 else if HOUR == 1 then -3.25 else if HOUR == 2 then -2.812 else if HOUR == 3 then -3.5 else if HOUR == 4 then -1.75 else if HOUR == 5 then -2.5 else if HOUR == 6 then -2.0 else if HOUR == 7 then -3.5 else if HOUR == 8 then -3.5 else if HOUR == 9 then -5.688 else if HOUR == 10 then -4.0 else if HOUR == 11 then -2.25 else if HOUR == 12 then -2.812 else if HOUR == 13 then -4.25 else if HOUR == 14 then -6.5 else if HOUR == 15 then -4.5 else if HOUR == 16 then -1.75 else if HOUR == 17 then 1.0 else if HOUR == 18 then -3.25 else if HOUR == 19 then -3.0 else if HOUR == 20 then -3.5 else if HOUR == 21 then -3.5 else if HOUR == 22 then -2.0 else -1.5; def q3 = if HOUR == 0 then 2.25 else if HOUR == 1 then 3.0 else if HOUR == 2 then 3.75 else if HOUR == 3 then 3.75 else if HOUR == 4 then 2.75 else if HOUR == 5 then 2.75 else if HOUR == 6 then 3.25 else if HOUR == 7 then 3.062 else if HOUR == 8 then 5.0 else if HOUR == 9 then 8.25 else if HOUR == 10 then 7.062 else if HOUR == 11 then 6.75 else if HOUR == 12 then 5.25 else if HOUR == 13 then 5.0 else if HOUR == 14 then 6.25 else if HOUR == 15 then 6.938 else if HOUR == 16 then 3.5 else if HOUR == 17 then 6.25 else if HOUR == 18 then 2.812 else if HOUR == 19 then 3.0 else if HOUR == 20 then 3.25 else if HOUR == 21 then 2.25 else if HOUR == 22 then 1.75 else 2.0; def m2 = if HOUR == 0 then -0.125 else if HOUR == 1 then -0.25 else if HOUR == 2 then 0.25 else if HOUR == 3 then 0.25 else if HOUR == 4 then 0.375 else if HOUR == 5 then 0.0 else if HOUR == 6 then 0.5 else if HOUR == 7 then 0.0 else if HOUR == 8 then 0.5 else if HOUR == 9 then 2.0 else if HOUR == 10 then 2.25 else if HOUR == 11 then 2.5 else if HOUR == 12 then 1.25 else if HOUR == 13 then 0.75 else if HOUR == 14 then -0.5 else if HOUR == 15 then 1.25 else if HOUR == 16 then 0.75 else if HOUR == 17 then 2.5 else if HOUR == 18 then -0.5 else if HOUR == 19 then 0.25 else if HOUR == 20 then 0.25 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);
You should update when you feel that the market has changed in some way. There is a long post I did about this earlier in this thread I think.Do we need to update every quarter? is there a way to automatically calculate on TOS instead of manual update every time. ?
Could you please send an update for SPX and /ESThank You kind sir!
Appreciate the help and guidance. I would like to learn to update the code by following the method. Could please help in pointing to the recent post/information. I would like to update my script for /MES, /MNQ, /MYM, /M2K, /CL and /GC futures.You should update when you feel that the market has changed in some way. There is a long post I did about this earlier in this thread I think.
There is no way to make ToS do the updates or use real-time data. The indicator code is "written" by a python script I wrote and does a bunch of statistical calculations on the data (aggregations etc...) that aren't really possible in the ToS thinkscript environment. A link to the python notebook that creates the thinkscript is elsewhere in this thread.
Happy Trading,
mashume
Thanks!
SPY
Code:######################################################### # # Next Hour SPY Trading Range # Algorithmic Prediction # # Values Derived on Data from # 2023-11-29 to # 2024-02-26 # # mashume at usethinkscript.com # #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- # # This Version SPY 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.0 else if HOUR == 1 then 0.0 else if HOUR == 2 then 0.0 else if HOUR == 3 then 0.0 else if HOUR == 4 then -0.21 else if HOUR == 5 then -0.19 else if HOUR == 6 then -0.17 else if HOUR == 7 then -0.26 else if HOUR == 8 then -0.52 else if HOUR == 9 then -0.546 else if HOUR == 10 then -0.486 else if HOUR == 11 then -0.474 else if HOUR == 12 then -0.286 else if HOUR == 13 then -0.413 else if HOUR == 14 then -0.346 else if HOUR == 15 then -0.43 else if HOUR == 16 then -0.1 else if HOUR == 17 then -0.1 else if HOUR == 18 then -0.323 else if HOUR == 19 then 0.0 else if HOUR == 20 then 0.0 else if HOUR == 21 then 0.0 else if HOUR == 22 then 0.0 else 0.0; def q3 = if HOUR == 0 then 0.0 else if HOUR == 1 then 0.0 else if HOUR == 2 then 0.0 else if HOUR == 3 then 0.0 else if HOUR == 4 then 0.21 else if HOUR == 5 then 0.153 else if HOUR == 6 then 0.3 else if HOUR == 7 then 0.38 else if HOUR == 8 then 0.55 else if HOUR == 9 then 0.838 else if HOUR == 10 then 0.54 else if HOUR == 11 then 0.549 else if HOUR == 12 then 0.531 else if HOUR == 13 then 0.631 else if HOUR == 14 then 0.55 else if HOUR == 15 then 0.604 else if HOUR == 16 then 0.13 else if HOUR == 17 then 0.17 else if HOUR == 18 then 0.783 else if HOUR == 19 then 0.0 else if HOUR == 20 then 0.0 else if HOUR == 21 then 0.0 else if HOUR == 22 then 0.0 else 0.0; def m2 = if HOUR == 0 then 0.0 else if HOUR == 1 then 0.0 else if HOUR == 2 then 0.0 else if HOUR == 3 then 0.0 else if HOUR == 4 then -0.02 else if HOUR == 5 then -0.01 else if HOUR == 6 then 0.08 else if HOUR == 7 then 0.08 else if HOUR == 8 then 0.04 else if HOUR == 9 then 0.18 else if HOUR == 10 then 0.05 else if HOUR == 11 then 0.087 else if HOUR == 12 then 0.142 else if HOUR == 13 then 0.18 else if HOUR == 14 then 0.13 else if HOUR == 15 then 0.059 else if HOUR == 16 then -0.01 else if HOUR == 17 then 0.03 else if HOUR == 18 then 0.297 else if HOUR == 19 then 0.0 else if HOUR == 20 then 0.0 else if HOUR == 21 then 0.0 else if HOUR == 22 then 0.0 else 0.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);
You kind of have to start at the beginning. It sets a lot of things that get used in the final printing. So start at the top and 'run' each cell on the way down the page. I think it's the second or third cell where you set the 'ticker' string which chooses which data to pull from the 'net.Hi I will like to use this indicator but,Im not available how figure out the Python manual to update the tickers,can some one explain step by step how use it.
Explain how generated the most recent values for the tickers.
I assume this part is the one that generated the code but how do i fill it for example the SPY or NQ?
View attachment 22316
Thanks
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Start a new thread and receive assistance from our community.
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.
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.