How do you make this current? Thanks!Whenever you feel that the market has changed in some subtle (or dramatic) way.
How do you make this current? Thanks!Whenever you feel that the market has changed in some subtle (or dramatic) way.
You ask, and tell me which instrument you'd like updated and I'll post the code here.How do you make this current? Thanks!
I can't find my local copy of the indicator generator code at the moment (it's on a different machine), but this was generated from the google colab notebook here:Is it current for ES?
#########################################################
#
# Next Hour ES=f Trading Range
# Algorithmic Prediction
#
# Values Derived on Data from
# 2023-01-20 to
# 2023-03-31
#
# mashume at usethinkscript.com
#
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#
# This Version ES=f only
# Functional on 1, 2, 3, 5, 10, 15, 20, 30, 60 minute charts
#
#########################################################
declare upper;
def Y = 31556926;
def M = 2629743;
def D = 86400;
def H = 3600;
def HalfHour = 1800;
def epoch = (getTime() / 1000);
def YMD = (epoch % Y) - (epoch / Y);
def month = (Floor(YMD / M) + 1);
def GMT = Floor((epoch % D) / H);
def HOUR = if GMT > 4 then GMT - 4 else if GMT < 4 then (GMT + 24) - 4 else 0;
def tf = getAggregationPeriod();
def barsPerHour = if tf == AggregationPeriod.HOUR then 1
else if tf == AggregationPeriod.THIRTY_MIN then 2
else if tf == AggregationPeriod.TWENTY_MIN then 3
else if tf == AggregationPeriod.FIFTEEN_MIN then 4
else if tf == AggregationPeriod.TEN_MIN then 6
else if tf == AggregationPeriod.FIVE_MIN then 12
else if tf == AggregationPeriod.THREE_MIN then 20
else if tf == AggregationPeriod.TWO_MIN then 30
else if tf == AggregationPeriod.MIN then 60
else double.nan;
def q1 =
if HOUR == 0 then -1.5
else if HOUR == 1 then -2.75
else if HOUR == 2 then -4.812
else if HOUR == 3 then -4.5
else if HOUR == 4 then -4.5
else if HOUR == 5 then -3.5
else if HOUR == 6 then -2.75
else if HOUR == 7 then -6.062
else if HOUR == 8 then -5.0
else if HOUR == 9 then -7.188
else if HOUR == 10 then -7.0
else if HOUR == 11 then -6.75
else if HOUR == 12 then -7.0
else if HOUR == 13 then -6.25
else if HOUR == 14 then -7.062
else if HOUR == 15 then -2.75
else if HOUR == 16 then -4.25
else if HOUR == 17 then nan
else if HOUR == 18 then -2.25
else if HOUR == 19 then -2.5
else if HOUR == 20 then -2.25
else if HOUR == 21 then -1.5
else if HOUR == 22 then -1.5
else -2.0;
def q3 =
if HOUR == 0 then 1.5
else if HOUR == 1 then 2.5
else if HOUR == 2 then 3.75
else if HOUR == 3 then 3.75
else if HOUR == 4 then 3.0
else if HOUR == 5 then 3.75
else if HOUR == 6 then 5.75
else if HOUR == 7 then 4.0
else if HOUR == 8 then 7.5
else if HOUR == 9 then 12.688
else if HOUR == 10 then 11.75
else if HOUR == 11 then 6.25
else if HOUR == 12 then 7.75
else if HOUR == 13 then 8.312
else if HOUR == 14 then 8.75
else if HOUR == 15 then 8.0
else if HOUR == 16 then 2.188
else if HOUR == 17 then nan
else if HOUR == 18 then 2.75
else if HOUR == 19 then 3.0
else if HOUR == 20 then 2.25
else if HOUR == 21 then 2.75
else if HOUR == 22 then 1.5
else 2.0;
def m2 =
if HOUR == 0 then 0.0
else if HOUR == 1 then 0.0
else if HOUR == 2 then -0.5
else if HOUR == 3 then 0.0
else if HOUR == 4 then -1.25
else if HOUR == 5 then 0.375
else if HOUR == 6 then 1.125
else if HOUR == 7 then -1.25
else if HOUR == 8 then 0.75
else if HOUR == 9 then 2.5
else if HOUR == 10 then 2.5
else if HOUR == 11 then -0.25
else if HOUR == 12 then 1.0
else if HOUR == 13 then 1.375
else if HOUR == 14 then 2.5
else if HOUR == 15 then 3.25
else if HOUR == 16 then -0.75
else if HOUR == 17 then nan
else if HOUR == 18 then 0.5
else if HOUR == 19 then 0.75
else if HOUR == 20 then 0.0
else if HOUR == 21 then 0.5
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);
With tight stops.
Hi Mashume, could you update for /TN? I searched the forum and did not find that python script, only one post of some single line code. Do you happen to know where I could find it?You ask, and tell me which instrument you'd like updated and I'll post the code here.
-mashume
Sounds good. I’ll watch it tomorrow and report back.With tight stops.
The first full hour of the day, the price opened near the bottom of the normal range, tried to climb up to the median, and failed, falling back (and through) the normal low.
The last three hours of the day, the price started closing near the median, and then flirted with the high normal range, bounding off the median range the last full hour shown.
I don't know that I would take many trades, but when it broke above the nedian in the third full hour before the close, I might have gone long with a stop at the next hour median and a target at the high. Looks like a nice R:R setup.
-mashume
The code is missing value for HOUR 17 is nanI can't find my local copy of the indicator generator code at the moment (it's on a different machine), but this was generated from the google colab notebook here:
https://colab.research.google.com/drive/15AXGoDA9rtaapu-FIPea8xmXNgRlibfx?usp=sharing
Code:######################################################### # # Next Hour ES=f Trading Range # Algorithmic Prediction # # Values Derived on Data from # 2023-01-20 to # 2023-03-31 # # mashume at usethinkscript.com # #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- # # This Version ES=f only # Functional on 1, 2, 3, 5, 10, 15, 20, 30, 60 minute charts # ######################################################### declare upper; def Y = 31556926; def M = 2629743; def D = 86400; def H = 3600; def HalfHour = 1800; def epoch = (getTime() / 1000); def YMD = (epoch % Y) - (epoch / Y); def month = (Floor(YMD / M) + 1); def GMT = Floor((epoch % D) / H); def HOUR = if GMT > 4 then GMT - 4 else if GMT < 4 then (GMT + 24) - 4 else 0; def tf = getAggregationPeriod(); def barsPerHour = if tf == AggregationPeriod.HOUR then 1 else if tf == AggregationPeriod.THIRTY_MIN then 2 else if tf == AggregationPeriod.TWENTY_MIN then 3 else if tf == AggregationPeriod.FIFTEEN_MIN then 4 else if tf == AggregationPeriod.TEN_MIN then 6 else if tf == AggregationPeriod.FIVE_MIN then 12 else if tf == AggregationPeriod.THREE_MIN then 20 else if tf == AggregationPeriod.TWO_MIN then 30 else if tf == AggregationPeriod.MIN then 60 else double.nan; def q1 = if HOUR == 0 then -1.5 else if HOUR == 1 then -2.75 else if HOUR == 2 then -4.812 else if HOUR == 3 then -4.5 else if HOUR == 4 then -4.5 else if HOUR == 5 then -3.5 else if HOUR == 6 then -2.75 else if HOUR == 7 then -6.062 else if HOUR == 8 then -5.0 else if HOUR == 9 then -7.188 else if HOUR == 10 then -7.0 else if HOUR == 11 then -6.75 else if HOUR == 12 then -7.0 else if HOUR == 13 then -6.25 else if HOUR == 14 then -7.062 else if HOUR == 15 then -2.75 else if HOUR == 16 then -4.25 else if HOUR == 17 then nan else if HOUR == 18 then -2.25 else if HOUR == 19 then -2.5 else if HOUR == 20 then -2.25 else if HOUR == 21 then -1.5 else if HOUR == 22 then -1.5 else -2.0; def q3 = if HOUR == 0 then 1.5 else if HOUR == 1 then 2.5 else if HOUR == 2 then 3.75 else if HOUR == 3 then 3.75 else if HOUR == 4 then 3.0 else if HOUR == 5 then 3.75 else if HOUR == 6 then 5.75 else if HOUR == 7 then 4.0 else if HOUR == 8 then 7.5 else if HOUR == 9 then 12.688 else if HOUR == 10 then 11.75 else if HOUR == 11 then 6.25 else if HOUR == 12 then 7.75 else if HOUR == 13 then 8.312 else if HOUR == 14 then 8.75 else if HOUR == 15 then 8.0 else if HOUR == 16 then 2.188 else if HOUR == 17 then nan else if HOUR == 18 then 2.75 else if HOUR == 19 then 3.0 else if HOUR == 20 then 2.25 else if HOUR == 21 then 2.75 else if HOUR == 22 then 1.5 else 2.0; def m2 = if HOUR == 0 then 0.0 else if HOUR == 1 then 0.0 else if HOUR == 2 then -0.5 else if HOUR == 3 then 0.0 else if HOUR == 4 then -1.25 else if HOUR == 5 then 0.375 else if HOUR == 6 then 1.125 else if HOUR == 7 then -1.25 else if HOUR == 8 then 0.75 else if HOUR == 9 then 2.5 else if HOUR == 10 then 2.5 else if HOUR == 11 then -0.25 else if HOUR == 12 then 1.0 else if HOUR == 13 then 1.375 else if HOUR == 14 then 2.5 else if HOUR == 15 then 3.25 else if HOUR == 16 then -0.75 else if HOUR == 17 then nan else if HOUR == 18 then 0.5 else if HOUR == 19 then 0.75 else if HOUR == 20 then 0.0 else if HOUR == 21 then 0.5 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);
-mashume
The code is here:Hi Mashume, could you update for /TN? I searched the forum and did not find that python script, only one post of some single line code. Do you happen to know where I could find it?
#########################################################
#
# Next Hour /TN Trading Range
# Algorithmic Prediction
#
# Values Derived on Data from
# 2023-02-03 to
# 2023-04-14
#
# mashume at usethinkscript.com
#
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#
# This Version /TN 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.031
else if HOUR == 1 then -0.062
else if HOUR == 2 then -0.098
else if HOUR == 3 then -0.125
else if HOUR == 4 then -0.094
else if HOUR == 5 then -0.07
else if HOUR == 6 then -0.094
else if HOUR == 7 then -0.141
else if HOUR == 8 then -0.203
else if HOUR == 9 then -0.176
else if HOUR == 10 then -0.109
else if HOUR == 11 then -0.109
else if HOUR == 12 then -0.109
else if HOUR == 13 then -0.102
else if HOUR == 14 then -0.062
else if HOUR == 15 then -0.062
else if HOUR == 16 then -0.078
else if HOUR == 17 then 0.0
else if HOUR == 18 then -0.031
else if HOUR == 19 then -0.062
else if HOUR == 20 then -0.047
else if HOUR == 21 then -0.031
else if HOUR == 22 then -0.031
else -0.031;
def q3 =
if HOUR == 0 then 0.047
else if HOUR == 1 then 0.062
else if HOUR == 2 then 0.047
else if HOUR == 3 then 0.078
else if HOUR == 4 then 0.062
else if HOUR == 5 then 0.063
else if HOUR == 6 then 0.094
else if HOUR == 7 then 0.141
else if HOUR == 8 then 0.156
else if HOUR == 9 then 0.156
else if HOUR == 10 then 0.125
else if HOUR == 11 then 0.078
else if HOUR == 12 then 0.094
else if HOUR == 13 then 0.078
else if HOUR == 14 then 0.062
else if HOUR == 15 then 0.078
else if HOUR == 16 then 0.031
else if HOUR == 17 then 0.0
else if HOUR == 18 then 0.062
else if HOUR == 19 then 0.062
else if HOUR == 20 then 0.047
else if HOUR == 21 then 0.062
else if HOUR == 22 then 0.047
else 0.031;
def m2 =
if HOUR == 0 then 0.0
else if HOUR == 1 then 0.0
else if HOUR == 2 then -0.031
else if HOUR == 3 then 0.0
else if HOUR == 4 then -0.016
else if HOUR == 5 then 0.0
else if HOUR == 6 then -0.016
else if HOUR == 7 then -0.016
else if HOUR == 8 then -0.016
else if HOUR == 9 then -0.016
else if HOUR == 10 then 0.0
else if HOUR == 11 then -0.016
else if HOUR == 12 then 0.0
else if HOUR == 13 then -0.016
else if HOUR == 14 then 0.0
else if HOUR == 15 then 0.016
else if HOUR == 16 then -0.016
else if HOUR == 17 then 0.0
else if HOUR == 18 then 0.0
else if HOUR == 19 then 0.016
else if HOUR == 20 then 0.0
else if HOUR == 21 then 0.016
else if HOUR == 22 then 0.016
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);
thx @mashume. can you please fix the errors for some of the variables marked :nanI can't find my local copy of the indicator generator code at the moment (it's on a different machine), but this was generated from the google colab notebook here:
https://colab.research.google.com/drive/15AXGoDA9rtaapu-FIPea8xmXNgRlibfx?usp=sharing
Code:######################################################### # # Next Hour ES=f Trading Range # Algorithmic Prediction # # Values Derived on Data from # 2023-01-20 to # 2023-03-31 # # mashume at usethinkscript.com # #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- # # This Version ES=f only # Functional on 1, 2, 3, 5, 10, 15, 20, 30, 60 minute charts # ######################################################### declare upper; def Y = 31556926; def M = 2629743; def D = 86400; def H = 3600; def HalfHour = 1800; def epoch = (getTime() / 1000); def YMD = (epoch % Y) - (epoch / Y); def month = (Floor(YMD / M) + 1); def GMT = Floor((epoch % D) / H); def HOUR = if GMT > 4 then GMT - 4 else if GMT < 4 then (GMT + 24) - 4 else 0; def tf = getAggregationPeriod(); def barsPerHour = if tf == AggregationPeriod.HOUR then 1 else if tf == AggregationPeriod.THIRTY_MIN then 2 else if tf == AggregationPeriod.TWENTY_MIN then 3 else if tf == AggregationPeriod.FIFTEEN_MIN then 4 else if tf == AggregationPeriod.TEN_MIN then 6 else if tf == AggregationPeriod.FIVE_MIN then 12 else if tf == AggregationPeriod.THREE_MIN then 20 else if tf == AggregationPeriod.TWO_MIN then 30 else if tf == AggregationPeriod.MIN then 60 else double.nan; def q1 = if HOUR == 0 then -1.5 else if HOUR == 1 then -2.75 else if HOUR == 2 then -4.812 else if HOUR == 3 then -4.5 else if HOUR == 4 then -4.5 else if HOUR == 5 then -3.5 else if HOUR == 6 then -2.75 else if HOUR == 7 then -6.062 else if HOUR == 8 then -5.0 else if HOUR == 9 then -7.188 else if HOUR == 10 then -7.0 else if HOUR == 11 then -6.75 else if HOUR == 12 then -7.0 else if HOUR == 13 then -6.25 else if HOUR == 14 then -7.062 else if HOUR == 15 then -2.75 else if HOUR == 16 then -4.25 else if HOUR == 17 then nan else if HOUR == 18 then -2.25 else if HOUR == 19 then -2.5 else if HOUR == 20 then -2.25 else if HOUR == 21 then -1.5 else if HOUR == 22 then -1.5 else -2.0; def q3 = if HOUR == 0 then 1.5 else if HOUR == 1 then 2.5 else if HOUR == 2 then 3.75 else if HOUR == 3 then 3.75 else if HOUR == 4 then 3.0 else if HOUR == 5 then 3.75 else if HOUR == 6 then 5.75 else if HOUR == 7 then 4.0 else if HOUR == 8 then 7.5 else if HOUR == 9 then 12.688 else if HOUR == 10 then 11.75 else if HOUR == 11 then 6.25 else if HOUR == 12 then 7.75 else if HOUR == 13 then 8.312 else if HOUR == 14 then 8.75 else if HOUR == 15 then 8.0 else if HOUR == 16 then 2.188 else if HOUR == 17 then nan else if HOUR == 18 then 2.75 else if HOUR == 19 then 3.0 else if HOUR == 20 then 2.25 else if HOUR == 21 then 2.75 else if HOUR == 22 then 1.5 else 2.0; def m2 = if HOUR == 0 then 0.0 else if HOUR == 1 then 0.0 else if HOUR == 2 then -0.5 else if HOUR == 3 then 0.0 else if HOUR == 4 then -1.25 else if HOUR == 5 then 0.375 else if HOUR == 6 then 1.125 else if HOUR == 7 then -1.25 else if HOUR == 8 then 0.75 else if HOUR == 9 then 2.5 else if HOUR == 10 then 2.5 else if HOUR == 11 then -0.25 else if HOUR == 12 then 1.0 else if HOUR == 13 then 1.375 else if HOUR == 14 then 2.5 else if HOUR == 15 then 3.25 else if HOUR == 16 then -0.75 else if HOUR == 17 then nan else if HOUR == 18 then 0.5 else if HOUR == 19 then 0.75 else if HOUR == 20 then 0.0 else if HOUR == 21 then 0.5 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);
-mashume
Futures market is closed for settlements from 17:00 to 18:00 Eastern time.The code is missing value for HOUR 17 is nan
You'll have to post the code you got out of the script. I don't have the ability to 'fix errors' in code I don't have.thx @mashume. can you please fix the errors for some of the variables marked :nan
1 is the 1st quartileWatching it more @mashume. Some elementary questions. What are these plots mainly meant for? I don't want to assume.
I am not a coder, but I believe what mashume meant to write is : double.NaN. I plugged that in where all the "nan"s are, and the /ES script worked just fine.thx @mashume. can you please fix the errors for some of the variables marked :nan
thx @mashume. can you please fix the errors for some of the variables marked :nan
Can you post latest for /ES?
#########################################################
#
# Next Hour /ES Trading Range
# Algorithmic Prediction
#
# Values Derived on Data from
# 2023-03-01 to
# 2023-05-10
#
# mashume at usethinkscript.com
#
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#
# This Version /ES only
# Functional on 1, 2, 3, 5, 10, 15, 20, 30, 60 minute charts
#
#########################################################
declare upper;
def Y = 31556926;
def M = 2629743;
def D = 86400;
def H = 3600;
def HalfHour = 1800;
def epoch = (getTime() / 1000);
def YMD = (epoch % Y) - (epoch / Y);
def month = (Floor(YMD / M) + 1);
def GMT = Floor((epoch % D) / H);
def HOUR = if GMT > 4 then GMT - 4 else if GMT < 4 then (GMT + 24) - 4 else 0;
def tf = getAggregationPeriod();
def barsPerHour = if tf == AggregationPeriod.HOUR then 1
else if tf == AggregationPeriod.THIRTY_MIN then 2
else if tf == AggregationPeriod.TWENTY_MIN then 3
else if tf == AggregationPeriod.FIFTEEN_MIN then 4
else if tf == AggregationPeriod.TEN_MIN then 6
else if tf == AggregationPeriod.FIVE_MIN then 12
else if tf == AggregationPeriod.THREE_MIN then 20
else if tf == AggregationPeriod.TWO_MIN then 30
else if tf == AggregationPeriod.MIN then 60
else double.nan;
def q1 =
if HOUR == 0 then -1.5
else if HOUR == 1 then -2.5
else if HOUR == 2 then -3.5
else if HOUR == 3 then -4.75
else if HOUR == 4 then -2.5
else if HOUR == 5 then -2.125
else if HOUR == 6 then -3.25
else if HOUR == 7 then -3.812
else if HOUR == 8 then -4.75
else if HOUR == 9 then -7.75
else if HOUR == 10 then -6.25
else if HOUR == 11 then -6.0
else if HOUR == 12 then -5.0
else if HOUR == 13 then -5.625
else if HOUR == 14 then -4.812
else if HOUR == 15 then -2.125
else if HOUR == 16 then -3.75
else if HOUR == 17 then -3.75
else if HOUR == 18 then -1.5
else if HOUR == 19 then -2.25
else if HOUR == 20 then -1.75
else if HOUR == 21 then -1.0
else if HOUR == 22 then -1.25
else -1.5;
def q3 =
if HOUR == 0 then 1.312
else if HOUR == 1 then 2.25
else if HOUR == 2 then 3.5
else if HOUR == 3 then 3.0
else if HOUR == 4 then 3.75
else if HOUR == 5 then 3.875
else if HOUR == 6 then 3.75
else if HOUR == 7 then 2.75
else if HOUR == 8 then 7.25
else if HOUR == 9 then 9.5
else if HOUR == 10 then 6.5
else if HOUR == 11 then 6.688
else if HOUR == 12 then 6.5
else if HOUR == 13 then 7.0
else if HOUR == 14 then 7.25
else if HOUR == 15 then 8.0
else if HOUR == 16 then 1.0
else if HOUR == 17 then -0.25
else if HOUR == 18 then 2.0
else if HOUR == 19 then 2.062
else if HOUR == 20 then 2.25
else if HOUR == 21 then 2.75
else if HOUR == 22 then 1.5
else 1.75;
def m2 =
if HOUR == 0 then 0.0
else if HOUR == 1 then 0.0
else if HOUR == 2 then 0.25
else if HOUR == 3 then -0.75
else if HOUR == 4 then 0.75
else if HOUR == 5 then 0.75
else if HOUR == 6 then 0.5
else if HOUR == 7 then -0.5
else if HOUR == 8 then 1.0
else if HOUR == 9 then 0.875
else if HOUR == 10 then 0.0
else if HOUR == 11 then 0.75
else if HOUR == 12 then 2.625
else if HOUR == 13 then 1.25
else if HOUR == 14 then 1.25
else if HOUR == 15 then 2.75
else if HOUR == 16 then -1.5
else if HOUR == 17 then -2.0
else if HOUR == 18 then 0.5
else if HOUR == 19 then -0.5
else if HOUR == 20 then 0.25
else if HOUR == 21 then 0.5
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);
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.