Get Updates:
Email
Twitter
RSS

Camarilla Pivots

I had a reader request an implementation of the Camarilla pivots. Rather than re-invent the wheel, I grabbed ToS’ new Person’s Pivots script, jammed in the Camarilla formulas, cut out some extra plumbing, and voilĂ . By default the pivot, H1, H2, L1, and L2 levels are hidden. My quick research of these pivots suggested the H3/H4, L3/L4 levels are where the heavy lifting is done. (There is a bug in ThinkScript that makes the dot size a bit large for my taste but until ToS fixes it we’re stuck.)

Camarilla Pivots

Camarilla Pivots

# CAMARILLAPIVOTS
# (c) 2009 http://www.thinkscripter.com
# thinkscripter@gmail.com
# Last Update 08 Feb 2009

input timeFrame = {default DAY, WEEK, MONTH};
input showOnlyToday = no;

def H = high(period = timeFrame)[1];
def L = low(period = timeFrame)[1];
def C = close(period = timeFrame)[1];

def R = H-L;
def calc_PP = (H + L + C) / 3;
def calc_H1 = C+(R*1.1/12);
def calc_H2 = C+(R*1.1/6);
def calc_H3 = C+(R*1.1/4);
def calc_H4 = C+(R*1.1/2);
def calc_L1 = C-(R*1.1/12);
def calc_L2 = C-(R*1.1/6);
def calc_L3 = C-(R*1.1/4);
def calc_L4 = C-(R*1.1/2);

plot H4;
plot H3;
plot H2;
plot H1;
plot PP;
plot L1;
plot L2;
plot L3;
plot L4;

PP.hide();
H1.hide();
H2.hide();
L1.hide();
L2.hide();

if (showOnlyToday and !IsNaN(close(period = timeFrame)[-1])) or
(getAggregationPeriod() > if timeframe == timeframe.DAY then AggregationPeriod.DAY else if timeframe == timeframe.WEEK then AggregationPeriod.WEEK else AggregationPeriod.MONTH)
then {
H1 = Double.NaN;
H2 = Double.NaN;
H3 = Double.NaN;
H4 = Double.NaN;
PP = Double.NaN;
L1 = Double.NaN;
L2 = Double.NaN;
L3 = Double.NaN;
L4 = double.NaN;
}
else {
H1 = calc_H1;
H2 = calc_H2;
H3 = calc_H3;
H4 = calc_H4;
PP = calc_PP;
L1 = calc_L1;
L2 = calc_L2;
L3 = calc_L3;
L4 = calc_L4;
}

PP.SetPaintingStrategy(if timeframe == timeframe.DAY then PaintingStrategy.LINE_VS_POINTS else if timeframe == timeframe.WEEK then PaintingStrategy.LINE_VS_TRIANGLES else PaintingStrategy.LINE_VS_SQUARES);
H1.SetPaintingStrategy(if timeframe == timeframe.DAY then PaintingStrategy.LINE_VS_POINTS else if timeframe == timeframe.WEEK then PaintingStrategy.LINE_VS_TRIANGLES else PaintingStrategy.LINE_VS_SQUARES);
H2.SetPaintingStrategy(if timeframe == timeframe.DAY then PaintingStrategy.LINE_VS_POINTS else if timeframe == timeframe.WEEK then PaintingStrategy.LINE_VS_TRIANGLES else PaintingStrategy.LINE_VS_SQUARES);
H3.SetPaintingStrategy(if timeframe == timeframe.DAY then PaintingStrategy.LINE_VS_POINTS else if timeframe == timeframe.WEEK then PaintingStrategy.LINE_VS_TRIANGLES else PaintingStrategy.LINE_VS_SQUARES);
H4.SetPaintingStrategy(if timeframe == timeframe.DAY then PaintingStrategy.LINE_VS_POINTS else if timeframe == timeframe.WEEK then PaintingStrategy.LINE_VS_TRIANGLES else PaintingStrategy.LINE_VS_SQUARES);

L1.SetPaintingStrategy(if timeframe == timeframe.DAY then PaintingStrategy.LINE_VS_POINTS else if timeframe == timeframe.WEEK then PaintingStrategy.LINE_VS_TRIANGLES else PaintingStrategy.LINE_VS_SQUARES);
L2.SetPaintingStrategy(if timeframe == timeframe.DAY then PaintingStrategy.LINE_VS_POINTS else if timeframe == timeframe.WEEK then PaintingStrategy.LINE_VS_TRIANGLES else PaintingStrategy.LINE_VS_SQUARES);
L3.SetPaintingStrategy(if timeframe == timeframe.DAY then PaintingStrategy.LINE_VS_POINTS else if timeframe == timeframe.WEEK then PaintingStrategy.LINE_VS_TRIANGLES else PaintingStrategy.LINE_VS_SQUARES);
L4.SetPaintingStrategy(if timeframe == timeframe.DAY then PaintingStrategy.LINE_VS_POINTS else if timeframe == timeframe.WEEK then PaintingStrategy.LINE_VS_TRIANGLES else PaintingStrategy.LINE_VS_SQUARES);

PP.SetDefaultColor(GetColor(0));
H1.SetDefaultColor(GetColor(5));
H2.SetDefaultColor(GetColor(5));
H3.SetDefaultColor(GetColor(5));
H4.SetDefaultColor(GetColor(5));
L1.SetDefaultColor(GetColor(6));
L2.SetDefaultColor(GetColor(6));
L3.SetDefaultColor(GetColor(6));
L4.SetDefaultColor(GetColor(6));

PP.SetStyle(Curve.POINTS);
H1.SetStyle(Curve.POINTS);
H2.SetStyle(Curve.POINTS);
H3.SetStyle(Curve.POINTS);
H4.SetStyle(Curve.POINTS);
L1.SetStyle(Curve.POINTS);
L2.SetStyle(Curve.POINTS);
L3.SetStyle(Curve.POINTS);
L4.SetStyle(Curve.POINTS);

9 Responses to “Camarilla Pivots”

  1. Danny says:

    This is a great blog, thank you for the work. I am trying to learn thinkscript and appreciate the work.

  2. Alan says:

    Hi,

    Thanks for all this great stuff. I loaded this study … It doesn’t plot correctly on 1-20-08 for some reason. I am using a 5 min chart of bgu (20 days).

    Thanks Again!

  3. Ron says:

    If you can remember which study you are looking, (day, week, month) then just “#” the SetPaintingStrategy instructions and pick your line style from the Plots Box. You get a nice thin line.
    By the way, there is some great stuff at your site—many thanks.

  4. Alan says:

    Why is there a “SetPaintingStrategy” for all the plots AND a “SetStyle” setting at the end of the code. The two must overlap each other. The same plots are being given two different styles at the same time.

  5. Gary Deckert says:

    Do you know if anyone has written the thinkscript formulas for TOS for Chandlier Stops?

    Regards
    Gary Deckert

  6. thinkscripter says:

    Why yes Gary – Me!

    The ThinkScripter Multi-Stops is a combination of Average True Range, Wilder’s Average, Chandelier, Elder SafeZone, and Fibonacci stops. You choose which type of stop you want, set the volatility coefficient and look-back length and you’re set.

    -Eric

  7. DougSF says:

    Wow! Worked straight away! Those lines sure are sharpie-thick. Very cool, I’m getting my donate $$ together, thank you!

  8. thinkscripter says:

    Alan,
    That was a long weekend and my guess is that when the script queries the ToS data for the previous day’s high, low, and close, it gets garbage back in return. Their data works properly over normal weekends but apparently not for unusual weekends.
    -TS

  9. thinkscripter says:

    As I stated above, this is a hacked version of ToS’ Person’s Pivots study. I don’t like the extraneous lines between the pivot levels that you get with the ToS code, so I modified the code to suit me.

Leave a Reply