Magic Box 49190

itstinotrades · study · 115 行 · 点赞 8 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=6
indicator("Magic Box 49190", overlay=true, max_boxes_count=500, max_lines_count=500)
 
//=====================================================
// TIMEZONE SETTINGS
//=====================================================
 
// Perth remains the fixed reference timezone.
// TradingView converts these timestamps automatically.
referenceTz = "Australia/Perth"
 
//=====================================================
// INPUTS
//=====================================================
 
sessionStr = input.session("1600-2130", "London range session (Perth)")
 
startHour = input.int(22, "Box starts at hour (Perth)", minval=0, maxval=23)
startMin  = input.int(0, "Box starts at minute", minval=0, maxval=59)
 
endHour = input.int(2, "Box ends at hour (Perth)", minval=0, maxval=23)
endMin  = input.int(0, "Box ends at minute", minval=0, maxval=59)
 
lineColor = input.color(color.red, "Red line color")
lineWidth = input.int(1, "Red line width", minval=1, maxval=5)
 
boxColor = input.color(color.red, "Box tint color")
boxTransp = input.int(60, "Box tint transparency", minval=0, maxval=100)
 
showVwap = input.bool(true, "Show VWAP")
vwapColor = input.color(color.black, "VWAP color")
vwapWidth = input.int(1, "VWAP width", minval=1, maxval=5)
 
//=====================================================
// VWAP
//=====================================================
 
plot(showVwap ? ta.vwap(hlc3) : na, "VWAP", color=vwapColor, linewidth=vwapWidth)
 
//=====================================================
// PERTH SESSION DETECTION
//=====================================================
 
// Detect the London range using Perth time.
inLondon = not na(time(timeframe.period, sessionStr, referenceTz))
newLondon = inLondon and not inLondon[1]
 
// Current bar's Perth date.
perthYear = year(time, referenceTz)
perthMonth = month(time, referenceTz)
perthDay = dayofmonth(time, referenceTz)
 
// Build exact Perth timestamps.
startTs = timestamp(referenceTz, perthYear, perthMonth, perthDay, startHour, startMin)
 
endRaw = timestamp(referenceTz, perthYear, perthMonth, perthDay, endHour, endMin)
 
// Handle the box ending after midnight.
endTs = endRaw <= startTs ? endRaw + 86400000 : endRaw
 
//=====================================================
// TRACK LONDON HIGH AND LOW
//=====================================================
 
var float londonHigh = na
var float londonLow = na
var int londonDayTs = na
 
if newLondon
    londonHigh := high
    londonLow := low
    londonDayTs := startTs
 
else if inLondon
    londonHigh := math.max(nz(londonHigh, high), high)
    londonLow := math.min(nz(londonLow, low), low)
 
//=====================================================
// DRAW BOX AND RED LINES
//=====================================================
 
// Detect the first chart bar at or after 10 PM Perth.
crossedStart = time >= startTs and nz(time[1], 0) < startTs and not na(londonHigh) and londonDayTs == startTs
 
if crossedStart
    hi = londonHigh
    lo = londonLow
 
    // Box uses exact Perth timestamps.
    box.new(
         left=startTs,
         top=hi,
         right=endTs,
         bottom=lo,
         xloc=xloc.bar_time,
         bgcolor=color.new(boxColor, boxTransp),
         border_color=color.new(boxColor, 100)
         )
 
    // Matching upper and lower boundaries.
    line.new(
         startTs, hi,
         endTs, hi,
         xloc=xloc.bar_time,
         color=lineColor,
         width=lineWidth
         )
 
    line.new(
         startTs, lo,
         endTs, lo,
         xloc=xloc.bar_time,
         color=lineColor,
         width=lineWidth
         )

← 返回列表