Camarilla Pivot Points for ThinkOrSwim

Reading through these posts...I have a similar question as several above: Is there a script for including pre and aftermarket hours when making the calculations?
So instead of using normal market hours, the highs and lows would be based on the hours between 0400-2000. And the close would be the price at 2000.
@rikinroy
Camarilla is a daily indicator. The ToS platform looks at "daily" as a single bar. The ToS platform does not provide for scripting, plotting, labeling, scanning, watchlisting in increments less than one bar.
 
Last edited:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

@rikinroy
Camarilla is a daily indicator. The ToS platform looks at "daily" as a single bar. It does not provide for scripting, plotting, labeling, scanning, watchlisting in increments less than a day.
@MerryDay Make sense, so we can not do it in TOS. Is there any other way you can think I can make this work? any other 3rd party software or website which will allow something like this?
 
CamarillaPivot Scanner - compared to previous day
Ola
, I would like to create a Scanner based on CamarillaPivot value. Below is a little detail about the CamarillaPivot study.
CamarillaPivot is a daily indicator. The TOS platform looks at "daily" as a single bar.
CamarillaPivot has levels (from S5 to R5). TOS has 5 support and 5 Resistance level, which are S1, S2, S3, S4, S5, R1, R2, R3, R4 and R5.
CamarillaPivot gets updated/added at 4am EST in TOS

Scanner Requirement -
I am looking to run this scanner every morning, around 7am EST.

Is there a way we can create a scanner that looks at the previous day's high and low Camarilla-Levels and compared to today's camarilla-Levels, if we can see today's high and low level is inside than previous day's high and low then it will give me a list of stocks?

Please see the example below -
1ViOcCx.png


above example, you can see that the current high/low of camarilla-levels are inside than the previous day's high/low. that's all I am looking for.
@MerryDay - Do you have any example of the scanner? on how to do it? - thank you in advance!

Thank you,
Rik
 
Last edited by a moderator:
@MerryDay @zeek Is there a way we can create a study to forecast tomorrow's CamarillaPivot range based on today's value once the market is closed? CamarillaPivot range is based on the last high, low and close price so I think it is doable. - thank you
 
Last edited:
@MerryDay @zeek Is there a way we can create a study to forecast tomorrow's CamarillaPivot range based on today's value once the market is closed? CamarillaPivot range is based on the last high, low and close price so I think it is doable. - thank you
It requires changing the essence of the Camarilla. I am not willing to go there.
 
It requires changing the essence of the Camarilla. I am not willing to go there.
@MerryDay - Do you have any sample/example similar code on how it is doable -

My strategy is to look for the inside camarilla range than yesterday, if you have any similar example study to forecast tomorrow's level based on today's value then I can modify and play. As CamarillaPivot range is based on the last high, low and close price so once today's market is closed, I can prepare for tomorrow. - Thank you!
 
@MerryDay - Do you have any sample/example similar code on how it is doable -

My strategy is to look for the inside camarilla range than yesterday, if you have any similar example study to forecast tomorrow's level based on today's value then I can modify and play. As CamarillaPivot range is based on the last high, low and close price so once today's market is closed, I can prepare for tomorrow. - Thank you!

Other suggestions:
You already commented in the other Camarilla thread which has the option to plot previous day pivots. So I am assuming you have already been through all these links. But I am providing them for future readers of this thread:
https://usethinkscript.com/threads/day-trading-with-pivots-for-thinkorswim.7943/
And as that thread mentioned, similar plots can be found playing with the DTR
As Future Tony mentioned in that thread, he also provided this:
https://usethinkscript.com/threads/time-range-comparison-for-thinkorswim.7978/

Nothing much further to add other than have you tried applying a CPR or a DCPR? Not the same but sometimes a different POV helps.
https://usethinkscript.com/threads/central-pivot-range-cpr-indicator-for-thinkorswim.1305/
https://usethinkscript.com/threads/developing-central-pivot-range-dcpr-for-thinkorswim.9948/
 
@MerryDay - Do you have any sample/example similar code on how it is doable -

My strategy is to look for the inside camarilla range than yesterday, if you have any similar example study to forecast tomorrow's level based on today's value then I can modify and play. As CamarillaPivot range is based on the last high, low and close price so once today's market is closed, I can prepare for tomorrow. - Thank you!

The Camarillo Pivots indicator already computes and plots the next day's/period's points. You can see these if you set the time axis in chart settings wide enough to see them. Added below is definitions for each point and a label option to display them real time. These are not fixed until the close of trading for the current day.

Capture.jpg

Ruby:
#
# TD Ameritrade IP Company, Inc. (c) 2013-2022
#
# Camirillot Pivots - Added a label to display the Cam Pivots Projected for the next day

input aggregationPeriod = {default "DAY", "WEEK", "MONTH"};
input length = 25;

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));
}
input offset = 1;
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)[offset] else if highValue[1] != 0 then highValue[1] else Double.NaN;
def lowValue = if start then Lowest(low(period = aggregationPeriod), length)[offset] else if lowValue[1] != 0 then lowValue[1] else Double.NaN;
def closeValue = if start then close(period = aggregationPeriod)[offset] 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.Hide();
S1.Hide();

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 aggregationPeriod == aggregationPeriod.DAY then PaintingStrategy.POINTS else if aggregationPeriod == aggregationPeriod.WEEK then PaintingStrategy.TRIANGLES 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);

#Next Day's Projected Camarillo Pivots
def highValue0 = Highest(high(period = aggregationPeriod), length);
def lowValue0 = Lowest(low(period = aggregationPeriod), length);
def closeValue0 = close(period = aggregationPeriod);
def range0 = highValue0 - lowValue0;
input showProjected = yes;
def R50 = (highValue0 / lowValue0) * closeValue0;
def R40 = closeValue0 + range0 * (1.1) / 2;
def R30 = closeValue0 + range0 * (1.1) / 4;
def R20 = closeValue0 + range0 * (1.1) / 6;
def R10 = closeValue0 + range0 * (1.1) / 12;
def S10 = closeValue0 - range0 * (1.1) / 12;
def S20 = closeValue0 - range0 * (1.1) / 6;
def S30 = closeValue0 - range0 * (1.1) / 4;
def S40 = closeValue0 - range0 * (1.1) / 2;
def S50 = (closeValue0 - (R50 - closeValue0));

input showProjectedlabel = yes;
defineGlobalColor("R", color.DARK_ORANGE);
defineGlobalColor("S", color.LIGHT_GREEN);
addlabel(showProjectedlabel, "Projected", color.white);
addlabel(showProjectedlabel, " R5: " + astext(R50)+ " R4: " + astext(R40) + " R3: " + astext(R30) + " R2: " + astext(R20) + " R1: " + astext(R10), globalColor("R"));
addlabel(showProjectedlabel, " S1: " + astext(S10)+ " S2: " + astext(S20) + " S3: " + astext(S30) + " S4: " + astext(S40) + " S5: " + astext(S50), globalColor("S"));
 
Last edited:
I see the S and R levels. Does it show the actual PP?

The TOS Camarillo Points does not include or explain how to use actual PP with the Camarillo Points.

You can however add the following PP code to the above code just after the definitions of the values used to compute the PP.

See the TOS Education Tab for a further explanation of how TOS recommends using this indicator.

Code:
plot PP = (highValue + lowValue + closeValue) / 3;
PP.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PP.SetLineWeight(3);
 
The Camarillo Pivots indicator already computes and plots the next day's/period's points. You can see these if you set the time axis in chart settings wide enough to see them. Added below is definitions for each point and a label option to display them real time. These are not fixed until the close of trading for the current day.

Thank you @SleepyZ @MerryDay - I sent an email to Thinkorswim and their response was below -

"I'd be happy to assist. I see the issue the scan tab is running into. It is a system limitation that the scan tab can't use daily aggregation for its scan and then apply that scan intraday. In essence it can't scan for daily based data until that new day has begun.

The good news is we can bypass this issue. Given that the CamarillaPivot is taking data from a previous day in order to generate the lines for the current day we have the necessary data in the premarket to generate the calculations. The following study lacks the flexibility of the CamarillaPivots but should meet your needs.



plot R5 = (high / low) * close;
plot R4= (high - low) *1.1/2 +close;
plot R3= (high - low) *1.1/4 +close;
plot R2= (high - low) *1.1/6 +close;
plot R1= (high - low) *1.1/12 +close;
plot S1= Close -(high-low)*1.1/12;
plot S2= Close -(high-low)*1.1/6;
plot S3= Close -(high-low)*1.1/4;
plot S4= Close -(high-low)*1.1/2;
plot S5 = (close - (R5 - close));

The above script will only work within a daily aggregation, but otherwise produces lines identical to CamarillaPivots one day earlier. This will bridge the gap during extended hours, while your previous work should do nicely for all other times."

The above was from TOS support team - I did try to add the above R5 to S5 variables to the current camarilla-Pivot Study, but it does not work?

Can anyone else give it a try and see if we can use the above logic in Camarilla and if that works?
 
Last edited:
It shows bubbles (labels at the lines). If you are wanting labels at the top of the chart, it is now an option in the code below.
It shows bubbles (labels at the lines). If you are wanting labels at the top of the chart, it is now an option in the code below.

Hi @SleepyZ Thanks for the amazing script. One clarification though, if I set the length to 1 it calculates the pivots using yesterday's bar, correct? If so the same will apply for weekly and monthly aggregation. BTW is there any benefit to using more than a day? I assume it will use the average of price points over those days. Thanks
 
Last edited by a moderator:
Hello I have camarilla pivot code. This shows pivot points for all days. How do I turn off previous days pivot lines and only shows for today. I ama not coder and if anyone can help, I appreciate a lot. Thank you.

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

input aggregationPeriod = {default "DAY", "WEEK", "MONTH"};
input length = 25;
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 = 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 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(6));
R5.SetDefaultColor(GetColor(6));
R4.SetDefaultColor(GetColor(6));
R3.SetDefaultColor(GetColor(6));
R2.SetDefaultColor(GetColor(6));
R1.SetDefaultColor(GetColor(6));
S1.SetDefaultColor(GetColor(5));
S2.SetDefaultColor(GetColor(5));
S3.SetDefaultColor(GetColor(5));
S4.SetDefaultColor(GetColor(5));
S5.SetDefaultColor(GetColor(5));
S6.SetDefaultColor(GetColor(5));

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.GREEN, if close[n1] > R6[n1] then no else yes);
AddChartBubble(StartPlot, R5[n1], "R5 " + (if showpricebubble then AsText(R5[n1]) else ""), Color.GREEN, if close[n1] > R5[n1] then no else yes);
AddChartBubble(StartPlot, R4[n1], "R4 " + (if showpricebubble then AsText(R4[n1]) else ""), Color.GREEN, if close[n1] > R4[n1] then no else yes);
AddChartBubble(StartPlot, R3[n1], "R3 " + (if showpricebubble then AsText(R3[n1]) else ""), Color.GREEN, if close[n1] > R3[n1] then no else yes);
AddChartBubble(StartPlot, R2[n1], "R2 " + (if showpricebubble then AsText(R2[n1]) else ""), Color.GREEN, 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.GREEN, if close[n1] > R1[n1] then no else yes);

AddChartBubble(StartPlot, S6[n1], "S6 " + (if showpricebubble then AsText(S6[n1]) else ""), Color.RED, if close[n1] > S6[n1] then no else yes);
AddChartBubble(StartPlot, S5[n1], "S5 " + (if showpricebubble then AsText(S5[n1]) else ""), Color.RED, if close[n1] > S5[n1] then no else yes);
AddChartBubble(StartPlot, S4[n1], "S4 " + (if showpricebubble then AsText(S4[n1]) else ""), Color.RED, if close[n1] > S4[n1] then no else yes);
AddChartBubble(StartPlot, S3[n1], "S3 " + (if showpricebubble then AsText(S3[n1]) else ""), Color.RED, if close[n1] > S3[n1] then no else yes);
AddChartBubble(StartPlot, S2[n1], "S2 " + (if showpricebubble then AsText(S2[n1]) else ""), Color.RED, 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.RED, 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();
 
Hello I have camarilla pivot code. This shows pivot points for all days. How do I turn off previous days pivot lines and only shows for today. I ama not coder and if anyone can help, I appreciate a lot. Thank you.

Added input showtodayonly and changed default to input length of 1

Capture.jpg
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     = 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(6));
R5.SetDefaultColor(GetColor(6));
R4.SetDefaultColor(GetColor(6));
R3.SetDefaultColor(GetColor(6));
R2.SetDefaultColor(GetColor(6));
R1.SetDefaultColor(GetColor(6));
S1.SetDefaultColor(GetColor(5));
S2.SetDefaultColor(GetColor(5));
S3.SetDefaultColor(GetColor(5));
S4.SetDefaultColor(GetColor(5));
S5.SetDefaultColor(GetColor(5));
S6.SetDefaultColor(GetColor(5));

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.GREEN, if close[n1] > R6[n1] then no else yes);
AddChartBubble(StartPlot, R5[n1], "R5 " + (if showpricebubble then AsText(R5[n1]) else ""), Color.GREEN, if close[n1] > R5[n1] then no else yes);
AddChartBubble(StartPlot, R4[n1], "R4 " + (if showpricebubble then AsText(R4[n1]) else ""), Color.GREEN, if close[n1] > R4[n1] then no else yes);
AddChartBubble(StartPlot, R3[n1], "R3 " + (if showpricebubble then AsText(R3[n1]) else ""), Color.GREEN, if close[n1] > R3[n1] then no else yes);
AddChartBubble(StartPlot, R2[n1], "R2 " + (if showpricebubble then AsText(R2[n1]) else ""), Color.GREEN, 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.GREEN, if close[n1] > R1[n1] then no else yes);

AddChartBubble(StartPlot, S6[n1], "S6 " + (if showpricebubble then AsText(S6[n1]) else ""), Color.RED, if close[n1] > S6[n1] then no else yes);
AddChartBubble(StartPlot, S5[n1], "S5 " + (if showpricebubble then AsText(S5[n1]) else ""), Color.RED, if close[n1] > S5[n1] then no else yes);
AddChartBubble(StartPlot, S4[n1], "S4 " + (if showpricebubble then AsText(S4[n1]) else ""), Color.RED, if close[n1] > S4[n1] then no else yes);
AddChartBubble(StartPlot, S3[n1], "S3 " + (if showpricebubble then AsText(S3[n1]) else ""), Color.RED, if close[n1] > S3[n1] then no else yes);
AddChartBubble(StartPlot, S2[n1], "S2 " + (if showpricebubble then AsText(S2[n1]) else ""), Color.RED, 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.RED, 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();
 
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
PP-1.png

PP-2.png




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);
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
268 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

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.

How do I get started?

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.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top