charlie2598
Member
sorry I am trying to tell you SPXsix ... is that minutes, or $SIX (some stock), or ...?
-mashume
sorry I am trying to tell you SPXsix ... is that minutes, or $SIX (some stock), or ...?
-mashume
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
No problem.sorry I am trying to tell you SPX
Yeah, I noticed that it quit working at some point... and then I forgot about it. Not sure why. Never was.Hi mashume,
good work. like this indicator.
question: it does not display the cloud(addcloud(ESUpTarget, ESDnTarget, color.white, color.white)- meaning the addcloud() function does not work.
I integrated the script with SuperTrend CCI ATR Trend Indicator. The addcloud() function stopped working in the integarted script - meaning the addcloud() function does not work.. The standalone SuperTrend CCI ATR Trend does display the cloud - meaning the addcloud() function does not work.
I also tried integrading the script in other scripts - addcloud() stops working in those integrated scripts also
Please advide
do you think you have to update the data because last date is 04.08.21So, from the data described here:
https://usethinkscript.com/threads/es-futures-probability-at-time-market-timing-differently.6250/
I decided to build an indicator to see what would happen. This indicator is the result of that.
It may or may not be mathematically correct. If you'd like to audit my statistics, shifts, and so forth, please do.
Remember, the bounding boxes are being drawn a minimum of 1 hour before the candles are drawn. They are real predictions, based on probable movements of the market as described in the link above. These use 1st and 3rd quartile deviances from median for the range shown (for those who care).
![]()
Overnight projections.
![]()
Showing regular trading day projections.
![]()
This one shows the predictions in the expansion area on the right.
These are not overly accurate, but an interesting direction in indicators.
I have written a python script to "regenerate" the indicator code so I can run it weekly to update the coefficients if there is interest.
Here's the code for the indicator:
Code:######################################################### # # Next Hour ES Trading Range # Algorithmic Prediction # Values Derived on Data from # 2021-01-12 to # 2021-04-08 # # @mashume at usethinkscript.com # #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- # # This Version /ES (and maybe /MES) only # Functional on 1, 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.MIN then 60 else double.nan; def q1 = if HOUR == 0 then -2.25 else if HOUR == 1 then -3.5 else if HOUR == 2 then -3.25 else if HOUR == 3 then -3.5 else if HOUR == 4 then -2.0 else if HOUR == 5 then -2.5 else if HOUR == 6 then -2.0 else if HOUR == 7 then -4.0 else if HOUR == 8 then -3.75 else if HOUR == 9 then -6.25 else if HOUR == 10 then -4.5 else if HOUR == 11 then -3.0 else if HOUR == 12 then -2.812 else if HOUR == 13 then -3.75 else if HOUR == 14 then -6.75 else if HOUR == 15 then -5.75 else if HOUR == 16 then -1.75 else if HOUR == 17 then 1.0 else if HOUR == 18 then -3.5 else if HOUR == 19 then -3.25 else if HOUR == 20 then -3.5 else if HOUR == 21 then -3.5 else if HOUR == 22 then -2.0 else -1.25; 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 4.25 else if HOUR == 4 then 2.75 else if HOUR == 5 then 3.25 else if HOUR == 6 then 3.75 else if HOUR == 7 then 3.0 else if HOUR == 8 then 5.312 else if HOUR == 9 then 8.75 else if HOUR == 10 then 7.75 else if HOUR == 11 then 7.0 else if HOUR == 12 then 5.5 else if HOUR == 13 then 5.25 else if HOUR == 14 then 6.562 else if HOUR == 15 then 6.75 else if HOUR == 16 then 4.0 else if HOUR == 17 then 6.25 else if HOUR == 18 then 3.25 else if HOUR == 19 then 3.5 else if HOUR == 20 then 3.75 else if HOUR == 21 then 2.5 else if HOUR == 22 then 2.25 else 2.5; def m2 = if HOUR == 0 then 0.0 else if HOUR == 1 then -0.5 else if HOUR == 2 then 0.25 else if HOUR == 3 then 0.25 else if HOUR == 4 then 0.25 else if HOUR == 5 then 0.5 else if HOUR == 6 then 0.5 else if HOUR == 7 then -0.25 else if HOUR == 8 then 0.5 else if HOUR == 9 then 2.0 else if HOUR == 10 then 2.75 else if HOUR == 11 then 2.5 else if HOUR == 12 then 1.5 else if HOUR == 13 then 1.0 else if HOUR == 14 then -0.5 else if HOUR == 15 then 0.75 else if HOUR == 16 then 1.0 else if HOUR == 17 then 2.5 else if HOUR == 18 then -0.25 else if HOUR == 19 then 0.5 else if HOUR == 20 then 0.25 else if HOUR == 21 then -0.75 else if HOUR == 22 then 0.5 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);
If you find this useful, let me know. This could, potentially, be applied to any ticker, though it would need to be for a single ticker. If you trade exclusively one symbol, it could be an interesting exercise.
REMEMBER This is just probabilities applied to prices. It's not magic, and it's not always going to be correct.
Happy Trading,
mashume
Nope. I havent gotten around to figuring out a new API other than the Yahoo Finance API that I was using last time around. When I get a break one of these days I'll go through setting up TD Ameritrade authentication to pull data from them, but not yet. Unless anyone out there has a source for 5m OHLC data for free???Hi Is there any updated version of this script. May i also know how it works and what did u notice while using/testing this script
Hi MushumeUpdates:
I have a working API again, through TDA. It's going to take a bit more time to collect the data into the format I need since apparently TDA is limiting me to 10 days of data in a single request and I've based the indicator thus far on a 60 day window.
Still working on getting all the ducks in a row.
-mashume
Nope. I havent gotten around to figuring out a new API other than the Yahoo Finance API that I was using last time around. When I get a break one of these days I'll go through setting up TD Ameritrade authentication to pull data from them, but not yet. Unless anyone out there has a source for 5m OHLC data for free???
-mashume
Just last weekend I finally got the TDA API working. This is on the list of things to doWere you able to get around to updating the data? The algos have had quite an impact on trading this year, i'd be curios to see how the graphs changed, especially on NQ.
Well, the TDA API doesn't provide futures price history. Live stream, quotes, but no historical data. So I'm still searching for a data source for this one.you're the man!
it seems like throughout the summer the NQ would trade very...untechnically...if that's a word. The only thing i can attribute that to is the explosion of quant funds.
Will be interesting to see what the results imply.
#########################################################
#
# 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);
#########################################################
#
# 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);
#########################################################
#
# 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);
#########################################################
#
# 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);
#########################################################
#
# Next Hour ^VIX Trading Range
# Algorithmic Prediction
#
# Values Derived on Data from
# 2021-08-27 to
# 2021-11-19
#
# @mashume at usethinkscript.com
#
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#
# This Version /^VIX 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.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.1
else if HOUR == 5 then -0.11
else if HOUR == 6 then -0.11
else if HOUR == 7 then -0.153
else if HOUR == 8 then -0.24
else if HOUR == 9 then -0.33
else if HOUR == 10 then -0.25
else if HOUR == 11 then -0.23
else if HOUR == 12 then -0.18
else if HOUR == 13 then -0.22
else if HOUR == 14 then -0.19
else if HOUR == 15 then -0.273
else if HOUR == 16 then -0.278
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.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.1
else if HOUR == 5 then 0.093
else if HOUR == 6 then 0.08
else if HOUR == 7 then 0.08
else if HOUR == 8 then 0.197
else if HOUR == 9 then 0.352
else if HOUR == 10 then 0.13
else if HOUR == 11 then 0.17
else if HOUR == 12 then 0.19
else if HOUR == 13 then 0.12
else if HOUR == 14 then 0.13
else if HOUR == 15 then 0.462
else if HOUR == 16 then 0.49
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.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.02
else if HOUR == 6 then -0.015
else if HOUR == 7 then -0.03
else if HOUR == 8 then -0.04
else if HOUR == 9 then -0.045
else if HOUR == 10 then -0.05
else if HOUR == 11 then -0.055
else if HOUR == 12 then -0.02
else if HOUR == 13 then -0.05
else if HOUR == 14 then -0.02
else if HOUR == 15 then 0.065
else if HOUR == 16 then 0.05
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.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 SPY Trading Range
# Algorithmic Prediction
#
# Values Derived on Data from
# 2021-08-27 to
# 2021-11-19
#
# @mashume at usethinkscript.com
#
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#
# This Version /SPY 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.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.25
else if HOUR == 5 then -0.2
else if HOUR == 6 then -0.192
else if HOUR == 7 then -0.28
else if HOUR == 8 then -0.6
else if HOUR == 9 then -0.892
else if HOUR == 10 then -0.45
else if HOUR == 11 then -0.35
else if HOUR == 12 then -0.482
else if HOUR == 13 then -0.31
else if HOUR == 14 then -0.416
else if HOUR == 15 then -0.64
else if HOUR == 16 then -0.09
else if HOUR == 17 then -0.11
else if HOUR == 18 then -0.14
else if HOUR == 19 then -0.713
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.23
else if HOUR == 5 then 0.23
else if HOUR == 6 then 0.283
else if HOUR == 7 then 0.3
else if HOUR == 8 then 0.674
else if HOUR == 9 then 0.996
else if HOUR == 10 then 0.546
else if HOUR == 11 then 0.49
else if HOUR == 12 then 0.37
else if HOUR == 13 then 0.486
else if HOUR == 14 then 0.385
else if HOUR == 15 then 0.4
else if HOUR == 16 then 0.11
else if HOUR == 17 then 0.18
else if HOUR == 18 then 0.215
else if HOUR == 19 then 1.15
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.03
else if HOUR == 5 then 0.02
else if HOUR == 6 then 0.035
else if HOUR == 7 then 0.02
else if HOUR == 8 then 0.06
else if HOUR == 9 then 0.112
else if HOUR == 10 then 0.05
else if HOUR == 11 then 0.07
else if HOUR == 12 then 0.0
else if HOUR == 13 then 0.09
else if HOUR == 14 then -0.02
else if HOUR == 15 then -0.09
else if HOUR == 16 then 0.005
else if HOUR == 17 then 0.04
else if HOUR == 18 then 0.0
else if HOUR == 19 then 0.335
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 QQQ Trading Range
# Algorithmic Prediction
#
# Values Derived on Data from
# 2021-08-30 to
# 2021-11-22
#
# @mashume at usethinkscript.com
#
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#
# This Version QQQ 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.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.28
else if HOUR == 5 then -0.23
else if HOUR == 6 then -0.23
else if HOUR == 7 then -0.27
else if HOUR == 8 then -0.61
else if HOUR == 9 then -0.867
else if HOUR == 10 then -0.572
else if HOUR == 11 then -0.519
else if HOUR == 12 then -0.51
else if HOUR == 13 then -0.296
else if HOUR == 14 then -0.421
else if HOUR == 15 then -0.6
else if HOUR == 16 then -0.1
else if HOUR == 17 then -0.09
else if HOUR == 18 then -0.12
else if HOUR == 19 then -0.528
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.22
else if HOUR == 5 then 0.22
else if HOUR == 6 then 0.27
else if HOUR == 7 then 0.35
else if HOUR == 8 then 0.625
else if HOUR == 9 then 1.173
else if HOUR == 10 then 0.723
else if HOUR == 11 then 0.618
else if HOUR == 12 then 0.42
else if HOUR == 13 then 0.596
else if HOUR == 14 then 0.496
else if HOUR == 15 then 0.37
else if HOUR == 16 then 0.15
else if HOUR == 17 then 0.166
else if HOUR == 18 then 0.26
else if HOUR == 19 then 1.218
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.02
else if HOUR == 6 then 0.04
else if HOUR == 7 then 0.035
else if HOUR == 8 then 0.018
else if HOUR == 9 then 0.118
else if HOUR == 10 then 0.079
else if HOUR == 11 then 0.12
else if HOUR == 12 then 0.012
else if HOUR == 13 then 0.179
else if HOUR == 14 then -0.01
else if HOUR == 15 then -0.05
else if HOUR == 16 then 0.01
else if HOUR == 17 then 0.03
else if HOUR == 18 then 0.04
else if HOUR == 19 then 0.37
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);
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.