I was wondering if anyone knew how to edit the plot time for these Camarilla Pivots to look like my IB_Pivot script. I'm guessing it has to do with premarket information perhaps? Basically would like the plotted lines to be within RTH
Camarilla Code
Code:# # TD Ameritrade IP Company, Inc. (c) 2013-2021 #Original by SleepyZ: https://usethinkscript.com/threads/camarilla-pivot-points-for-thinkorswim.696/post-77438 #R5 & S5 Added by Wiinii #Added showtodayonly input showtodayonly = yes; input aggregationPeriod = {default "DAY", "WEEK", "MONTH"}; input length = 1; input hide_s1_r1 = yes; input lines = {default dashes, points, triangles, horizontal, squares}; input showbubbles_description = yes; input showpricebubble = 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 = CompoundValue(1, if start then Highest(high(period = aggregationPeriod), length)[1] else if highValue[1] != 0 then highValue[1] else Double.NaN, high); def lowValue = CompoundValue(1, if start then Lowest(low(period = aggregationPeriod), length)[1] else if lowValue[1] != 0 then lowValue[1] else Double.NaN, low); def closeValue = if showtodayonly and GetDay() != GetLastDay() then Double.NaN else if start then close(period = aggregationPeriod)[1] else closeValue[1]; def range = highValue - lowValue; plot R6 = (highValue / lowValue) * closeValue; plot R4 = closeValue + range * (1.1) / 2; plot R3 = closeValue + range * (1.1) / 4; plot R5 = R4 + 1.168 * (R4 – R3); 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 = S4 - 1.168 * (S3 - S4); plot S6 = (closeValue - (R6 - closeValue)); R1.SetHiding(hide_s1_r1); S1.SetHiding(hide_s1_r1); R6.SetDefaultColor(GetColor(5)); 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)); S6.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; R6.SetPaintingStrategy(paintingStrategy); 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); S6.SetPaintingStrategy(paintingStrategy); #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, R6[n1], "R6 " + (if showpricebubble then AsText(R6[n1]) else ""), Color.RED, if close[n1] > R6[n1] then no else yes); 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, S6[n1], "S6 " + (if showpricebubble then AsText(S6[n1]) else ""), Color.GREEN, if close[n1] > S6[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(); R6.HideBubble(); S1.HideBubble(); S2.HideBubble(); S3.HideBubble(); S4.HideBubble(); S5.HideBubble(); S6.HideBubble();
IB Pivot Code
Code:# IB_Fib_Pivots # Author: Kory Gill, @korygill # # VERSION HISTORY (sortable date and time (your local time is fine), and your initials # 20190906-1900-KG - Created. # ... # ... declare hide_on_daily; declare once_per_bar; input AggregationPeriod = AggregationPeriod.DAY; input LabelsOn = yes; # # logic # def nan = Double.NaN; def isRollover = GetYYYYMMDD() != GetYYYYMMDD()[1]; def beforeStart = GetTime() < RegularTradingStart(GetYYYYMMDD()); def afterEnd = GetTime() > RegularTradingEnd(GetYYYYMMDD()); def firstBarOfDay = if (beforeStart[1] == 1 and beforeStart == 0) or (isRollover and beforeStart == 0) then 1 else 0; def lastBarOfDay = if (afterEnd[-1] == 1 and afterEnd == 0) or (isRollover[-1] and firstBarOfDay[-1]) then 1 else 0; # # See this page for how to calculate the indicator # https://www.interactivebrokers.com/en/software/tws/usersguidebook/technicalanalytics/fibonaccipivotpoints.htm # Pivot Point (P) = (High + Low + Close)/3 # Support 0 (S0) = P- {.236 * (High - Low)} # Support 1 (S1) = P - {.382 * (High - Low)} # Support 2 (S2) = P - {.5 * (High - Low)} # Support 3 (S3) = P - {.618 * (High - Low)} # Support 4 (S4) = P - {.764 * (High - Low)} # Support 5 (S5) = P - {1 * (High - Low)} # Support 6 (S6) = P - {1.236 * (High - Low)} # Resistance 0 (R0) = P + {.236 * (High - Low)} # Resistance 1 (R1) = P + {.382 * (High - Low)} # Resistance 2 (R2) = P + {.5 * (High - Low)} # Resistance 3 (R3) = P + {.618 * (High - Low)} # Resistance 4 (R4) = P + {.764 * (High - Low)} # Resistance 5 (R5) = P + {1 * (High - Low)} # Resistance 5 (R6) = P + {1.236 * (High - Low)} # Resistance 5 (R7) = P + {1.618 * (High - Low)} # def pc = close(period = AggregationPeriod)[1]; def ph = high(period = AggregationPeriod)[1]; def pl = low(period = AggregationPeriod)[1]; #Pivot Point (P) = (High + Low + Close)/3 #Support 0 (S0) = P - {.236 * (High - Low)} #Support 1 (S1) = P - {.382 * (High - Low)} #Support 2 (S2) = P - {.5 * (High - Low)} #Support 3 (S3) = P - {.618 * (High - Low)} #Support 4 (S4) = P - {.764 * (High - Low)} #Support 5 (S5) = P - {1 * (High - Low)} #Support 5 (S5) = P - {1.236 * (High - Low)} #Resistance 0 (R0) = P + {.236 * (High - Low)} #Resistance 1 (R1) = P + {.382 * (High - Low)} #Resistance 2 (R2) = P + {.5 * (High - Low)} #Resistance 3 (R3) = P + {.618 * (High - Low)} #Resistance 4 (R4) = P + {.764 * (High - Low)} #Resistance 5 (R5) = P + {1 * (High - Low)} #Resistance 6 (R6) = P + {1.272 * (High - Low)} #Resistance 7 (R7) = P + {1.618 * (High - Low)} def delta = ph - pl; def pp = if firstBarOfDay then (pc + ph + pl) / 3 else if lastBarOfDay then nan else pp[1]; def s0 = if firstBarOfDay then pp - (.272 * delta) else if lastBarOfDay then nan else s0[1]; def s1 = if firstBarOfDay then pp - (.382 * delta) else if lastBarOfDay then nan else s1[1]; def s2 = if firstBarOfDay then pp - (.5 * delta) else if lastBarOfDay then nan else s2[1]; def s3 = if firstBarOfDay then pp - (.618 * delta) else if lastBarOfDay then nan else s3[1]; def s4 = if firstBarOfDay then pp - (.786 * delta) else if lastBarOfDay then nan else s4[1]; def s5 = if firstBarOfDay then pp - (1 * delta) else if lastBarOfDay then nan else s5[1]; def s6 = if firstBarOfDay then pp - (1.236 * delta) else if lastBarOfDay then nan else s6[1]; def r0 = if firstBarOfDay then pp + (.236 * delta) else if lastBarOfDay then nan else r0[1]; def r1 = if firstBarOfDay then pp + (.382 * delta) else if lastBarOfDay then nan else r1[1]; def r2 = if firstBarOfDay then pp + (.5 * delta) else if lastBarOfDay then nan else r2[1]; def r3 = if firstBarOfDay then pp + (.618 * delta) else if lastBarOfDay then nan else r3[1]; def r4 = if firstBarOfDay then pp + (.786 * delta) else if lastBarOfDay then nan else r4[1]; def r5 = if firstBarOfDay then pp + (.886 * delta) else if lastBarOfDay then nan else r5[1]; def r6 = if firstBarOfDay then pp + (1 * delta) else if lastBarOfDay then nan else r6[1]; def r7 = if firstBarOfDay then pp + (1.236 * delta) else if lastBarOfDay then nan else r7[1]; def r8 = if firstBarOfDay then pp + (1.618 * delta) else if lastBarOfDay then nan else r8[1]; plot ppp = pp; plot ps0 = s0; plot ps1 = s1; plot ps2 = s2; plot ps3 = s3; plot ps4 = s4; plot ps5 = s5; plot ps6 = s6; plot pr0 = r0; plot pr1 = r1; plot pr2 = r2; plot pr3 = r3; plot pr4 = r4; plot pr5 = r5; plot pr6 = r6; plot pr7 = r7; plot pr8 = r8; ppp.SetDefaultColor(Color.BLUE); ps0.SetDefaultColor(Color.GREEN); ps1.SetDefaultColor(Color.GREEN); ps2.SetDefaultColor(Color.GREEN); ps3.SetDefaultColor(Color.GREEN); ps4.SetDefaultColor(Color.GREEN); ps5.SetDefaultColor(CreateColor(231, 133, 0)); ps6.SetDefaultColor(Color.GREEN); pS6.SetPaintingStrategy(PaintingStrategy.LINE); pS6.SetStyle(Curve.SHORT_DASH); pr0.SetDefaultColor(Color.LIGHT_RED); pr1.SetDefaultColor(Color.LIGHT_RED); pr2.SetDefaultColor(Color.LIGHT_RED); pr3.SetDefaultColor(Color.LIGHT_RED); pr4.SetDefaultColor(Color.LIGHT_RED); pr5.SetDefaultColor(Color.LIGHT_RED); pr6.SetDefaultColor(CreateColor(231, 133, 0)); pr7.SetDefaultColor(Color.LIGHT_RED); pr7.SetPaintingStrategy(PaintingStrategy.LINE); pr7.SetStyle(Curve.SHORT_DASH); pr8.SetDefaultColor(Color.LIGHT_RED); pr8.SetPaintingStrategy(PaintingStrategy.LINE); pr8.SetStyle(Curve.SHORT_DASH); #Bubbles input bubblemover = 125; def b = bubblemover; def b1 = b + 1; def Yesterday = GetDay() == GetLastDay() - 1; def BubbleLocation = !yesterday and yesterday[1]; DefineGlobalColor("D”, CreateColor(133, 163, 104)); AddChartBubble(LabelsOn and IsNaN(pp[b1]) and !IsNaN(pp[b]), pp[b], "Pivot", GlobalColor("D")); DefineGlobalColor("D”, CreateColor(133, 163, 104)); AddChartBubble(LabelsOn and IsNaN(r0[b1]) and !IsNaN(r0[b]), r0[b], "23.6%", GlobalColor("D"), LabelsOn); DefineGlobalColor("D”, CreateColor(133, 163, 104)); AddChartBubble(LabelsOn and IsNaN(r3[b1]) and !IsNaN(r3[b]), r3[b], "61.8%", GlobalColor("D"), LabelsOn); DefineGlobalColor("D”, CreateColor(133, 163, 104)); AddChartBubble(LabelsOn and IsNaN(r7[b1]) and !IsNaN(r7[b]), r7[b], "123.6%", GlobalColor("D"), LabelsOn); DefineGlobalColor("D”, CreateColor(133, 163, 104)); AddChartBubble(LabelsOn and IsNaN(r8[b1]) and !IsNaN(r8[b]), r8[b], "161.8%", GlobalColor("D"), LabelsOn); DefineGlobalColor("D”, CreateColor(133, 163, 104)); AddChartBubble(LabelsOn and IsNaN(s0[b1]) and !IsNaN(s0[b]), s0[b], "-27.2%", GlobalColor("D"), LabelsOn); DefineGlobalColor("D”, CreateColor(133, 163, 104)); AddChartBubble(LabelsOn and IsNaN(s1[b1]) and !IsNaN(s1[b]), s1[b], "-38.2%", GlobalColor("D"), LabelsOn); DefineGlobalColor("D”, CreateColor(133, 163, 104)); AddChartBubble(LabelsOn and IsNaN(s3[b1]) and !IsNaN(s3[b]), s3[b], "-61.8%", GlobalColor("D"), LabelsOn); DefineGlobalColor("D”, CreateColor(133, 163, 104)); AddChartBubble(LabelsOn and IsNaN(S4[b1]) and !IsNaN(S4[b]), S4[b], "-78.6%", GlobalColor("D"), LabelsOn); AddChartBubble(BubbleLocation, S5, "100%", Color.DARK_GRAY, yes);
This provides options to show only rthrs
Ruby:# # TD Ameritrade IP Company, Inc. (c) 2013-2021 #Original by SleepyZ: https://usethinkscript.com/threads/camarilla-pivot-points-for-thinkorswim.696/post-77438 #R5 & S5 Added by Wiinii #Added showtodayonly input showtodayonly = no; input showrthrsonly = yes; input aggregationPeriod = {default "DAY", "WEEK", "MONTH"}; input length = 1; input hide_s1_r1 = yes; input lines = {default dashes, points, triangles, horizontal, squares}; input showbubbles = yes; input showpricebubble = 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 = CompoundValue(1, if start then Highest(high(period = aggregationPeriod), length)[1] else if highValue[1] != 0 then highValue[1] else Double.NaN, high); def lowValue = CompoundValue(1, if start then Lowest(low(period = aggregationPeriod), length)[1] else if lowValue[1] != 0 then lowValue[1] else Double.NaN, low); def closeValue = if showtodayonly and GetDay() != GetLastDay() then Double.NaN else if start then close(period = aggregationPeriod)[1] else closeValue[1]; def range = highValue - lowValue; def rthrs = between(gettime(), regularTradingStart(getyyyYMMDD()), regularTradingEnd(getyyyYMMDD())); plot R6 = if showrthrsonly and !rthrs then double.nan else (highValue / lowValue) * closeValue; plot R4 = if showrthrsonly and !rthrs then double.nan else closeValue + range * (1.1) / 2; plot R3 = if showrthrsonly and !rthrs then double.nan else closeValue + range * (1.1) / 4; plot R5 = if showrthrsonly and !rthrs then double.nan else R4 + 1.168 * (R4 – R3); plot R2 = if showrthrsonly and !rthrs then double.nan else closeValue + range * (1.1) / 6; plot R1 = if showrthrsonly and !rthrs then double.nan else closeValue + range * (1.1) / 12; plot S1 = if showrthrsonly and !rthrs then double.nan else closeValue - range * (1.1) / 12; plot S2 = if showrthrsonly and !rthrs then double.nan else closeValue - range * (1.1) / 6; plot S3 = if showrthrsonly and !rthrs then double.nan else closeValue - range * (1.1) / 4; plot S4 = if showrthrsonly and !rthrs then double.nan else closeValue - range * (1.1) / 2; plot S5 = if showrthrsonly and !rthrs then double.nan else S4 - 1.168 * (S3 - S4); plot S6 = if showrthrsonly and !rthrs then double.nan else (closeValue - (R6 - closeValue)); R1.SetHiding(hide_s1_r1); S1.SetHiding(hide_s1_r1); R6.SetDefaultColor(GetColor(5)); 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)); S6.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; R6.SetPaintingStrategy(paintingStrategy); 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); S6.SetPaintingStrategy(paintingStrategy); #Bubbles to describe Pivot Levels input bubblemover = 8; def n = bubblemover; def n1 = n + 1; def StartPlot = if showbubbles and !showrthrsonly then (IsNaN(close[n]) and !IsNaN(close[n1])) else if showbubbles and showrthrsonly then rthrs[n1]==1 and rthrs[n]==0 else Double.NaN; AddChartBubble(StartPlot, R6[n1], "R6 " + (if showpricebubble then AsText(R6[n1]) else ""), Color.RED, if close[n1] > R6[n1] then no else yes); 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, S6[n1], "S6 " + (if showpricebubble then AsText(S6[n1]) else ""), Color.GREEN, if close[n1] > S6[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(); R6.HideBubble(); S1.HideBubble(); S2.HideBubble(); S3.HideBubble(); S4.HideBubble(); S5.HideBubble(); S6.HideBubble();