Skip to content

Pivot Points Standard ​

Daily or weekly pivot levels from the previous period, five formulas.

Kind indicator · Drawn on the price pane

Try it ​

On the chart, press / and choose Pivot Points Standard under Support & resistance. To change it, copy the source below into the AlphaScript editor.

Inputs ​

InputTypeDefault
Typeselect"Traditional"
Pivots timeframeselect"1D"
Number of pivots backint15
Show labelsbooltrue
Colorcolor"#FB8C00"

Source ​

From packages/alphascript/indicators/pivots.as.js.

js
indicator({ name: "Pivot Points Standard", shortTitle: "Pivots", overlay: true });
const kind = input.select("Type", "Traditional", ["Traditional", "Fibonacci", "Woodie", "Classic", "Camarilla"]);
const timeframe = input.select("Pivots timeframe", "1D", ["1D", "1W"]);
const back = input.int("Number of pivots back", 15, { min: 1, max: 50 });
const showLabels = input.bool("Show labels", true);
const color = input.color("Color", "#FB8C00", { group: "Style" });
const period = timeframe === "1W" ? 7 * 86400000 : 86400000;
const prevH = request.security(timeframe, (h) => h.candle.high, { confirmed: true });
const prevL = request.security(timeframe, (h) => h.candle.low, { confirmed: true });
const prevC = request.security(timeframe, (h) => h.candle.close, { confirmed: true });
const start = request.security(timeframe, (h) => h.candle.time);
const open = request.security(timeframe, (h) => h.candle.open);
/** @param {number} H @param {number} L @param {number} C @param {number} O @returns {[string, number][]} */
function levels(H, L, C, O) {
  const r = H - L;
  if (kind === "Camarilla") return [["P", (H + L + C) / 3], ["R1", C + (1.1 * r) / 12], ["S1", C - (1.1 * r) / 12], ["R2", C + (1.1 * r) / 6], ["S2", C - (1.1 * r) / 6], ["R3", C + (1.1 * r) / 4], ["S3", C - (1.1 * r) / 4]];
  const P = kind === "Woodie" ? (H + L + 2 * O) / 4 : (H + L + C) / 3;
  if (kind === "Fibonacci") return [["P", P], ["R1", P + 0.382 * r], ["S1", P - 0.382 * r], ["R2", P + 0.618 * r], ["S2", P - 0.618 * r], ["R3", P + r], ["S3", P - r]];
  if (kind === "Classic") return [["P", P], ["R1", 2 * P - L], ["S1", 2 * P - H], ["R2", P + r], ["S2", P - r], ["R3", P + 2 * r], ["S3", P - 2 * r]];
  return [["P", P], ["R1", 2 * P - L], ["S1", 2 * P - H], ["R2", P + r], ["S2", P - r], ["R3", H + 2 * (P - L)], ["S3", L - 2 * (H - P)]];
}
/** @type {number[][]} */
const periods = [];
let drawnFor = NaN;
event.onCandle(() => {
  const t = start.value, H = prevH.value, L = prevL.value, C = prevC.value;
  if (t === drawnFor || !(H === H && L === L && C === C)) return;
  drawnFor = t;
  /** @type {number[]} */
  const ids = [];
  for (const [name, v] of levels(H, L, C, open.value)) {
    ids.push(draw.line({ x1: t, y1: v, x2: t + period, y2: v, color, width: 1 }));
    if (showLabels) ids.push(draw.label({ x: t, y: v, text: name, style: "right", color: "rgba(0,0,0,0)", textColor: color, size: "small" }));
  }
  periods.push(ids);
  while (periods.length > back) for (const id of periods.shift() ?? []) draw.remove(id);
});

AlphaScript language v0.1 · runtime 0.2.0