OPEN-SOURCE SCRIPT

Trendzones

Hi all!

This indicator plots trendlines. These lines are not plotted as traditional lines, but are instead zones. This is useful if you think that trend lines are more of an area of importance than a line.

It does so by finding pivots and connecting two of them if they have not been broken (more about that later) in-between the pivots.

These trend zones can be used as support/resistance that the price can react to.

• The first trendline is drawn between the high/low of the first and second pivot.
• The second trendline's first point is at the open/close of the pivot (either the first pivot or the second one) that has the smallest difference between the high/low and the nearest open/close. The same difference (between the high/low and the open/close) is then subtracted from the other pivot's high/low. This creates a point at the other pivot bar. A trendline is then drawn between the points.

This creates two trendlines and a zone between the two trendlines. This zone is the one kept and is shown by the script.

You can define the pivot lengths used to find trend zones (defaults to 3/3). You can also define the number of pivots to look back for, to find trend zones and the number of active zones, both of these defaults to 3. You can also choose to let the script create new zones based on time ("Oldest") or the zone that is furthest away in price, this defaults to be based on time but it can be useful for letting the script remove the one which is furthest away in price. Another useful setting is the one called "Cross source". This defines the price that has to cross the trend zone to make it invalid (broken). This defaults to "Close", i.e. the bar has to close on the "wrong side" of the trend zone.

The current zones are shown with an extension to the right, but you can also choose to keep the previous lines (without extension). Please note that kept zones are only the ones that are broken, not the replaced ones. I.e. the zones that are kept are the ones that are crossed by the user defined "cross source" (defaults to the closing/current price of the bar).

Hope this makes sense, let me know if you have any questions.

Best of trading luck!
Pivot PointsSupport and ResistanceTrend Analysistrendlineanalysistrendlinesuport

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in publication is governed by House rules. You can favorite it to use it on a chart.

Want to use this script on a chart?

Disclaimer