mod note:
Calculates classic floor‑trader pivot levels using 4‑hour candles, then projects those levels onto any intraday chart.
A day trader wants 4‑hour levels because they give a clean, higher‑timeframe map that doesn’t flicker or recalc intraday, letting you instantly see where price is likely to react, stall, or break with conviction. They act as stable decision zones—helping you avoid bad entries directly into support or resistance, time exits more cleanly, and judge strength or weakness without adding noise or clutter to the chart.
Calculates classic floor‑trader pivot levels using 4‑hour candles, then projects those levels onto any intraday chart.
A day trader wants 4‑hour levels because they give a clean, higher‑timeframe map that doesn’t flicker or recalc intraday, letting you instantly see where price is likely to react, stall, or break with conviction. They act as stable decision zones—helping you avoid bad entries directly into support or resistance, time exits more cleanly, and judge strength or weakness without adding noise or clutter to the chart.
| Plot Name | Level Type | Meaning | Color |
|---|---|---|---|
| PivotLinebrk | Pivot (P) | Central reference level from prior 4H candle | Yellow |
| Res1Line | R1 | First resistance above pivot | Red |
| Res2Line | R2 | Second resistance above pivot | Red |
| Res3Line | R3 | Third resistance above pivot | Red |
| Res4Line | R4 | Fourth resistance above pivot | Red |
| Sup1Line | S1 | First support below pivot | Green |
| Sup2Line | S2 | Second support below pivot | Green |
| Sup3Line | S3 | Third support below pivot | Green |
| Sup4Line | S4 | Fourth support below pivot | Green |
Code:
# ===== 4 hour levels=====
def showP = 1;
def showSR = 1;
# ===== 4H DATA =====
def agg = AggregationPeriod.FOUR_HOURS;
def h4H = high(period = agg);
def h4L = low(period = agg);
def h4C = close(period = agg);
def new4H = h4H != h4H[1];
rec piv;
rec r1v;
rec r2v;
rec r3v;
rec r4v;
rec s1v;
rec s2v;
rec s3v;
rec s4v;
if new4H then {
piv = (h4H[1] + h4L[1] + h4C[1]) / 3;
r1v = 2 * piv - h4L[1];
r2v = piv + (h4H[1] - h4L[1]);
r3v = h4H[1] + 2 * (piv - h4L[1]);
r4v = r3v + (h4H[1] - h4L[1]);
s1v = 2 * piv - h4H[1];
s2v = piv - (h4H[1] - h4L[1]);
s3v = h4L[1] - 2 * (h4H[1] - piv);
s4v = s3v - (h4H[1] - h4L[1]);
} else {
piv = piv[1];
r1v = r1v[1];
r2v = r2v[1];
r3v = r3v[1];
r4v = r4v[1];
s1v = s1v[1];
s2v = s2v[1];
s3v = s3v[1];
s4v = s4v[1];
}
# ===== PLOTS =====
plot PivotLinebrk = if showP then piv else Double.NaN;
plot Res1Line = if showSR then r1v else Double.NaN;
plot Res2Line = if showSR then r2v else Double.NaN;
plot Res3Line = if showSR then r3v else Double.NaN;
plot Res4Line = if showSR then r4v else Double.NaN;
plot Sup1Line = if showSR then s1v else Double.NaN;
plot Sup2Line = if showSR then s2v else Double.NaN;
plot Sup3Line = if showSR then s3v else Double.NaN;
plot Sup4Line = if showSR then s4v else Double.NaN;
# ===== COLOR & STYLES=====
PivotLinebrk.SetDefaultColor(Color.YELLOW);
PivotLinebrk.SetPaintingStrategy(PaintingStrategy.POINTS);
Res1Line.SetDefaultColor(Color.RED);
Res1Line.SetPaintingStrategy(PaintingStrategy.POINTS);
Res2Line.SetDefaultColor(Color.RED);
Res2Line.SetPaintingStrategy(PaintingStrategy.POINTS);
Res3Line.SetDefaultColor(Color.RED);
Res3Line.SetPaintingStrategy(PaintingStrategy.POINTS);
Res4Line.SetDefaultColor(Color.RED);
Res4Line.SetPaintingStrategy(PaintingStrategy.POINTS);
Sup1Line.SetDefaultColor(Color.GREEN);
Sup1Line.SetPaintingStrategy(PaintingStrategy.POINTS);
Sup2Line.SetDefaultColor(Color.GREEN);
Sup2Line.SetPaintingStrategy(PaintingStrategy.POINTS);
Sup3Line.SetDefaultColor(Color.GREEN);
Sup3Line.SetPaintingStrategy(PaintingStrategy.POINTS);
Sup4Line.SetDefaultColor(Color.GREEN);
Sup4Line.SetPaintingStrategy(PaintingStrategy.POINTS);
Last edited by a moderator: