sandy_s157
New member
@mashume - is there anyway you can create a scan when the price crosses above median? I am looking to create a scan for SPY and AMZN on 2m timeframe. I am not able to create one for a 2m time frame since the Aggregation Period is set to 1 hour.EDIT 2021-December
There are many updated versions of this indicator using more recent data. Please start your search at the END of this thread and work your way toward page 1 to find the most recent for whichever instrument you want. If you don't see it, post a request and I'll do my best to fill it in reasonable order.
So, 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).
View attachment 10334
Overnight projections.
View attachment 10335
Showing regular trading day projections.
View attachment 10336
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
Last edited: