instrument { name = "RETALIACAO 2 MORTALHA", icon = "https://pixabay.com/images/id-3727790/", overlay = " true" } MaFast_period = input(5,"Ma Fast period",input.integer,1,1000,1) MaValue = input(5,"Ma Value", input.string_selection,inputs.titles) MaSlow_period = input(60,"Ma Slow period",input.integer,1,1000,1) Signal_period = input(5,"Signal period",input.integer,1,1000,1) input_group { "Compra", colorBuy = input { default = "#40ff00", type = input.color }, visibleBuy = input { default = true, type = input.plot_visibility } } input_group { "Venda", colorSell = input { default = "#ff0040", type = input.color }, visibleSell = input { default = true, type = input.plot_visibility } } local titleValue = inputs[MaValue] -- mdia mvel linear rpida smaFast = sma(titleValue, MaFast_period) -- mdia mvel linear devagar smaSlow = sma(titleValue, MaSlow_period) -- calculo diferencial - serie buffer1 = smaFast - smaSlow -- clculo da mdia mvel ponderada - serie buffer2 = wma(buffer1, Signal_period) buyCondition = conditional(buffer1 > buffer2 and buffer1[1] < buffer2[1] and not (buffer1 < buffer2 and buffer1[1] > buffer2[1])) buyCondition = conditional(buffer1 > buffer2 and buffer1[1] < buffer2[1]) sellCondition = conditional(buffer1 < buffer2 and buffer1[1] > buffer2[1] and not (buffer1 > buffer2 and buffer1[1] < buffer2[1])) sellCondition = conditional(buffer1 < buffer2 and buffer1[1] > buffer2[1] ) plot_shape( (buyCondition), ".", shape_style.triangleup, shape_size.huge, colorBuy, shape_location.belowbar, -1, ".", "#bf00ff" ) plot_shape( (sellCondition), ".", shape_style.triangledown, shape_size.huge, colorSell, shape_location.abovebar, -1, ".", "#bf00ff" ) instrument { name = "X-Lowest", overlay = true } period = input (14, "front.period", input.integer, 1 ) input_group { "front.ind.dpo.generalline", color = input { default = "#FF6C58", type = input.color }, width = input { default = 1, type = input.line_width} } plot (lowest (period) [1], "LL", color, width) instrument { name = "Highest High", overlay = true } period = input (14, "front.period", input.integer, 1 ) input_group { "front.ind.dpo.generalline", color = input { default = "#25E154", type = input.color }, width = input { default = 1, type = input.line_width} } plot (highest (period) [1], "HH", color, width) instrument { name = "XS trader", overlay = true } percentage = input (0.5, "Percentage", input.double, 0.01, 100, 1.0) / 100 period = 1 input_group { "front.ind.dpo.generalline", up_color = input { default = "#00ff77", type = input.color }, down_color = input { default = "#f90f65", type = input.color }, width = input { default = 1, type = input.line_width } } local reference = make_series () reference:set(nz(reference[1], high)) local is_direction_up = make_series () is_direction_up:set(nz(is_direction_up[1], true)) local htrack = make_series () local ltrack = make_series () local pivot = make_series () reverse_range = reference * percentage / 100 if get_value (is_direction_up) then htrack:set (max(high, nz(htrack[1], high))) if close < htrack[1] - reverse_range then pivot:set (htrack) is_direction_up:set (false) reference:set(htrack) end else ltrack:set (min(low, nz(ltrack[1], low))) if close > ltrack[1] + reverse_range then pivot:set (ltrack) is_direction_up:set(true) reference:set (ltrack) end end color = is_direction_up() and up_color or down_color plot(pivot, 'ZZ', color, width, -1, style.solid_line, na_mode.continue)