Skip to content

Pivot Points High Low ​

Labels at swing highs and lows confirmed N bars later.

Kind indicator · Drawn on the price pane

Try it ​

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

Inputs ​

InputTypeDefault
Pivot high leftint10
Pivot high rightint10
Pivot low leftint10
Pivot low rightint10
High colorcolor"#089981"
Low colorcolor"#F23645"

Source ​

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

js
indicator({ name: "Pivot Points High Low", shortTitle: "Pivots HL", overlay: true });
const highLeft = input.int("Pivot high left", 10, { min: 1 }), highRight = input.int("Pivot high right", 10, { min: 1 });
const lowLeft = input.int("Pivot low left", 10, { min: 1 }), lowRight = input.int("Pivot low right", 10, { min: 1 });
const highColor = input.color("High color", "#089981", { group: "Style" }), lowColor = input.color("Low color", "#F23645", { group: "Style" });
const ph = ta.pivothigh(highLeft, highRight), pl = ta.pivotlow(lowLeft, lowRight);
/** @param {number} p */
const fmt = (p) => { const d = p > 0 ? math.max(2, 4 - math.floor(math.log(p) / math.log(10))) : 2; return String(math.round(p, d)); };
event.onCandle(() => {
  if (ph.value === ph.value) draw.label({ x: candle.time.at(highRight), y: ph.value, text: fmt(ph.value), style: "down", color: highColor, size: "small" });
  if (pl.value === pl.value) draw.label({ x: candle.time.at(lowRight), y: pl.value, text: fmt(pl.value), style: "up", color: lowColor, size: "small" });
});

AlphaScript language v0.1 · runtime 0.2.0