You are AWESOMEEEEEEE! It works! I really appreciate it! I was losing my mind trying to figure it out.
p.s The only thing, I think, I shot myself in the foot was this piece of code:
def MarketOpen = if getday() == getlastday() and SecondsFromTime(0930) >= 0 and SecondsTillTime(1600) >= 0 then 1 else 0;
It is only plotting bubbles strictly for today's session and I cannot see any bubbles for previous days. If I remove getday() == getlastday() ...do you think it will solve it? or what would be the proper way to do it?
def MarketOpen = if SecondsFromTime(0930) >= 0 and SecondsTillTime(1600) >= 0 then 1 else 0;
I think the following is a little simpler and seems to work on all days on the chart. I used SPX 30d 5m chart with Cam Pivots set to 15d as it provided some good test data.
Edit: correction to S3 code to include secondsfromtime(0930) > 0 to the secondstilltime(1600) > 0 line below to eliminate where first 'buy bubble' occurred outside regular trading session
Ruby:# # TD Ameritrade IP Company, Inc. (c) 2013-2021 # input aggregationPeriod = {default "DAY", "WEEK", "MONTH"}; input length = 15; input hide_s1_r1 = yes; input lines = {default dashes, points, triangles, horizontal, squares}; input showbubbles_description = yes; input showpricebubble = yes; input showlabels = yes; Assert(length > 0, "'length' should be positive: " + length); def yyyymmdd = GetYYYYMMDD(); def month = GetYear() * 12 + GetMonth(); def day_number = DaysFromDate(First(yyyymmdd)) + GetDayOfWeek(First(yyyymmdd)); def period; switch (aggregationPeriod) { case DAY: period = CountTradingDays(Min(First(yyyymmdd), yyyymmdd), yyyymmdd) - 1; case WEEK: period = Floor(day_number / 7); case MONTH: period = Floor(month - First(month)); } def count = CompoundValue(1, if period != period[1] then (count[1] + period - period[1]) % length else count[1], 0); def start = CompoundValue(1, count < count[1] + period - period[1], yes); def highValue = if start then Highest(high(period = aggregationPeriod), length)[1] else if highValue[1] != 0 then highValue[1] else Double.NaN; def lowValue = if start then Lowest(low(period = aggregationPeriod), length)[1] else if lowValue[1] != 0 then lowValue[1] else Double.NaN; def closeValue = if start then close(period = aggregationPeriod)[1] else closeValue[1]; def range = highValue - lowValue; plot R5 = (highValue / lowValue) * closeValue; plot R4 = closeValue + range * (1.1) / 2; plot R3 = closeValue + range * (1.1) / 4; plot R2 = closeValue + range * (1.1) / 6; plot R1 = closeValue + range * (1.1) / 12; plot S1 = closeValue - range * (1.1) / 12; plot S2 = closeValue - range * (1.1) / 6; plot S3 = closeValue - range * (1.1) / 4; plot S4 = closeValue - range * (1.1) / 2; plot S5 = (closeValue - (R5 - closeValue)); R1.SetHiding(hide_s1_r1); S1.SetHiding(hide_s1_r1); R5.SetDefaultColor(GetColor(5)); R4.SetDefaultColor(GetColor(5)); R3.SetDefaultColor(GetColor(5)); R2.SetDefaultColor(GetColor(5)); R1.SetDefaultColor(GetColor(5)); S1.SetDefaultColor(GetColor(6)); S2.SetDefaultColor(GetColor(6)); S3.SetDefaultColor(GetColor(6)); S4.SetDefaultColor(GetColor(6)); S5.SetDefaultColor(GetColor(6)); def paintingStrategy = if lines == lines.points then PaintingStrategy.POINTS else if lines == lines.triangles then PaintingStrategy.TRIANGLES else if lines == lines.dashes then PaintingStrategy.DASHES else if lines == lines.horizontal then PaintingStrategy.HORIZONTAL else PaintingStrategy.SQUARES; R5.SetPaintingStrategy(paintingStrategy); R4.SetPaintingStrategy(paintingStrategy); R3.SetPaintingStrategy(paintingStrategy); R2.SetPaintingStrategy(paintingStrategy); R1.SetPaintingStrategy(paintingStrategy); S1.SetPaintingStrategy(paintingStrategy); S2.SetPaintingStrategy(paintingStrategy); S3.SetPaintingStrategy(paintingStrategy); S4.SetPaintingStrategy(paintingStrategy); S5.SetPaintingStrategy(paintingStrategy); #Labels AddLabel(showlabels, "R5 " + AsText(R5), Color.RED); AddLabel(showlabels, "R4 " + AsText(R4), Color.RED); AddLabel(showlabels, "R3 " + AsText(R3), Color.RED); AddLabel(showlabels, "R2 " + AsText(R2), Color.RED); AddLabel(showlabels, "R1 " + AsText(R1), Color.RED); AddLabel(showlabels, "S5 " + AsText(S5), Color.GREEN); AddLabel(showlabels, "S4 " + AsText(S4), Color.GREEN); AddLabel(showlabels, "S3 " + AsText(S3), Color.GREEN); AddLabel(showlabels, "S2 " + AsText(S2), Color.GREEN); AddLabel(showlabels, "S1 " + AsText(S1), Color.GREEN); #Bubbles to describe Pivot Levels input bubblemover = 8; def n = bubblemover; def n1 = n + 1; def StartPlot = if showbubbles_description == yes then (IsNaN(close[n]) and !IsNaN(close[n1])) else Double.NaN; AddChartBubble(StartPlot, R5[n1], "R5 " + (if showpricebubble then AsText(R5[n1]) else ""), Color.RED, if close[n1] > R5[n1] then no else yes); AddChartBubble(StartPlot, R4[n1], "R4 " + (if showpricebubble then AsText(R4[n1]) else ""), Color.RED, if close[n1] > R4[n1] then no else yes); AddChartBubble(StartPlot, R3[n1], "R3 " + (if showpricebubble then AsText(R3[n1]) else ""), Color.RED, if close[n1] > R3[n1] then no else yes); AddChartBubble(StartPlot, R2[n1], "R2 " + (if showpricebubble then AsText(R2[n1]) else ""), Color.RED, if close[n1] > R2[n1] then no else yes); AddChartBubble(StartPlot and hide_s1_r1 == no, R1[n1], "R1 " + (if showpricebubble then AsText(R1[n1]) else ""), Color.RED, if close[n1] > R1[n1] then no else yes); AddChartBubble(StartPlot, S5[n1], "S5 " + (if showpricebubble then AsText(S5[n1]) else ""), Color.GREEN, if close[n1] > S5[n1] then no else yes); AddChartBubble(StartPlot, S4[n1], "S4 " + (if showpricebubble then AsText(S4[n1]) else ""), Color.GREEN, if close[n1] > S4[n1] then no else yes); AddChartBubble(StartPlot, S3[n1], "S3 " + (if showpricebubble then AsText(S3[n1]) else ""), Color.GREEN, if close[n1] > S3[n1] then no else yes); AddChartBubble(StartPlot, S2[n1], "S2 " + (if showpricebubble then AsText(S2[n1]) else ""), Color.GREEN, if close[n1] > S2[n1] then no else yes); AddChartBubble(StartPlot and hide_s1_r1 == no, S1[n1], "S1 " + (if showpricebubble then AsText(S1[n1]) else ""), Color.GREEN, if close[n1] > S1[n1] then no else yes); R1.HideBubble(); R2.HideBubble(); R3.HideBubble(); R4.HideBubble(); R5.HideBubble(); S1.HideBubble(); S2.HideBubble(); S3.HideBubble(); S4.HideBubble(); S5.HideBubble(); #S3 Buy Bubble ----------------------------------------------------------- def cond2 = if SecondsFromTime(0930) == 0 then 0 else if Between(open(period = aggregationPeriod), S4, S3) and close crosses above S3 and secondsfromTime(0930)>0 and SecondsTillTime(1600) > 0 then 1 else cond2[1] >= 1 ; AddChartBubble(cond2[1] == 0 and cond2 == 1, low, "Buy", Color.LIGHT_RED, no);
Last edited: