Trapoints
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © sateriok
//@version=5
indicator("Trapoints", shorttitle = "TP", overlay = true)

//Inputs
show_c = input(true, title = "Display", group = "Traparilla")
i_c_tf = input.timeframe("D", title = "Resolution", options=["D", "W", "M"], 
  tooltip = "Look at using the weekly resolution if you are on the hourly timeframe or higher.",
  group = "Traparilla")

show_f = input(true, title = "Display", group = "Trapanacci")
i_f_tf = input.timeframe("", title = "Resolution", group = "Trapanacci")

//Price Data

//Traparilla
[_close, _low, _high, _open] = request.security(syminfo.tickerid, i_c_tf, [close[1], low[1], high[1], open[1]], 
 lookahead = barmerge.lookahead_on)

//Trapanacci
[f_close, f_low, f_high, f_open] = request.security(syminfo.tickerid, i_f_tf, [close[1], low[1], high[1], open[1]], 
 lookahead = barmerge.lookahead_on)

//Colors
c5 = _open != _open[1] ? na : color.red
c4 = _open != _open[1] ? na : color.orange
c3 = _open != _open[1] ? na : color.green
c2 = _open != _open[1] ? na : color.yellow
c1 = _open != _open[1] ? na : color.silver
c0 = _open != _open[1] ? na : color.white

//Floor Pivots
floor_pivot = (_high + _low + _close) / 3
floor_l1 = (floor_pivot * 2) - _high
floor_l2 = floor_pivot - (_high - _low)
floor_l3 = _low - 2 * (_high - floor_pivot)
floor_h1 = (floor_pivot * 2) - _low
floor_h2 = floor_pivot + (_high - _low)
floor_h3 = _high + 2 * (floor_pivot - _low)

//Traparilla Pivots
r = _high - _low
center = (_close)
h1 = _close + r * (1.1 / 12)
h2 = _close + r * (1.1 / 6)
h3 = _close + r * (1.1 / 4)
h4 = _close + r * (1.1 / 2)
h5 = (_high / _low) * _close
l1 = _close - r * (1.1 / 12)
l2 = _close - r * (1.1 / 6)
l3 = _close - r * (1.1 / 4)
l4 = _close - r * (1.1 / 2)
l5 = _close - (h5 - _close)

//Trapanacci Pivots
fib_h5 = floor_pivot + ((_high - _low) * 1.000)
fib_h4 = floor_pivot + ((_high - _low) * 0.786)
fib_h3 = floor_pivot + ((_high - _low) * 0.618)
fib_h2 = floor_pivot + ((_high - _low) * 0.500)
fib_h1 = floor_pivot + ((_high - _low) * 0.382)
fib_l1 = floor_pivot - ((_high - _low) * 0.382)
fib_l2 = floor_pivot - ((_high - _low) * 0.500)
fib_l3 = floor_pivot - ((_high - _low) * 0.618)
fib_l4 = floor_pivot - ((_high - _low) * 0.786)
fib_l5 = floor_pivot - ((_high - _low) * 1.000)

//Traparilla Plots
plot(show_c ? math.round_to_mintick(h5) : na, title = "Traparilla H5", style = plot.style_line, linewidth = 1, color = c5)
plot(show_c ? math.round_to_mintick(h4) : na, title = "Traparilla H4", style = plot.style_line, linewidth = 1, color = c4)
plot(show_c ? math.round_to_mintick(h3) : na, title = "Traparilla H3", style = plot.style_line, linewidth = 2, color = c2)
plot(show_c ? math.round_to_mintick(h2) : na, title = "Traparilla H2", style = plot.style_line, linewidth = 1, color = c3)
plot(show_c ? math.round_to_mintick(h1) : na, title = "Traparilla H1", style = plot.style_line, linewidth = 1, color = c3)
plot(show_c ? math.round_to_mintick(center) : na, title = "Traparilla Central", style = plot.style_line, linewidth = 1, color = c1)
plot(show_c ? math.round_to_mintick(l1) : na, title = "Traparilla L1", style = plot.style_line, linewidth = 1, color = c3)
plot(show_c ? math.round_to_mintick(l2) : na, title = "Traparilla L2", style = plot.style_line, linewidth = 1, color = c3)
plot(show_c ? math.round_to_mintick(l3) : na, title = "Traparilla L3", style = plot.style_line, linewidth = 2, color = c2)
plot(show_c ? math.round_to_mintick(l4) : na, title = "Traparilla L4", style = plot.style_line, linewidth = 1, color = c4)
plot(show_c ? math.round_to_mintick(l5) : na, title = "Traparilla L5", style = plot.style_line, linewidth = 1, color = c5)

//Trapanacci Plots
plot(show_f ? fib_h5 : na, title = "Trapanacci H5", linewidth = 1, style = plot.style_line, color = c3)
plot(show_f ? fib_h4 : na, title = "Trapanacci H4", linewidth = 1, style = plot.style_line, color = c3)
plot(show_f ? fib_h3 : na, title = "Trapanacci H3", linewidth = 1, style = plot.style_line, color = c3)
plot(show_f ? fib_h2 : na, title = "Trapanacci H2", linewidth = 1, style = plot.style_line, color = c3)
plot(show_f ? fib_h1 : na, title = "Trapanacci H1", linewidth = 1, style = plot.style_line, color = c3)
plot(show_f ? floor_pivot : na, title = "Trapanacci Pivot", linewidth = 1, style = plot.style_line, color = c0)
plot(show_f ? fib_l1 : na, title = "Trapanacci L1", linewidth = 1, style = plot.style_line, color = c5)
plot(show_f ? fib_l2 : na, title = "Trapanacci L2", linewidth = 1, style = plot.style_line, color = c5)
plot(show_f ? fib_l3 : na, title = "Trapanacci L3", linewidth = 1, style = plot.style_line, color = c5)
plot(show_f ? fib_l4 : na, title = "Trapanacci L4", linewidth = 1, style = plot.style_line, color = c5)
plot(show_f ? fib_l5 : na, title = "Trapanacci L5", linewidth = 1, style = plot.style_line, color = c5)