Tradingview: Support and Resistance Indicator

This post contains a simple automated support and resistance indicator for use on Tradingview.

Identifying support and resistance zones is an important and popular technical analysis technique. Using historical data, humans can easily identify price zones where a lot of buyers (or sellers) came into the market. We can then use this information as a guide to indicate where demand might increase again in the future.

How it works

The indicator attempts to automate detection of support and resistance levels by identifying large swings/pivots in historical price action. These tops and bottoms in price action show where lots of buyers or sellers came into the market and might act as future levels of support or resistance. By default, the code detects the last 3 significant swing highs and the last 3 swing lows. It then places lines on the chart to highlight those levels.

In support and resistance theory we often hear that support becomes resistance and vice versa. Because of this, the indicator does not simply categorize swings lows as “support” and swing highs as “resistance”. Instead, we look at the swing position relative to the current close price. If we are above the level, we consider it support. If we are below the level, we consider it to be resistance.

With this in mind, the lines are automatically colored according to whether they are above or below the current close price. When any of the levels are below the close price, the lines are colored green. Conversely, whenever they are above the close, they are colored red.

Support and Resistance Indicator Code

Code Commentary

Since significant levels are detected using pivots with large numbers of left and right bars, this can cause quite a delay in receiving a recent significant swing. As such, a quick_rightvariable is used to detect the first and second levels. This will help to reduce the lag and highlight a possible support level after only 5 bars as opposed to the usual 25. Of course, this speed comes at a cost of accuracy.

Line coloring is set using a simple ternary conditional operator to detect whether the current close price is above/below the line..

Finally, a plotting trick is used so that we don’t end up with messy lines on the chart as new swings are detected. We simply plot the last value on the chart only and then use trackpriceto draw the line.

On the Charts

Loading up the indicator, you should see something that looks a little like this:

Support and Resistance Indicator on the charts

Note The annotations have been written on the chart after adding the support and resistance indicator!

In the image above we can see a couple of interesting things going on:

  1. We highlight an area of potentially increased resistance as two levels are close together.
  2. quick_righthas identified a recent swing low which looks like it could form the basis for future support.
  3. We successfully capture the highest high and lowest low of the trading period on the chart.

Of course, this indicator is not perfect. No indicators are! If you scroll back in time, you will find significant areas of support and resistance that happened more than 3 pivots/swings ago. Additionally, it may flag some swings which turn out not to be all that significant in the end. Use your own judgment when utilizing this indicator as to whether or not to rely on the levels it produces!

Expanding the code

Once you are comfortable with the code base and how the indicator operates, you may wish to expand upon it. One obvious addition to make would be inputs for the left,rightandquick_rightvariables so that you can tune the indicator according to your own taste.

Other users may wish to add more lines or perhaps swings from other time-frames. How far you take this, is up to you. I just hope the base code provides a good enough example for readers to build upon!