OPEN-SOURCE SCRIPT
Peak Support/Resistance Lines v1

//version=6
indicator("Peak Support/Resistance Lines", shorttitle="Peak S/R", overlay=true, max_lines_count=500)
// Input parameters
lookback = input.int(5, title="Lookback Period", minval=1, maxval=50)
show_resistance = input.bool(true, title="Show Resistance Lines")
show_support = input.bool(true, title="Show Support Lines")
resistance_color = input.color(color.red, title="Resistance Color")
support_color = input.color(color.green, title="Support Color")
// Function to check if current bar is a peak
is_peak() =>
ta.pivothigh(high, lookback, lookback)
// Function to check if current bar is a valley
is_valley() =>
ta.pivotlow(low, lookback, lookback)
// Main logic
if barstate.isconfirmed
// Check for resistance peaks
if show_resistance
peak_price = is_peak()
if not na(peak_price)
line.new(x1=bar_index - lookback, y1=peak_price, x2=bar_index + 50, y2=peak_price, color=resistance_color, width=1)
// Check for support valleys
if show_support
valley_price = is_valley()
if not na(valley_price)
line.new(x1=bar_index - lookback, y1=valley_price, x2=bar_index + 50, y2=valley_price, color=support_color, width=1)
indicator("Peak Support/Resistance Lines", shorttitle="Peak S/R", overlay=true, max_lines_count=500)
// Input parameters
lookback = input.int(5, title="Lookback Period", minval=1, maxval=50)
show_resistance = input.bool(true, title="Show Resistance Lines")
show_support = input.bool(true, title="Show Support Lines")
resistance_color = input.color(color.red, title="Resistance Color")
support_color = input.color(color.green, title="Support Color")
// Function to check if current bar is a peak
is_peak() =>
ta.pivothigh(high, lookback, lookback)
// Function to check if current bar is a valley
is_valley() =>
ta.pivotlow(low, lookback, lookback)
// Main logic
if barstate.isconfirmed
// Check for resistance peaks
if show_resistance
peak_price = is_peak()
if not na(peak_price)
line.new(x1=bar_index - lookback, y1=peak_price, x2=bar_index + 50, y2=peak_price, color=resistance_color, width=1)
// Check for support valleys
if show_support
valley_price = is_valley()
if not na(valley_price)
line.new(x1=bar_index - lookback, y1=valley_price, x2=bar_index + 50, y2=valley_price, color=support_color, width=1)
Mã nguồn mở
Theo đúng tinh thần TradingView, người tạo ra tập lệnh này đã biến tập lệnh thành mã nguồn mở để các nhà giao dịch có thể xem xét và xác minh công năng. Xin dành lời khen tặng cho tác giả! Mặc dù bạn có thể sử dụng miễn phí, nhưng lưu ý nếu đăng lại mã, bạn phải tuân theo Quy tắc nội bộ của chúng tôi.
Thông báo miễn trừ trách nhiệm
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.
Mã nguồn mở
Theo đúng tinh thần TradingView, người tạo ra tập lệnh này đã biến tập lệnh thành mã nguồn mở để các nhà giao dịch có thể xem xét và xác minh công năng. Xin dành lời khen tặng cho tác giả! Mặc dù bạn có thể sử dụng miễn phí, nhưng lưu ý nếu đăng lại mã, bạn phải tuân theo Quy tắc nội bộ của chúng tôi.
Thông báo miễn trừ trách nhiệm
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.