// This Strategy was Created by ©NoobSharks // if you use it and like it, send us some donation: BinancePay ID: 223731148 - Metamask: 0x82782b3ebD1d6bf7faa18a3943fA6f16EBBF3134 // (yes, I might be naive but I trully Believe you will support us) // For more information about this indicator check "https://www.youtube.com/c/NoobSharksLutanoMercadoCripto" and give us a hand following us on YouTube // Check also our website includeing strategies, free indicatores and technical analysis videos: https://www.noobsharks.com // ATTENTION! REPAINTS! // THIS INDICATOR IS AN UNION OF TWO INDICATORS FROM ©LuxAlgo: NADARAYA WATSON ENVELOPE AND NADARAYA-WATSON ESTIMATOR // CREDITS FOR THE BASIS OF THE INDICATOR GO TO ©LuxAlgo, I just made some adjustment so both could run together. A set of alerts were also included //@version=6 indicator(title = '[NB] Indicator - NADARAYA-WATSON Envelope & Estimator', shorttitle = '[NB]IND.Nadaraya.WATSON.Envelope&Estimator', overlay = true, max_bars_back = 1000, max_lines_count = 500, max_labels_count = 500) length = input.float(330, 'Window Size', maxval = 330, minval = 0) h = input.float(8., 'Bandwidth') mult = input.float(3.) src = input.source(close, 'Source') up_col = input.color(color.lime, 'Colors', inline = 'col') dn_col = input.color(color.red, '', inline = 'col') //---- n = bar_index var k = 2 var upper = array.new_line(0) var lower = array.new_line(0) var centerline = array.new_line(0) lset(l, x1, y1, x2, y2, col) => line.set_xy1(l, x1, y1) line.set_xy2(l, x2, y2) line.set_color(l, col) line.set_width(l, 2) if barstate.isfirst for i = 0 to length / k - 1 by 1 array.push(upper, line.new(na, na, na, na)) array.push(lower, line.new(na, na, na, na)) array.push(centerline, line.new(na, na, na, na)) //---- line up = na line dn = na line cnt = na var line lineTest = na //---- cross_up = 0. cross_dn = 0. reference1 = 0. reference2 = 0. reference3 = 0. mae = 0. y1 = 0. y2 = 0. if barstate.islast y = array.new_float(0) sum_e = 0. for i = 0 to length - 1 by 1 sum = 0. sumw = 0. for j = 0 to length - 1 by 1 w = math.exp(-(math.pow(i - j, 2) / (h * h * 2))) sum := sum + src[j] * w sumw := sumw + w sumw y2 := sum / sumw sum_e := sum_e + math.abs(src[i] - y2) array.push(y, y2) mae := sum_e / length * mult for i = 1 to length - 1 by 1 y2 := array.get(y, i) y1 := array.get(y, i - 1) up := array.get(upper, i / k) dn := array.get(lower, i / k) cnt := array.get(centerline, i / k) lset(up, n - i + 1, y1 + mae, n - i, y2 + mae, up_col) lset(dn, n - i + 1, y1 - mae, n - i, y2 - mae, dn_col) lset(cnt, n - i + 1, y1, n - i, y2, y2 > y1 ? dn_col : up_col) if src[i] > y1 + mae and src[i + 1] < y1 + mae label.new(n - i, src[i], '▼', color = #00000000, style = label.style_label_down, textcolor = dn_col, textalign = text.align_center) if src[i] < y1 - mae and src[i + 1] > y1 - mae label.new(n - i, src[i], '▲', color = #00000000, style = label.style_label_up, textcolor = up_col, textalign = text.align_center) cross_up := array.get(y, 0) + mae cross_dn := array.get(y, 0) - mae reference1 := array.get(y, 0) reference2 := array.get(y, 2) reference3 := array.get(y, 4) reference3 bullSign = ta.crossover(src, cross_dn) bearSign = ta.crossunder(src, cross_up) center = (cross_up + cross_dn) / 2 centerSignUp = ta.crossover(src, center) centerSignDown = ta.crossunder(src, center) bool isCenterBull = false if reference1 > math.max(reference2, reference3) isCenterBull := true isCenterBull else isCenterBull := false isCenterBull // ----- ALERTS RELATED TO CENTER LINE if centerSignUp and isCenterBull alert(syminfo.ticker + ' CrossUP GREEN avg (Open Long or Close short)', alert.freq_once_per_bar_close) if centerSignUp and not isCenterBull alert(syminfo.ticker + ' CrossUP RED avg (Keep Shorting or Open Short)', alert.freq_once_per_bar_close) if centerSignDown and isCenterBull alert(syminfo.ticker + ' CrossDOWN GREEN avg (Keep Longing or Open Long)', alert.freq_once_per_bar_close) if centerSignDown and not isCenterBull alert(syminfo.ticker + ' CrossDOWN RED avg (Open Short or Close Long)', alert.freq_once_per_bar_close) // ----- ALERTS RELATED ON TOP OR BOTTOM OF THE CHANNELS if not isCenterBull and bullSign alert(syminfo.ticker + ' CrossUP RED channel - avg is RED (TP Short or Keep Shorting)', alert.freq_once_per_bar_close) if isCenterBull and bullSign alert(syminfo.ticker + ' CrossUP RED channel - avg is is GREEN (CloseShort AND OpenLong)', alert.freq_once_per_bar_close) if isCenterBull and bearSign alert(syminfo.ticker + ' CrossDOWN GREEN channel - avg is GREEN (TP Long or Keep Longing)', alert.freq_once_per_bar_close) if not isCenterBull and bearSign alert(syminfo.ticker + ' CrossDOWN GREEN channel - avg is is red (CloseLong AND OpenShort)', alert.freq_once_per_bar_close) var tbRepaintAlert = table.new(position.top_right, 1, 1, bgcolor = #35202b) if barstate.isfirst table.cell(tbRepaintAlert, 0, 0, 'ATTENTION! REPAINTS! @NOOBSHARKS', text_size = size.small, text_color = #cc2f3c)