Support and Resistance

Support and resistance levels are crucial concepts in technical analysis, providing key insights into potential price reversal points and areas of consolidation

Summary

This script segment is designed to dynamically identify and visualize support and resistance levels based on user-defined periods. It uses the highest high and lowest low over the specified period to determine these levels. The support and resistance levels are then plotted on the chart, with changing colors indicating new instances of these levels. This can be particularly useful for traders and analysts looking to understand market sentiment and potential reversal points.

Input Variable

RST = input(title='Support / Resistance length:', defval=10)
  • RST is an input variable that allows the user to specify the length of the period over which to calculate support and resistance levels. The default value is set to 10.

Calculating Support and Resistance Levels

RSTT = ta.valuewhen(high >= ta.highest(high, RST), high, 0)
RSTB = ta.valuewhen(low <= ta.lowest(low, RST), low, 0)
  • RSTT calculates the most recent instance when the current high is greater than or equal to the highest high over the specified period (RST). This indicates a potential resistance level.

  • RSTB calculates the most recent instance when the current low is less than or equal to the lowest low over the specified period (RST). This indicates a potential support level.

Plotting Support and Resistance Levels

RT2 = plot(RSTT, color=RSTT!= RSTT[2]? na : color.red, linewidth=1, offset=+0)
RB2 = plot(RSTB, color=RSTB!= RSTB[2]? na : color.green, linewidth=1, offset=0)
  • RT2 plots the calculated resistance level (RSTT). The color condition checks if the current resistance level is different from the previous one; if not, it sets the color to red, indicating a potential resistance level. The offset=+0 means the plot starts at the beginning of the chart.

  • RB2 plots the calculated support level (RSTB). Similarly, the color condition changes the line to green if the current support level is different from the previous one, indicating a potential support level. The offset=0 places the plot at the current bar level.

Last updated