-- // start: ADR-Signal-TD-KL -- @author: Kallebe Lins -- @email: kallebe.santos@outlook.com -- @mentor: Aderaldo Nunes JĂșnior -- @description: Signal based on domain transfer. -- @documentation: https://quadcode-tech.github.io/quadcodescript-docs/index.html instrument {name = "ADR-Signal-TD-KL", icon = "indicators:CCI", overlay = true} -- // inputs local count_candle = input(30, "Candle Quantity Analysis", input.integer, 1, 120) -- // 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 -- 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 -- // execute local show_rev_up_lote = false local show_con_up_lote = false local show_rev_up_tx = false local show_con_up_tx = false local show_rev_down_lote = false local show_con_down_lote = false local show_rev_down_tx = false local show_con_down_tx = false for i = 2, count_candle, 1 do local ps_a = i+1 -- position a local ps_b = i -- position b local ps_current = 1 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_current) -- lote if (is_up(ps_a) and is_down(ps_b) and is_down(ps_current)) then -- reversal show_rev_up_lote = show_rev_up_lote or ((c3 == b1 or c4 == b1) and b1 > b2) -- continuation show_con_down_lote = show_con_down_lote or (c3 == c4 and ((c3 == a1 and a1 > b1) or c3 == b2)) end -- tax if (is_up(ps_a) and is_up(ps_b) and is_up(ps_current)) then -- reversal show_rev_down_tx = show_rev_down_tx or (c1 == c2 and c2 == b4 and b3 > b4) -- continuation show_con_up_tx = show_con_up_tx or (c1 == c2 and c2 == b3) end -- lote if (is_down(ps_a) and is_up(ps_b) and is_up(ps_current)) then -- reversal show_rev_down_lote = show_rev_down_lote or ((c2 == b4 or c1 == b4) and b4 < b3) -- continuation show_con_up_lote = show_con_up_lote or (c2 == c1 and ((c2 == a4 and a4 < b4) or c2 == b3)) end -- tax if (is_down(ps_a) and is_down(ps_b) and is_down(ps_current)) then -- reversal show_rev_up_tx = show_rev_up_tx or (c3 == c4 and c3 == b1 and b2 < b1) -- continuation show_con_down_tx = show_con_down_tx or (c3 == c4 and c3 == b2) end end -- plot plot_shape(show_rev_up_lote, "show_rev_up_lote", shape_style.labelup, shape_size.large, "green", shape_location.belowbar, 0, "DLT-R", "white") plot_shape(show_con_up_lote, "show_con_up_lote", shape_style.labelup, shape_size.large, "green", shape_location.belowbar, 0, "DLT-C", "white") plot_shape(show_rev_up_tx, "show_rev_up_tx", shape_style.labelup, shape_size.large, "green", shape_location.belowbar, 0, "DTX-R", "white") plot_shape(show_con_up_tx, "show_con_up_tx", shape_style.labelup, shape_size.large, "green", shape_location.belowbar, 0, "DTX-C", "white") plot_shape(show_rev_down_lote, "show_rev_down_lote", shape_style.labeldown, shape_size.large, "red", shape_location.abovebar, 0, "DLT-R", "white") plot_shape(show_con_down_lote, "show_con_down_lote", shape_style.labeldown, shape_size.large, "red", shape_location.abovebar, 0, "DLT-C", "white") plot_shape(show_rev_down_tx, "show_rev_down_tx", shape_style.labeldown, shape_size.large, "red", shape_location.abovebar, 0, "DTX-R", "white") plot_shape(show_con_down_tx, "show_con_down_tx", shape_style.labeldown, shape_size.large, "red", shape_location.abovebar, 0, "DTX-C", "white") -- // end: ADR-Signal-TD-KL