本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("DD Bands Daily and Sessions", overlay=true, max_labels_count=20)
// ── Visibility
showDay = input.bool(true, "Show daily band", group="Visibility")
showNY = input.bool(true, "Show New York band", group="Visibility")
showLondon = input.bool(true, "Show London band", group="Visibility")
showTokyo = input.bool(true, "Show Tokyo band", group="Visibility")
showTags = input.bool(false, "Show chart tags", group="Visibility")
// ── Calculation
atrLength = input.int(14, "Daily ATR period", minval=1, group="Calculation")
dayMult = input.float(1.0, "Daily band multiplier", minval=0.1, step=0.1, group="Calculation")
sessionMult = input.float(0.5, "Session band multiplier", minval=0.1, step=0.1, group="Calculation")
// ── Session hours
nyHours = input.session("0930-1600:12345", "New York hours", group="Sessions")
londonHours = input.session("0800-1630:12345", "London hours", group="Sessions")
tokyoHours = input.session("0900-1500:12345", "Tokyo hours", group="Sessions")
// ── Tag appearance
tagSizeChoice = input.string(
"Tiny",
"Tag size",
options=["Tiny", "Small", "Normal", "Large"],
group="Tags")
tagOffsetBars = input.int(
2,
"Horizontal offset (bars)",
minval=1,
maxval=100,
group="Tags")
tagGapTicks = input.int(
0,
"Vertical offset (ticks)",
minval=0,
maxval=100,
group="Tags")
dailyColor = input.color(color.aqua, "Daily color", group="Colors")
nyColor = input.color(color.orange, "New York color", group="Colors")
londonColor = input.color(color.fuchsia, "London color", group="Colors")
tokyoColor = input.color(color.yellow, "Tokyo color", group="Colors")
tagSize = switch tagSizeChoice
"Tiny" => size.tiny
"Small" => size.small
"Normal" => size.normal
"Large" => size.large
// ── Previous completed daily close and ATR
previousClose = request.security(
syminfo.tickerid,
"1D",
close[1],
gaps=barmerge.gaps_off,
lookahead=barmerge.lookahead_on)
previousATR = request.security(
syminfo.tickerid,
"1D",
ta.atr(atrLength)[1],
gaps=barmerge.gaps_off,
lookahead=barmerge.lookahead_on)
// ── Daily bands
dailyUp = previousClose + previousATR * dayMult
dailyDown = previousClose - previousATR * dayMult
// Plot values are hidden from the price scale and status line.
plot(
showDay ? dailyUp : na,
"Daily DD up",
color=color.new(dailyColor, 10),
linewidth=1,
style=plot.style_stepline,
display=display.all - display.price_scale - display.status_line)
plot(
showDay ? dailyDown : na,
"Daily DD down",
color=color.new(dailyColor, 10),
linewidth=1,
style=plot.style_stepline,
display=display.all - display.price_scale - display.status_line)
// ── Session detection using each market's local time zone
inNY = not na(time(timeframe.period, nyHours, "America/New_York"))
inLondon = not na(time(timeframe.period, londonHours, "Europe/London"))
inTokyo = not na(time(timeframe.period, tokyoHours, "Asia/Tokyo"))
newNY = inNY and not inNY[1]
newLondon = inLondon and not inLondon[1]
newTokyo = inTokyo and not inTokyo[1]
// ── Store each session's opening price
var float nyOpen = na
var float londonOpen = na
var float tokyoOpen = na
if newNY
nyOpen := open
if newLondon
londonOpen := open
if newTokyo
tokyoOpen := open
// ── Session bands, centered on each session open
nyUp = nyOpen + previousATR * sessionMult
nyDown = nyOpen - previousATR * sessionMult
londonUp = londonOpen + previousATR * sessionMult
londonDown = londonOpen - previousATR * sessionMult
tokyoUp = tokyoOpen + previousATR * sessionMult
tokyoDown = tokyoOpen - previousATR * sessionMult
plot(
showNY ? nyUp : na,
"NY DD up",
color=color.new(nyColor, 10),
linewidth=1,
style=plot.style_stepline,
display=display.all - display.price_scale - display.status_line)
plot(
showNY ? nyDown : na,
"NY DD down",
color=color.new(nyColor, 10),
linewidth=1,
style=plot.style_stepline,
display=display.all - display.price_scale - display.status_line)
plot(
showLondon ? londonUp : na,
"London DD up",
color=color.new(londonColor, 15),
linewidth=1,
style=plot.style_stepline,
display=display.all - display.price_scale - display.status_line)
plot(
showLondon ? londonDown : na,
"London DD down",
color=color.new(londonColor, 15),
linewidth=1,
style=plot.style_stepline,
display=display.all - display.price_scale - display.status_line)
plot(
showTokyo ? tokyoUp : na,
"Tokyo DD up",
color=color.new(tokyoColor, 15),
linewidth=1,
style=plot.style_stepline,
display=display.all - display.price_scale - display.status_line)
plot(
showTokyo ? tokyoDown : na,
"Tokyo DD down",
color=color.new(tokyoColor, 15),
linewidth=1,
style=plot.style_stepline,
display=display.all - display.price_scale - display.status_line)
// ── Create or update a tag at the chart's right edge
updateTag(
label currentTag,
bool visible,
float price,
string tagText,
color tagColor,
int direction) =>
label result = currentTag
if barstate.islast
if visible and not na(price)
float tagPrice = price + syminfo.mintick * tagGapTicks * direction
if na(result)
result := label.new(
bar_index + tagOffsetBars,
tagPrice,
tagText,
style=label.style_label_left,
color=color.new(tagColor, 82),
textcolor=tagColor,
size=tagSize)
else
label.set_xy(result, bar_index + tagOffsetBars, tagPrice)
label.set_text(result, tagText)
label.set_color(result, color.new(tagColor, 82))
label.set_textcolor(result, tagColor)
label.set_size(result, tagSize)
else
if not na(result)
label.delete(result)
result := na
result
// ── Tags
var label dailyUpTag = na
var label dailyDownTag = na
var label nyUpTag = na
var label nyDownTag = na
var label londonUpTag = na
var label londonDownTag = na
var label tokyoUpTag = na
var label tokyoDownTag = na
dailyUpTag := updateTag(
dailyUpTag, showTags and showDay, dailyUp, "DDBand Day+", dailyColor, 1)
dailyDownTag := updateTag(
dailyDownTag, showTags and showDay, dailyDown, "DDBand Day-", dailyColor, -1)
nyUpTag := updateTag(
nyUpTag, showTags and showNY, nyUp, "DDBand NY+", nyColor, 1)
nyDownTag := updateTag(
nyDownTag, showTags and showNY, nyDown, "DDBand NY-", nyColor, -1)
londonUpTag := updateTag(
londonUpTag, showTags and showLondon, londonUp, "DDBand London+", londonColor, 1)
londonDownTag := updateTag(
londonDownTag, showTags and showLondon, londonDown, "DDBand London-", londonColor, -1)
tokyoUpTag := updateTag(
tokyoUpTag, showTags and showTokyo, tokyoUp, "DDBand Tokyo+", tokyoColor, 1)
tokyoDownTag := updateTag(
tokyoDownTag, showTags and showTokyo, tokyoDown, "DDBand Tokyo-", tokyoColor, -1)