devTooltip = "Deviation is a multiplier that affects how much the price should deviate from the previous pivot in order for the bar to become a new pivot." depthTooltip = "The minimum number of bars that will be taken into account when calculating the indicator."
// Pivots threshold threshold_multiplier = input.float(title="Deviation", defval=10, minval=0, tooltip=devTooltip) depth = input.int(title="Depth", defval=3, minval=2, tooltip=depthTooltip) reverse = input(false, "Reverse", display = display.data_window) var extendLeft = input(false, "Extend Left | Extend Right", inline = "Extend Lines") var extendRight = input(true, "", inline = "Extend Lines") var extending = extend.none if extendLeft and extendRight extending := extend.both if extendLeft and not extendRight extending := extend.left if not extendLeft and extendRight extending := extend.right
update() => var settings = zigzag.Settings.new(threshold_multiplier, depth, color(na), false, false, false, false, "Absolute", true) var zigzag.ZigZag zigZag = zigzag.newInstance(settings) var zigzag.Pivot lastP = na var float startPrice = na var float endPrice = na // End price değişkenini ekliyoruz var float height = na settings.devThreshold := ta.atr(10) / close * 100 * threshold_multiplier if zigZag.update() lastP := zigZag.lastPivot() if not na(lastP) var line lineLast = na if na(lineLast) lineLast := line.new(lastP.start, lastP.end, xloc=xloc.bar_time, color=color.gray, width=1, style=line.style_dashed) else line.set_first_point(lineLast, lastP.start) line.set_second_point(lineLast, lastP.end)
_crossing_level(series float sr, series float r) => (r > sr and r < sr[1]) or (r < sr and r > sr[1])
processLevel(bool show, float value, string label, color colorL, line lineIdOther) => r = startPrice + height * value crossed = _crossing_level(close, r) if show and not na(lastP) lineId = _draw_line(r, colorL) _draw_label(r, _label_txt(label, r), colorL) if crossed alert("Autofib: " + syminfo.ticker + " crossing level " + str.tostring(label)) if not na(lineIdOther) linefill.new(lineId, lineIdOther, color = color.new(colorL, backgroundTransparency)) lineId else lineIdOther
// Define the text values and colors for each level show_tepe = input(true, "Show Tepe", display = display.data_window) color_tepe = input(color.new(color.gray, 50), "Tepe Color", display = display.data_window)