本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("TTD - Daily Premarket Weekly Levels", overlay=true, max_lines_count=50, max_labels_count=50)
// SETTINGS
showPD = input.bool(true, "Show Previous Day High/Low")
showPM = input.bool(true, "Show Premarket High/Low")
showPW = input.bool(true, "Show Previous Week High/Low")
pdColor = input.color(color.yellow, "Previous Day Color")
pmColor = input.color(color.aqua, "Premarket Color")
pwColor = input.color(color.fuchsia, "Previous Week Color")
lineWidth = input.int(2, "Line Width", minval=1, maxval=5)
showLabels = input.bool(true, "Show Price Labels")
labelOffset = input.int(3, "Label Offset", minval=0, maxval=50)
// PREVIOUS DAY LEVELS
pdh = request.security(syminfo.tickerid, "D", high[1], lookahead=barmerge.lookahead_on)
pdl = request.security(syminfo.tickerid, "D", low[1], lookahead=barmerge.lookahead_on)
// PREVIOUS WEEK LEVELS
pwh = request.security(syminfo.tickerid, "W", high[1], lookahead=barmerge.lookahead_on)
pwl = request.security(syminfo.tickerid, "W", low[1], lookahead=barmerge.lookahead_on)
// PREMARKET SESSION (NEW YORK TIME)
pmSession = input.session("0400-0930", "Premarket Session")
inPM = not na(time(timeframe.period, pmSession, "America/New_York"))
newPM = inPM and not inPM[1]
var float pmHigh = na
var float pmLow = na
if newPM
pmHigh := high
pmLow := low
else if inPM
pmHigh := math.max(nz(pmHigh, high), high)
pmLow := math.min(nz(pmLow, low), low)
// PLOT LEVELS
plot(showPD ? pdh : na, "PDH", color=pdColor, linewidth=lineWidth, style=plot.style_stepline)
plot(showPD ? pdl : na, "PDL", color=pdColor, linewidth=lineWidth, style=plot.style_stepline)
plot(showPM ? pmHigh : na, "PMH", color=pmColor, linewidth=lineWidth, style=plot.style_stepline)
plot(showPM ? pmLow : na, "PML", color=pmColor, linewidth=lineWidth, style=plot.style_stepline)
plot(showPW ? pwh : na, "PWH", color=pwColor, linewidth=lineWidth, style=plot.style_stepline)
plot(showPW ? pwl : na, "PWL", color=pwColor, linewidth=lineWidth, style=plot.style_stepline)
// PRICE LABELS
var label pdhLabel = na
var label pdlLabel = na
var label pmhLabel = na
var label pmlLabel = na
var label pwhLabel = na
var label pwlLabel = na
if barstate.islast
label.delete(pdhLabel)
label.delete(pdlLabel)
label.delete(pmhLabel)
label.delete(pmlLabel)
label.delete(pwhLabel)
label.delete(pwlLabel)
if showLabels
if showPD
pdhLabel := label.new(bar_index + labelOffset, pdh, "PDH $" + str.tostring(pdh, format.mintick), style=label.style_label_left, color=pdColor, textcolor=color.black)
pdlLabel := label.new(bar_index + labelOffset, pdl, "PDL $" + str.tostring(pdl, format.mintick), style=label.style_label_left, color=pdColor, textcolor=color.black)
if showPM and not na(pmHigh)
pmhLabel := label.new(bar_index + labelOffset, pmHigh, "PMH $" + str.tostring(pmHigh, format.mintick), style=label.style_label_left, color=pmColor, textcolor=color.black)
pmlLabel := label.new(bar_index + labelOffset, pmLow, "PML $" + str.tostring(pmLow, format.mintick), style=label.style_label_left, color=pmColor, textcolor=color.black)
if showPW
pwhLabel := label.new(bar_index + labelOffset, pwh, "PWH $" + str.tostring(pwh, format.mintick), style=label.style_label_left, color=pwColor, textcolor=color.white)
pwlLabel := label.new(bar_index + labelOffset, pwl, "PWL $" + str.tostring(pwl, format.mintick), style=label.style_label_left, color=pwColor, textcolor=color.white)