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!
Theo tinh thần TradingView thực sự, tác giả của tập lệnh này đã xuất bản dưới dạng nguồn mở để các nhà giao dịch có thể hiểu và xác minh. Chúc mừng tác giả! Bạn có thể sử dụng miễn phí. Tuy nhiên, bạn cần sử dụng lại mã này theo Quy tắc nội bộ. Bạn có thể yêu thích nó để sử dụng nó trên biểu đồ.
Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.