mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-07-27 17:27:43 +00:00
63 lines
2.9 KiB
Plaintext
63 lines
2.9 KiB
Plaintext
// Licensed under the Apache License, Version 2.0
|
|
// © mihakralj
|
|
//@version=6
|
|
indicator("Pivot Points (Extended)", "PIVOTEXT", overlay=true)
|
|
|
|
//@function Calculates extended traditional pivot points with R4-R5 and S4-S5 levels
|
|
//@param tf Timeframe for pivot calculation ("D", "W", "M")
|
|
//@returns Tuple [pp, r1, r2, r3, r4, r5, s1, s2, s3, s4, s5] with pivot levels
|
|
//@references Extended floor trader pivot formula
|
|
pivotext(simple string tf) =>
|
|
[hi, lo, cl] = request.security(syminfo.tickerid, tf, [high[1], low[1], close[1]], lookahead=barmerge.lookahead_on)
|
|
if na(hi) or na(lo) or na(cl)
|
|
[na, na, na, na, na, na, na, na, na, na, na]
|
|
else
|
|
float pp = (hi + lo + cl) / 3.0
|
|
float hl_range = hi - lo
|
|
float r1 = 2.0 * pp - lo
|
|
float s1 = 2.0 * pp - hi
|
|
float r2 = pp + hl_range
|
|
float s2 = pp - hl_range
|
|
float r3 = hi + 2.0 * (pp - lo)
|
|
float s3 = lo - 2.0 * (hi - pp)
|
|
float r4 = hi + 3.0 * (pp - lo)
|
|
float s4 = lo - 3.0 * (hi - pp)
|
|
float r5 = hi + 4.0 * (pp - lo)
|
|
float s5 = lo - 4.0 * (hi - pp)
|
|
[pp, r1, r2, r3, r4, r5, s1, s2, s3, s4, s5]
|
|
|
|
// ---------- Main loop ----------
|
|
|
|
// Inputs
|
|
i_timeframe = input.timeframe("D", "Pivot Timeframe", options=["D", "W", "M"])
|
|
i_show_pp = input.bool(true, "Show Pivot Point")
|
|
i_show_r1 = input.bool(true, "Show R1")
|
|
i_show_r2 = input.bool(true, "Show R2")
|
|
i_show_r3 = input.bool(true, "Show R3")
|
|
i_show_r4 = input.bool(true, "Show R4")
|
|
i_show_r5 = input.bool(true, "Show R5")
|
|
i_show_s1 = input.bool(true, "Show S1")
|
|
i_show_s2 = input.bool(true, "Show S2")
|
|
i_show_s3 = input.bool(true, "Show S3")
|
|
i_show_s4 = input.bool(true, "Show S4")
|
|
i_show_s5 = input.bool(true, "Show S5")
|
|
i_color_pp = input.color(color.yellow, "PP Color")
|
|
i_color_r = input.color(color.red, "Resistance Color")
|
|
i_color_s = input.color(color.green, "Support Color")
|
|
|
|
// Calculation
|
|
[pp, r1, r2, r3, r4, r5, s1, s2, s3, s4, s5] = pivotext(i_timeframe)
|
|
|
|
// Plot
|
|
plot(i_show_pp ? pp : na, "PP", color=i_color_pp, linewidth=2, style=plot.style_stepline)
|
|
plot(i_show_r1 ? r1 : na, "R1", color=i_color_r, linewidth=1, style=plot.style_stepline)
|
|
plot(i_show_r2 ? r2 : na, "R2", color=i_color_r, linewidth=1, style=plot.style_stepline)
|
|
plot(i_show_r3 ? r3 : na, "R3", color=i_color_r, linewidth=1, style=plot.style_stepline)
|
|
plot(i_show_r4 ? r4 : na, "R4", color=i_color_r, linewidth=1, style=plot.style_stepline)
|
|
plot(i_show_r5 ? r5 : na, "R5", color=i_color_r, linewidth=1, style=plot.style_stepline)
|
|
plot(i_show_s1 ? s1 : na, "S1", color=i_color_s, linewidth=1, style=plot.style_stepline)
|
|
plot(i_show_s2 ? s2 : na, "S2", color=i_color_s, linewidth=1, style=plot.style_stepline)
|
|
plot(i_show_s3 ? s3 : na, "S3", color=i_color_s, linewidth=1, style=plot.style_stepline)
|
|
plot(i_show_s4 ? s4 : na, "S4", color=i_color_s, linewidth=1, style=plot.style_stepline)
|
|
plot(i_show_s5 ? s5 : na, "S5", color=i_color_s, linewidth=1, style=plot.style_stepline)
|