OPEN-SOURCE SCRIPT

Peak Support/Resistance Lines v1

82
//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)

免責聲明

這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。