OPEN-SOURCE SCRIPT

Previous Day/Week/Month Rays

//version=5
indicator("Previous Day/Week/Month Rays", overlay=true)

// Fetch the high/low for the previous day, week, and month
prevDayHigh = request.security(syminfo.tickerid, "D", high[1], lookahead=barmerge.lookahead_on)
prevDayLow = request.security(syminfo.tickerid, "D", low[1], lookahead=barmerge.lookahead_on)

prevWeekHigh = request.security(syminfo.tickerid, "W", high[1], lookahead=barmerge.lookahead_on)
prevWeekLow = request.security(syminfo.tickerid, "W", low[1], lookahead=barmerge.lookahead_on)

prevMonthHigh = request.security(syminfo.tickerid, "M", high[1], lookahead=barmerge.lookahead_on)
prevMonthLow = request.security(syminfo.tickerid, "M", low[1], lookahead=barmerge.lookahead_on)

// Determine time points (UNIX timestamps) for anchoring the rays
prevDayTime = request.security(syminfo.tickerid, "D", time[1], lookahead=barmerge.lookahead_on)
prevWeekTime = request.security(syminfo.tickerid, "W", time[1], lookahead=barmerge.lookahead_on)
prevMonthTime = request.security(syminfo.tickerid, "M", time[1], lookahead=barmerge.lookahead_on)

// Create variables to store the rays
var line dayHighRay = na
var line dayLowRay = na
var line weekHighRay = na
var line weekLowRay = na
var line monthHighRay = na
var line monthLowRay = na

// Create or update the rays using time for x-coordinates
if na(dayHighRay)
dayHighRay := line.new(x1=prevDayTime, y1=prevDayHigh, x2=timestamp("2100-01-01 00:00"), y2=prevDayHigh, color=color.green, width=1, extend=extend.right, xloc=xloc.bar_time)

if na(dayLowRay)
dayLowRay := line.new(x1=prevDayTime, y1=prevDayLow, x2=timestamp("2100-01-01 00:00"), y2=prevDayLow, color=color.green, width=1, extend=extend.right, xloc=xloc.bar_time)

if na(weekHighRay)
weekHighRay := line.new(x1=prevWeekTime, y1=prevWeekHigh, x2=timestamp("2100-01-01 00:00"), y2=prevWeekHigh, color=color.white, width=1, extend=extend.right, xloc=xloc.bar_time)

if na(weekLowRay)
weekLowRay := line.new(x1=prevWeekTime, y1=prevWeekLow, x2=timestamp("2100-01-01 00:00"), y2=prevWeekLow, color=color.white, width=1, extend=extend.right, xloc=xloc.bar_time)

if na(monthHighRay)
monthHighRay := line.new(x1=prevMonthTime, y1=prevMonthHigh, x2=timestamp("2100-01-01 00:00"), y2=prevMonthHigh, color=color.red, width=1, extend=extend.right, xloc=xloc.bar_time)

if na(monthLowRay)
monthLowRay := line.new(x1=prevMonthTime, y1=prevMonthLow, x2=timestamp("2100-01-01 00:00"), y2=prevMonthLow, color=color.red, width=1, extend=extend.right, xloc=xloc.bar_time)

// Update the rays dynamically
line.set_xy1(dayHighRay, prevDayTime, prevDayHigh)
line.set_xy2(dayHighRay, timestamp("2100-01-01 00:00"), prevDayHigh)

line.set_xy1(dayLowRay, prevDayTime, prevDayLow)
line.set_xy2(dayLowRay, timestamp("2100-01-01 00:00"), prevDayLow)

line.set_xy1(weekHighRay, prevWeekTime, prevWeekHigh)
line.set_xy2(weekHighRay, timestamp("2100-01-01 00:00"), prevWeekHigh)

line.set_xy1(weekLowRay, prevWeekTime, prevWeekLow)
line.set_xy2(weekLowRay, timestamp("2100-01-01 00:00"), prevWeekLow)

line.set_xy1(monthHighRay, prevMonthTime, prevMonthHigh)
line.set_xy2(monthHighRay, timestamp("2100-01-01 00:00"), prevMonthHigh)

line.set_xy1(monthLowRay, prevMonthTime, prevMonthLow)
line.set_xy2(monthLowRay, timestamp("2100-01-01 00:00"), prevMonthLow)

// Handle timeframe-specific logic
isMonthTimeframe = timeframe.ismonthly
isWeekTimeframe = timeframe.isweekly

// Remove irrelevant rays for higher timeframes
if isMonthTimeframe
line.delete(dayHighRay)
line.delete(dayLowRay)
line.delete(weekHighRay)
line.delete(weekLowRay)

if isWeekTimeframe
line.delete(dayHighRay)
line.delete(dayLowRay)
Candlestick analysisChart patterns

오픈 소스 스크립트

진정한 TradingView 정신에 따라, 이 스크립트의 저자는 트레이더들이 이해하고 검증할 수 있도록 오픈 소스로 공개했습니다. 저자에게 박수를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 출판물에서 이 코드를 재사용하는 것은 하우스 룰에 의해 관리됩니다. 님은 즐겨찾기로 이 스크립트를 차트에서 쓸 수 있습니다.

차트에 이 스크립트를 사용하시겠습니까?

면책사항