// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © vnhilton //@version=5 indicator("ZigZag With ATR Filter [vnhilton]", "ZigZag w/ ATR Filter", true, max_lines_count = 500, max_labels_count = 500) //Parameters errorMsgToggle = input.bool (true, "Show Pivot Point Length Error Message") showPivotValueText = input.bool (true, "", inline = "Pivot Label") showTrendText = input.bool (true, "Show Pivot Value/Trend Text", inline = "Pivot Label") showZigZagSizeText = input.bool (true, "", inline = "ZigZag Settings") showZigZagLengthText = input.bool (true, "", inline = "ZigZag Settings") showZigZagVolumeText = input.bool (true, "Show ZigZag Size/Length/Volume Text", inline = "ZigZag Settings") atrLength = input.int (20, "ATR/Pivot Point Period", 1, inline = "Lengths") pivotLength = input.int (3, "", 3, 501, 2, "Pivot point length must be an odd number; Looks for middle bar of period to be highest/lowest, with preceding and succeeding lower/higher and lower/higher highs/lows", inline = "Lengths") atrMultiplier = input.float(2, "ATR Multiplier Minimum Threshold", 0, tooltip = "A pivot is only recognised if it is at least N ATRs away from the prior pivot") maxLines = input.int (497, "Show the last N ZigZag lines", 2, 497) pivotLabelSize = input.string("Normal", "Label Size", ["Auto", "Tiny", "Small", "Normal", "Large", "Huge"], group = "Pivot Label Settings") highPivotStyle = input.string("Label Lower Right", "High/Low Pivot Label Style", ["None", "X-Cross", "Cross", "Triangle Up", "Triangle Down", "Flag", "Circle", "Arrow Up", "Arrow Down", "Label Up", "Label Down", "Label Left", "Label Right", "Label Lower Left", "Label Lower Right", "Label Upper Left", "Label Upper Right", "Label Center", "Label Square", "Label Diamond", "Label Text Outline"], inline = "Label Style", group = "Pivot Label Settings") lowPivotStyle = input.string("Label Upper Right", "", ["None", "X-Cross", "Cross", "Triangle Up", "Triangle Down", "Flag", "Circle", "Arrow Up", "Arrow Down", "Label Up", "Label Down", "Label Left", "Label Right", "Label Lower Left", "Label Lower Right", "Label Upper Left", "Label Upper Right", "Label Center", "Label Square", "Label Diamond", "Label Text Outline"], inline = "Label Style", group = "Pivot Label Settings") confHighPivotLabelColorU = input.color(color.new(color.green, 80), "High Pivot Confirmed Colors", inline = "P High Confirmed", group = "Label Uptrend/Downtrend/Range Color Settings") confHighPivotLabelColorD = input.color(color.new(color.red, 80), "", inline = "P High Confirmed", group = "Label Uptrend/Downtrend/Range Color Settings") confHighPivotLabelColorR = input.color(color.new(color.gray, 80), "", inline = "P High Confirmed", group = "Label Uptrend/Downtrend/Range Color Settings") liveHighPivotLabelColorU = input.color(color.new(color.blue, 80), "High Pivot Live Colors", inline = "P High Live", group = "Label Uptrend/Downtrend/Range Color Settings") liveHighPivotLabelColorD = input.color(color.new(color.fuchsia, 80), "", inline = "P High Live", group = "Label Uptrend/Downtrend/Range Color Settings") liveHighPivotLabelColorR = input.color(color.new(color.yellow, 80), "", inline = "P High Live", group = "Label Uptrend/Downtrend/Range Color Settings") confLowPivotLabelColorU = input.color(color.new(color.green, 80), "Low Pivot Confirmed Colors", inline = "P Low Confirmed", group = "Label Uptrend/Downtrend/Range Color Settings") confLowPivotLabelColorD = input.color(color.new(color.red, 80), "", inline = "P Low Confirmed", group = "Label Uptrend/Downtrend/Range Color Settings") confLowPivotLabelColorR = input.color(color.new(color.gray, 80), "", inline = "P Low Confirmed", group = "Label Uptrend/Downtrend/Range Color Settings") liveLowPivotLabelColorU = input.color(color.new(color.blue, 80), "Low Pivot Live Colors", inline = "P Low Live", group = "Label Uptrend/Downtrend/Range Color Settings") liveLowPivotLabelColorD = input.color(color.new(color.fuchsia, 80), "", inline = "P Low Live", group = "Label Uptrend/Downtrend/Range Color Settings") liveLowPivotLabelColorR = input.color(color.new(color.yellow, 80), "", inline = "P Low Live", group = "Label Uptrend/Downtrend/Range Color Settings") confHighPivotTextColorU = input.color(color.green, "High Text Confirmed Colors", inline = "T High Confirmed", group = "Text Uptrend/Downtrend/Range Color Settings") confHighPivotTextColorD = input.color(color.red, "", inline = "T High Confirmed", group = "Text Uptrend/Downtrend/Range Color Settings") confHighPivotTextColorR = input.color(color.gray, "", inline = "T High Confirmed", group = "Text Uptrend/Downtrend/Range Color Settings") liveHighPivotTextColorU = input.color(color.blue, "High Text Live Colors", inline = "T High Live", group = "Text Uptrend/Downtrend/Range Color Settings") liveHighPivotTextColorD = input.color(color.fuchsia, "", inline = "T High Live", group = "Text Uptrend/Downtrend/Range Color Settings") liveHighPivotTextColorR = input.color(color.yellow, "", inline = "T High Live", group = "Text Uptrend/Downtrend/Range Color Settings") confLowPivotTextColorU = input.color(color.green, "Low Text Confirmed Colors", inline = "T Low Confirmed", group = "Text Uptrend/Downtrend/Range Color Settings") confLowPivotTextColorD = input.color(color.red, "", inline = "T Low Confirmed", group = "Text Uptrend/Downtrend/Range Color Settings") confLowPivotTextColorR = input.color(color.gray, "", inline = "T Low Confirmed", group = "Text Uptrend/Downtrend/Range Color Settings") liveLowPivotTextColorU = input.color(color.blue, "Low Text Live Colors", inline = "T Low Live", group = "Text Uptrend/Downtrend/Range Color Settings") liveLowPivotTextColorD = input.color(color.fuchsia, "", inline = "T Low Live", group = "Text Uptrend/Downtrend/Range Color Settings") liveLowPivotTextColorR = input.color(color.yellow, "", inline = "T Low Live", group = "Text Uptrend/Downtrend/Range Color Settings") confZZLineColorU = input.color (color.green, "Uptrend/Downtrend/Range Colors", inline = "Confirmed Colors", group = "Confirmed ZigZag Line Settings") confZZLineColorD = input.color (color.red, "", inline = "Confirmed Colors", group = "Confirmed ZigZag Line Settings") confZZLineColorR = input.color (color.gray, "", inline = "Confirmed Colors", group = "Confirmed ZigZag Line Settings") confZZLineWidth = input.int (2, "Line Width/Style", 1, inline = "Confirmed WS", group = "Confirmed ZigZag Line Settings") confZZLineStyle = input.string("Solid", "", ["Arrow Right", "Dashed", "Dotted", "Solid"], inline = "Confirmed WS", group = "Confirmed ZigZag Line Settings") liveZZLineColorU = input.color (color.blue, "Uptrend/Downtrend/Range Colors", inline = "Live Colors", group = "Live ZigZag Line Settings") liveZZLineColorD = input.color (color.fuchsia, "", inline = "Live Colors", group = "Live ZigZag Line Settings") liveZZLineColorR = input.color (color.yellow, "", inline = "Live Colors", group = "Live ZigZag Line Settings") liveZZLineWidth = input.int (2, "Line Width/Style", 1, inline = "Live WS", group = "Live ZigZag Line Settings") liveZZLineStyle = input.string("Solid", "", ["Arrow Right", "Dashed", "Dotted", "Solid"], inline = "Live WS", group = "Live ZigZag Line Settings") livePZZLineColorU = input.color (color.new(color.green, 80), "Up/Down/Level Colors", inline = "Potential Colors", group = "Potential ZigZag Line Settings") livePZZLineColorD = input.color (color.new(color.red, 80), "", inline = "Potential Colors", group = "Potential ZigZag Line Settings") livePZZLineColorR = input.color (color.new(color.gray, 80), "", inline = "Potential Colors", group = "Potential ZigZag Line Settings") livePZZLineWidth = input.int (2, "Line Width/Style", 1, inline = "Potential WS", group = "Potential ZigZag Line Settings") livePZZLineStyle = input.string("Solid", "", ["Arrow Right", "Dashed", "Dotted", "Solid"], inline = "Potential WS", group = "Potential ZigZag Line Settings") livePZZLabelColorU = input.color(color.new(color.green, 80), "Up/Down Label Colors", inline = "Potential L Colors", group = "Potential ZigZag Label Settings") livePZZLabelColorD = input.color(color.new(color.red, 80), "", inline = "Potential L Colors", group = "Potential ZigZag Label Settings") livePZZTextColorU = input.color(color.new(color.green, 80), "Up/Down Text Colors", inline = "Potential T Colors", group = "Potential ZigZag Label Settings") livePZZTextColorD = input.color(color.new(color.red, 80), "", inline = "Potential T Colors", group = "Potential ZigZag Label Settings") //Arrays var int [] pivotIndices = array.new() var float [] pivotValues = array.new() var string [] pivotTypes = array.new() var string [] pivotTrends = array.new() var label [] pivotLabels = array.new