-- // start: ADR-Signal-Exhaustion-KL -- @author: Kallebe Lins -- @email: kallebe.santos@outlook.com -- @mentor: Aderaldo Nunes JĂșnior -- @description: Signal based on exhaustion after double and triple candlestick positions. -- @documentation: https://quadcode-tech.github.io/quadcodescript-docs/index.html instrument {name = "ADR-Signal-Exhaustion-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 check_inside(p1, p2) return get_top(p1) < high[p2] and get_bottom(p1) > low[p2] end function check_same_color(p1, p2) return (is_down(p1) and is_down(p2)) or (is_up(p1) and is_up(p2)) end -- wick function has_up_wick(ps) return high[ps] > get_top(ps) end function has_down_wick(ps) return low[ps] < get_bottom(ps) 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 = 3 -- position a local ps_b = 2 -- position b local ps_c = 1 -- position c local ps_d = 0 -- position d : current local a1, a2, a3, a4 = get_candle_point(ps_a) local b1, b2, b3, b4 = get_candle_point(ps_b) local c1, c2, c3, c4 = get_candle_point(ps_c) local d1, d2, d3, d4 = get_candle_point(ps_d) -- double position local is_inside_double = check_inside(ps_c, ps_b) and check_same_color(ps_c, ps_b) local is_ex_up_double = is_down(ps_d) and has_up_wick(ps_d) and d4 == d3 and d4 < c4 and d4 < b4 and is_inside_double local is_ex_down_double = is_up(ps_d) and has_down_wick(ps_d) and d1 == d2 and d1 > c1 and c1 > b1 and is_inside_double -- triple position local is_inside_triple = check_inside(ps_c, ps_b) and check_same_color(ps_c, ps_b) and check_inside(ps_c, ps_a) and check_same_color(ps_c, ps_a) local is_ex_up_triple = is_down(ps_d) and has_up_wick(ps_d) and d4 == d3 and d4 < c4 and d4 < b4 and d4 < a4 and is_inside_triple local is_ex_down_triple = is_up(ps_d) and has_down_wick(ps_d) and d1 == d2 and d1 > c1 and d1 > b1 and d1 > a1 and is_inside_triple -- plot plot_shape(is_ex_up_double, "is_ex_up_double", shape_style.labelup, shape_size.large, "green", shape_location.belowbar, 0, "EX", "white") plot_shape(is_ex_down_double, "is_ex_down_double", shape_style.labeldown, shape_size.large, "red", shape_location.abovebar, 0, "EX", "white") plot_shape(is_ex_up_triple, "is_ex_up_triple", shape_style.labelup, shape_size.large, "green", shape_location.belowbar, 0, "EX", "white") plot_shape(is_ex_down_triple, "is_ex_down_triple", shape_style.labeldown, shape_size.large, "red", shape_location.abovebar, 0, "EX", "white") -- // end: ADR-Signal-Exhaustion-KL