-- // start: ADR-Signal-Pressure-KL -- @author: Kallebe Lins -- @email: kallebe.santos@outlook.com -- @mentor: Aderaldo Nunes JĂșnior -- @description: Signal based on pressure from buyers and sellers. -- @documentation: https://quadcode-tech.github.io/quadcodescript-docs/index.html instrument {name = "ADR-Signal-Pressure-KL", icon = "indicators:CCI", overlay = true} -- // variables and functions - support zero = make_series() zero:set(0) function ternary(cond, T, F) if (cond) then return T else return F end end function is_up(ps) return open[ps] < close[ps] end function is_down(ps) return open[ps] > close[ps] end function get_top(ps) if open[ps] > close[ps] then return open[ps] else return close[ps] end end function get_bottom(ps) if open[ps] > close[ps] then return close[ps] else return open[ps] end end function is_inside(p1, p2) return get_top(p1) < high[p2] and get_bottom(p1) > low[p2] end -- 1: high | 2: body top (open|close) | 3: body bottom (open|close) | 4: low function get_candle_point(ps) local _p1 = high[ps] local _p2 = get_top(ps) local _p3 = get_bottom(ps) local _p4 = low[ps] return _p1, _p2, _p3, _p4 end -- // inputs -- // execute local ps_a = 2 -- position a local ps_b = 1 -- position b if (is_inside(ps_b, ps_a)) then local a1, a2, a3, a4 = get_candle_point(ps_a) local b1, b2, b3, b4 = get_candle_point(ps_b) local show_pc1 = false local show_pc2 = false local show_pc3 = false local show_pc4 = false local show_pc5 = false local show_pv1 = false local show_pv2 = false local show_pv3 = false local show_pv4 = false local show_pv5 = false -- UP => (a = b) => reversal if (is_down(ps_a) and is_down(ps_b)) then show_pc1 = a4 < b3 and b4 < a4 show_pc2 = a4 < b4 and a1 < b1 show_pc3 = a1 < b1 and a4 > b4 -- UP => (a <> b) => continuation elseif (is_down(ps_a) and is_up(ps_b)) then show_pc4 = a4 == b4 and a3 == b3 and a1 < b1 elseif (is_up(ps_a) and is_down(ps_b)) then show_pc5 = a1 < b1 and a2 >= b2 end -- DOWN => (a = b) => reversal if (is_up(ps_a) and is_up(ps_b)) then show_pv1 = a1 > b2 and b1 > a1 show_pv2 = a1 > b1 and a4 > b4 show_pv3 = a1 < b1 and a4 > b4 -- DOWN => (a <> b) => continuation elseif (is_down(ps_a) and is_up(ps_b)) then show_pv4 = a1 == b1 and a2 == b2 and a4 > b4 elseif (is_down(ps_a) and is_up(ps_b)) then show_pv5 = a4 > b4 and a3 <= b3 end -- plot plot_shape(show_pc1, "show_pc1", shape_style.labelup, shape_size.large, "green", shape_location.belowbar, 0, "PC1", "white") plot_shape(show_pc2, "show_pc2", shape_style.labelup, shape_size.large, "green", shape_location.belowbar, 0, "PC2", "white") plot_shape(show_pc3, "show_pc3", shape_style.labelup, shape_size.large, "green", shape_location.belowbar, 0, "PC3", "white") plot_shape(show_pc4, "show_pc4", shape_style.labelup, shape_size.large, "green", shape_location.belowbar, 0, "PC4", "white") plot_shape(show_pc5, "show_pc5", shape_style.labelup, shape_size.large, "green", shape_location.belowbar, 0, "PC5", "white") plot_shape(show_pv1, "show_pv1", shape_style.labeldown, shape_size.large, "red", shape_location.abovebar, 0, "PV1", "white") plot_shape(show_pv2, "show_pv2", shape_style.labeldown, shape_size.large, "red", shape_location.abovebar, 0, "PV2", "white") plot_shape(show_pv3, "show_pv3", shape_style.labeldown, shape_size.large, "red", shape_location.abovebar, 0, "PV3", "white") plot_shape(show_pv4, "show_pv4", shape_style.labeldown, shape_size.large, "red", shape_location.abovebar, 0, "PV4", "white") plot_shape(show_pv5, "show_pv5", shape_style.labeldown, shape_size.large, "red", shape_location.abovebar, 0, "PV5", "white") end -- // end: ADR-Signal-Pressure-KL