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

Skrip open-source

Dengan semangat TradingView yang sesungguhnya, penulis skrip ini telah menerbitkannya sebagai sumber terbuka, sehingga para trader dapat memahami dan memverifikasinya. Hormat untuk penulisnya! Anda dapat menggunakannya secara gratis, namun penggunaan kembali kode ini dalam publikasi diatur oleh Tata Tertib. Anda dapat memfavoritkannya untuk digunakan pada chart

Inggin menggunakan skrip ini pada chart?

Pernyataan Penyangkalan