Create Swing High and Swing Low Indicator in PineScript. Purpose: This indicator is…
- User
Create Swing High and Swing Low Indicator in PineScript.
Purpose: This indicator is meticulously crafted to accurately identify swing highs and swing lows on your chart by applying detailed rules. It includes features for recognizing inside bars as potential swing points, and customizable visual outputs for enhanced chart analysis.
Key Definitions: Candle: Refers to a single candle or a group of up to 10 consecutive candles with identical high and low prices, treated as one unit. Inside Bar: A smaller candle that has a lower high than the high of an adjacent larger candle and a higher low than the low of that same larger candle. The inside bar can be on either side of the larger candle, provided they are direct neighbors without any intervening candles.
Rules for Identifying Swing Highs: Formation: A swing high is identified when it has one neighboring candle on each side, both with lower high prices than the swing high. At the chart's beginning, if there is no left neighbor, only the right neighbor is checked. Confirmation: The right-side neighbor candle must be confirmed by closing before the swing high is officially labeled.
Rules for Identifying Swing Lows: Formation: A swing low is identified when it is surrounded by one neighboring candle on each side, both with higher low prices than the swing low. If at the chart's start and a left neighbor is absent, only the right neighbor is checked. Confirmation: Similar to swing highs, the right-side neighbor candle must be closed to confirm the swing low designation.
Inside Bar Rules: Standard Conditions: The high and low of an inside bar must be strictly within the high and low of the adjacent larger candle. Exceptions: When Larger Candle is a Swing High: The inside bar's low can be equal to the larger candle's low but must not be lower. Its high must be lower (not equal) to the larger candle's high. When Larger Candle is a Swing Low: The inside bar's high can be equal to the larger candle's high but must not be higher. Its low must be higher (not equal) to the larger candle's low. Inside Bar as Swing High and Swing Low: Larger Candle on the Left, Inside Bar on the Right: For swing high: The high of the next candle after the inside bar must be lower than the inside bar's high, and the larger candle must be confirmed as a swing low. For swing low: The low of the next candle after the inside bar must be higher than the inside bar's low, and the larger candle must be confirmed as a swing high. Larger Candle on the Right, Inside Bar on the Left: For swing high: The larger candle must be confirmed as a swing low, and the high of the preceding candle must be lower than the inside bar's high. For swing low: The low of the preceding candle must be higher than the inside bar's low, and the larger candle must be confirmed as a swing high.
Output Features: Labeling Swing Points: Each identified swing point is labeled on the chart. Users have the option in the settings to make these labels invisible if desired. Zigzag Line: A zigzag line connects each swing point on the chart for visual clarity. Users have the option in the settings to hide the zigzag line if preferred.
- Assistant
- User
error in line 9: Syntax error at input ','
- Assistant