OPEN-SOURCE SCRIPT

Support and Resistance Trendlines

Strategy:
Support: Identified as the lowest low over a specific period.
Resistance: Identified as the highest high over a specific period.
Dynamic Trendlines: We’ll use the concept of a rolling window to calculate the highest highs and lowest lows over the last n bars (you can adjust the number of bars for more sensitivity).

Explanation:
Lookback Period (length): The number of bars over which we calculate the support and resistance levels. You can adjust this value depending on the timeframe and the sensitivity you want for the trendlines.

Resistance: This is the highest high over the length of bars. We use ta.highest(high, length) to find the highest high within the specified lookback period.

Support: This is the lowest low over the length of bars. We use ta.lowest(low, length) to find the lowest low within the specified lookback period.

Plotting the Lines:

We plot the support and resistance as horizontal lines on the chart using plot().
Additionally, we create dynamic trendlines that update automatically with each new bar. The line.new function creates lines that can be modified dynamically as new price data comes in.
Line Persistence:

The line functions are used to create horizontal lines that persist across bars. The trendlines adjust their position as the bars move forward.
How It Works:
This indicator will automatically detect the highest and lowest prices over the last n bars and draw support (green line) and resistance (red line) levels on the chart.
The trendlines will adjust as the market evolves and provide visual reference points for potential areas of price reversal.
How to Use This Script:
Copy and paste the Pine Script code into the Pine Script Editor on TradingView.
Save the script, and then add it to your chart.
Adjust the Lookback Period input to suit your trading strategy and timeframe.
The support and resistance levels will be drawn dynamically, and the lines will update as new bars form.
Customizations:
You can modify the number of bars (length) used to calculate support and resistance, depending on the timeframes you're interested in.
If you need more advanced trendline drawing (such as drawing trendlines between significant high/low points or automatic adjustment to more complex patterns), you might need to implement more advanced logic using peaks and valleys or price action patterns.
Let me know if you need any further adjustments!



Breadth IndicatorsCandlestick analysisChart patterns

Скрипт с открытым кодом

В истинном духе TradingView автор этого скрипта опубликовал его с открытым исходным кодом, чтобы трейдеры могли понять, как он работает, и проверить на практике. Вы можете воспользоваться им бесплатно, но повторное использование этого кода в публикации регулируется Правилами поведения. Вы можете добавить этот скрипт в избранное и использовать его на графике.

Хотите использовать этот скрипт на графике?

Отказ от ответственности