INVITE-ONLY SCRIPT

Daily SD (200 pips/level)

30
//version=6
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)

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.