Daily SD (200 pips/level)

indicator("Daily SD (200 pips/level)", overlay=true, max_lines_count=200, max_labels_count=200)
// Inputs
pipSize = input.float(0.1, "Pip Size", step=0.0001) // 1 pip = 0.1 (เช่น XAUUSD หลายโบรก)
pipsPerSD = input.int(200, "Pips per SD", minval=1) // 200 pips ต่อระดับ
sdCount = input.int(5, "Number of SD levels", minval=1, maxval=10)
showLbl = input.bool(true, "Show labels")
showMid = input.bool(true, "Show daily-open midline")
// Derived
step = pipsPerSD * pipSize
// Daily open (intraday-safe)
dayOpen = request.security(syminfo.tickerid, "D", open, lookahead=barmerge.lookahead_on)
// Detect new day safely (store change result in a variable and coerce to bool)
dayTime = time("D")
dayTimeDiff = ta.change(dayTime) // series int
isNewDay = dayTimeDiff != 0 // series bool
// Rebuild condition
rebuild = barstate.isfirst or isNewDay
// Storage
var line[] lines = array.new_line()
var label[] labels = array.new_label()
if rebuild
// Clear previous drawings
while array.size(lines) > 0
line.delete(array.pop(lines))
while array.size(labels) > 0
label.delete(array.pop(labels))
// Midline
if showMid
m = line.new(bar_index, dayOpen, bar_index + 1, dayOpen, xloc=xloc.bar_index, extend=extend.right, color=color.gray, width=2)
array.push(lines, m)
if showLbl
ml = label.new(bar_index, dayOpen, "Open", style=label.style_label_left, textcolor=color.white, color=color.gray)
array.push(labels, ml)
// ±SD levels
for i = 1 to sdCount
up = dayOpen + step * i
dn = dayOpen - step * i
lu = line.new(bar_index, up, bar_index + 1, up, xloc=xloc.bar_index, extend=extend.right, color=color.teal, style=line.style_dotted)
ld = line.new(bar_index, dn, bar_index + 1, dn, xloc=xloc.bar_index, extend=extend.right, color=color.orange, style=line.style_dotted)
array.push(lines, lu)
array.push(lines, ld)
if showLbl
lbu = label.new(bar_index, up, "+SD" + str.tostring(i), style=label.style_label_left, textcolor=color.white, color=color.teal)
lbd = label.new(bar_index, dn, "-SD" + str.tostring(i), style=label.style_label_left, textcolor=color.white, color=color.orange)
array.push(labels, lbu)
array.push(labels, lbd)
Tập lệnh chỉ hiển thị cho người được mời
Chỉ những người dùng được tác giả đồng ý mới có thể truy cập tập lệnh này. Bạn cần yêu cầu và xin phép sử dụng tập lệnh này. Quyền truy cập thường được cấp sau khi thanh toán. Để biết thêm chi tiết, hãy làm theo hướng dẫn của tác giả bên dưới hoặc liên hệ trực tiếp với View_Yui.
TradingView KHÔNG khuyến khích trả tiền hoặc sử dụng tập lệnh trừ khi bạn hoàn toàn tin tưởng tác giả và hiểu cách hoạt động của tập lệnh. Bạn cũng có thể tìm thấy các giải pháp thay thế miễn phí, mã nguồn mở trong mục tập lệnh cộng đồng của chúng tôi.
Hướng dẫn của tác giả
Thông báo miễn trừ trách nhiệm
Tập lệnh chỉ hiển thị cho người được mời
Chỉ những người dùng được tác giả đồng ý mới có thể truy cập tập lệnh này. Bạn cần yêu cầu và xin phép sử dụng tập lệnh này. Quyền truy cập thường được cấp sau khi thanh toán. Để biết thêm chi tiết, hãy làm theo hướng dẫn của tác giả bên dưới hoặc liên hệ trực tiếp với View_Yui.
TradingView KHÔNG khuyến khích trả tiền hoặc sử dụng tập lệnh trừ khi bạn hoàn toàn tin tưởng tác giả và hiểu cách hoạt động của tập lệnh. Bạn cũng có thể tìm thấy các giải pháp thay thế miễn phí, mã nguồn mở trong mục tập lệnh cộng đồng của chúng tôi.