TTG Brick Strategy Day Swing Mini Bricks

TheTradingGoddess · study · 2898 行 · 点赞 9 · TradingView 原页

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

Pine Script

//@version=6
indicator(
     "TTG Brick Strategy Day Swing Updated alerts",
     overlay = true,
     max_boxes_count = 500,
     max_lines_count = 500
)
 
//=====================================================================
// TIME ZONE
//=====================================================================
string TZ = "America/New_York"
 
//=====================================================================
// 1. RANGE SETTINGS
//=====================================================================
groupRanges = "1. RANGE SETTINGS"
 
showON = input.bool(
     true,
     "Toggle 1 — 4PM → 9:30AM",
     group = groupRanges,
     tooltip = "Measures the high/low from 4:00 PM ET through 9:29 AM ET."
)
 
showRTH = input.bool(
     false,
     "Toggle 2 — 9:30AM → 4PM",
     group = groupRanges,
     tooltip = "Measures the regular-session high/low from 9:30 AM through 4:00 PM ET."
)
 
showWeekly = input.bool(
     false,
     "Toggle 3 — Previous Week Swing",
     group = groupRanges,
     tooltip = "Uses the previous completed weekly candle high/low and projects it from the beginning of the current week."
)
 
showMonthly = input.bool(
     false,
     "Toggle 4 — Previous Month Swing",
     group = groupRanges,
     tooltip = "Uses the previous completed monthly candle high/low and projects it from the beginning of the current month."
)
 
maxContinuationBricks = input.int(
     6,
     "Max Continuation Bricks Per Side",
     minval = 1,
     maxval = 12,
     group = groupRanges
)
 
//=====================================================================
// 2. BOX APPEARANCE
//=====================================================================
groupBox = "2. BOX APPEARANCE"
 
centerColor = input.color(
     color.rgb(205, 235, 245),
     "Center Rectangle",
     group = groupBox
)
 
upperInactiveColor = input.color(
     color.rgb(185, 215, 190),
     "Upper Rectangle",
     group = groupBox
)
 
lowerInactiveColor = input.color(
     color.rgb(245, 190, 205),
     "Lower Rectangle",
     group = groupBox
)
 
upperActiveColor = input.color(
     color.green,
     "Upper ACTIVE Color",
     group = groupBox
)
 
lowerActiveColor = input.color(
     color.red,
     "Lower ACTIVE Color",
     group = groupBox
)
 
boxTransparency = input.int(
     78,
     "Normal Transparency",
     minval = 0,
     maxval = 100,
     group = groupBox
)
 
activeTransparency = input.int(
     68,
     "Active Transparency",
     minval = 0,
     maxval = 100,
     group = groupBox
)
 
borderColor = input.color(
     color.black,
     "Border Color",
     group = groupBox
)
 
borderWidth = input.int(
     2,
     "Border Width",
     minval = 1,
     maxval = 5,
     group = groupBox
)
 
//=====================================================================
// 3. MIDLINE SETTINGS
//=====================================================================
groupMid = "3. MIDLINE"
 
showMidline = input.bool(
     true,
     "Show Rectangle Midlines",
     group = groupMid
)
 
midlineColor = input.color(
     color.red,
     "Midline Color",
     group = groupMid
)
 
midlineTicks = input.int(
     3,
     "Midline Thickness",
     minval = 1,
     maxval = 20,
     group = groupMid
)
 
float midThickness = syminfo.mintick * midlineTicks
float halfMidThickness = midThickness / 2.0
 
//=====================================================================
// SECONDARY DASHED BRICK LINE
//=====================================================================
showSecondaryLine = input.bool(
     true,
     "Show Secondary Dashed Line",
     group = groupMid
)
 
showUpperSecondaryLine = input.bool(
     false,
     "Show Upper Secondary Dashed Line",
     group = groupMid,
     tooltip = "Adds a mirrored dashed level near the upper end of every brick. Uses the same percentage, color, and width as the lower secondary dashed line."
)
 
secondaryLinePercent = input.float(
     25.0,
     "Secondary Line Position %",
     minval = 0.0,
     maxval = 100.0,
     step = 1.0,
     group = groupMid,
     tooltip = "Position inside EACH brick measured from the brick bottom. 25 = lower quarter, 50 = middle, 75 = upper quarter."
)
 
secondaryLineColor = input.color(
     color.gray,
     "Secondary Dashed Line Color",
     group = groupMid
)
 
secondaryLineWidth = input.int(
     1,
     "Secondary Dashed Line Width",
     minval = 1,
     maxval = 4,
     group = groupMid
)
 
float secondaryPct = secondaryLinePercent / 100.0
 
// Base secondary dashed lines
var line onBullSecondary = na
var line onCenterSecondary = na
var line onBearSecondary = na
var line rthBullSecondary = na
var line rthCenterSecondary = na
var line rthBearSecondary = na
var line weekBullSecondary = na
var line weekCenterSecondary = na
var line weekBearSecondary = na
var line monthBullSecondary = na
var line monthCenterSecondary = na
var line monthBearSecondary = na
 
// Continuation-brick secondary dashed lines
var array<line> onUpSecondaryExt = array.new<line>()
var array<line> onDownSecondaryExt = array.new<line>()
var array<line> rthUpSecondaryExt = array.new<line>()
var array<line> rthDownSecondaryExt = array.new<line>()
var array<line> weekUpSecondaryExt = array.new<line>()
var array<line> weekDownSecondaryExt = array.new<line>()
var array<line> monthUpSecondaryExt = array.new<line>()
var array<line> monthDownSecondaryExt = array.new<line>()
 
// Mirrored upper secondary dashed lines — independently toggled
var line onBullUpperSecondary = na
var line onCenterUpperSecondary = na
var line onBearUpperSecondary = na
var line rthBullUpperSecondary = na
var line rthCenterUpperSecondary = na
var line rthBearUpperSecondary = na
var line weekBullUpperSecondary = na
var line weekCenterUpperSecondary = na
var line weekBearUpperSecondary = na
var line monthBullUpperSecondary = na
var line monthCenterUpperSecondary = na
var line monthBearUpperSecondary = na
 
var array<line> onUpUpperSecondaryExt = array.new<line>()
var array<line> onDownUpperSecondaryExt = array.new<line>()
var array<line> rthUpUpperSecondaryExt = array.new<line>()
var array<line> rthDownUpperSecondaryExt = array.new<line>()
var array<line> weekUpUpperSecondaryExt = array.new<line>()
var array<line> weekDownUpperSecondaryExt = array.new<line>()
var array<line> monthUpUpperSecondaryExt = array.new<line>()
var array<line> monthDownUpperSecondaryExt = array.new<line>()
 
//=====================================================================
// 4. ALERT SETTINGS
//=====================================================================
groupAlerts = "4. ALERT SETTINGS"
 
enableAlerts = input.bool(
     true,
     "Enable Alerts",
     group = groupAlerts
)
 
alertOnClose = input.bool(
     true,
     "Require Candle Close",
     group = groupAlerts
)
 
bool alertConfirmed =
     not alertOnClose or
     barstate.isconfirmed
 
//=====================================================================
// HELPER — DELETE BOX ARRAY
//=====================================================================
f_delete_boxes(array<box> arr) =>
    int count = array.size(arr)
 
    if count > 0
        for i = 0 to count - 1
            box b = array.get(arr, i)
 
            if not na(b)
                box.delete(b)
 
    array.clear(arr)
 
//=====================================================================
// SESSION LOGIC
//=====================================================================
int hh = hour(time, TZ)
int mm = minute(time, TZ)
 
bool after1600 =
     hh >= 16
 
bool before0930 =
     hh < 9 or
     (hh == 9 and mm < 30)
 
bool atOrAfter0930 =
     hh > 9 or
     (hh == 9 and mm >= 30)
 
bool before1600 =
     hh < 16
 
bool inOvernight =
     after1600 or before0930
 
bool inRTH =
     atOrAfter0930 and before1600
 
bool overnightStart =
     inOvernight and not inOvernight[1]
 
bool rthStart =
     inRTH and not inRTH[1]
 
bool onRangeLocked =
     showON and not inOvernight
 
bool rthRangeLocked =
     showRTH and not inRTH and after1600
 
//=====================================================================
// CURRENT WEEK / MONTH START TIMES
// THIS IS THE IMPORTANT SWING FIX
//=====================================================================
int currentWeekStart =
     time("W")
 
int currentMonthStart =
     time("M")
 
bool newWeek =
     ta.change(currentWeekStart) != 0
 
bool newMonth =
     ta.change(currentMonthStart) != 0
 
//=====================================================================
// PREVIOUS COMPLETED WEEK
//=====================================================================
float previousWeekHigh =
     request.security(
          syminfo.tickerid,
          "W",
          high[1],
          gaps = barmerge.gaps_off,
          lookahead = barmerge.lookahead_on
     )
 
float previousWeekLow =
     request.security(
          syminfo.tickerid,
          "W",
          low[1],
          gaps = barmerge.gaps_off,
          lookahead = barmerge.lookahead_on
     )
 
//=====================================================================
// PREVIOUS COMPLETED MONTH
//=====================================================================
float previousMonthHigh =
     request.security(
          syminfo.tickerid,
          "M",
          high[1],
          gaps = barmerge.gaps_off,
          lookahead = barmerge.lookahead_on
     )
 
float previousMonthLow =
     request.security(
          syminfo.tickerid,
          "M",
          low[1],
          gaps = barmerge.gaps_off,
          lookahead = barmerge.lookahead_on
     )
 
//#####################################################################
// TOGGLE 1 VARIABLES
//#####################################################################
var float onHigh = na
var float onLow = na
var int onLeft = na
 
var box onUpperBox = na
var box onCenterBox = na
var box onLowerBox = na
 
var box onUpperMidBox = na
var box onCenterMidBox = na
var box onLowerMidBox = na
 
var array<box> onUpExt = array.new<box>()
var array<box> onDownExt = array.new<box>()
 
var array<box> onUpMidExt = array.new<box>()
var array<box> onDownMidExt = array.new<box>()
 
//#####################################################################
// TOGGLE 2 VARIABLES
//#####################################################################
var float rthHigh = na
var float rthLow = na
var int rthLeft = na
 
var box rthUpperBox = na
var box rthCenterBox = na
var box rthLowerBox = na
 
var box rthUpperMidBox = na
var box rthCenterMidBox = na
var box rthLowerMidBox = na
 
var array<box> rthUpExt = array.new<box>()
var array<box> rthDownExt = array.new<box>()
 
var array<box> rthUpMidExt = array.new<box>()
var array<box> rthDownMidExt = array.new<box>()
 
//#####################################################################
// TOGGLE 3 VARIABLES — WEEKLY
//#####################################################################
var box weekUpperBox = na
var box weekCenterBox = na
var box weekLowerBox = na
 
var box weekUpperMidBox = na
var box weekCenterMidBox = na
var box weekLowerMidBox = na
 
var array<box> weekUpExt = array.new<box>()
var array<box> weekDownExt = array.new<box>()
 
var array<box> weekUpMidExt = array.new<box>()
var array<box> weekDownMidExt = array.new<box>()
 
var int storedWeekStart = na
 
//#####################################################################
// TOGGLE 4 VARIABLES — MONTHLY
//#####################################################################
var box monthUpperBox = na
var box monthCenterBox = na
var box monthLowerBox = na
 
var box monthUpperMidBox = na
var box monthCenterMidBox = na
var box monthLowerMidBox = na
 
var array<box> monthUpExt = array.new<box>()
var array<box> monthDownExt = array.new<box>()
 
var array<box> monthUpMidExt = array.new<box>()
var array<box> monthDownMidExt = array.new<box>()
 
var int storedMonthStart = na
 
//#####################################################################
// TOGGLE 1 — 4PM → 9:30AM
//#####################################################################
 
//=====================================================================
// RESET OVERNIGHT
//=====================================================================
if overnightStart
 
    if not na(onUpperBox)
        box.delete(onUpperBox)
 
    if not na(onCenterBox)
        box.delete(onCenterBox)
 
    if not na(onLowerBox)
        box.delete(onLowerBox)
 
    if not na(onUpperMidBox)
        box.delete(onUpperMidBox)
 
    if not na(onCenterMidBox)
        box.delete(onCenterMidBox)
 
    if not na(onLowerMidBox)
        box.delete(onLowerMidBox)
 
    f_delete_boxes(onUpExt)
    f_delete_boxes(onDownExt)
    f_delete_boxes(onUpMidExt)
    f_delete_boxes(onDownMidExt)
 
    onUpperBox := na
    onCenterBox := na
    onLowerBox := na
 
    onUpperMidBox := na
    onCenterMidBox := na
    onLowerMidBox := na
 
    onHigh := high
    onLow := low
    onLeft := time
 
//=====================================================================
// MEASURE OVERNIGHT
//=====================================================================
if inOvernight
 
    if na(onHigh)
        onHigh := high
 
    if na(onLow)
        onLow := low
 
    if na(onLeft)
        onLeft := time
 
    onHigh := math.max(onHigh, high)
    onLow := math.min(onLow, low)
 
//=====================================================================
// DRAW TOGGLE 1
//=====================================================================
if showON and not na(onHigh) and not na(onLow)
 
    float onRange =
         onHigh - onLow
 
    if onRange > 0
 
        float upperTop =
             onHigh + onRange
 
        float upperBottom =
             onHigh
 
        float upperMid =
             onHigh + onRange / 2.0
 
 
        float centerTop =
             onHigh
 
        float centerBottom =
             onLow
 
        float centerMid =
             onLow + onRange / 2.0
 
 
        float lowerTop =
             onLow
 
        float lowerBottom =
             onLow - onRange
 
        float lowerMid =
             onLow - onRange / 2.0
 
        //-------------------------------------------------------------
        // CREATE ORIGINAL 3
        //-------------------------------------------------------------
        if na(onCenterBox)
 
            onUpperBox := box.new(
                 left = onLeft,
                 top = upperTop,
                 right = time,
                 bottom = upperBottom,
                 xloc = xloc.bar_time,
                 extend = extend.right,
                 border_color = borderColor,
                 border_width = borderWidth,
                 bgcolor = color.new(
                      upperInactiveColor,
                      boxTransparency
                 )
            )
 
            onCenterBox := box.new(
                 left = onLeft,
                 top = centerTop,
                 right = time,
                 bottom = centerBottom,
                 xloc = xloc.bar_time,
                 extend = extend.right,
                 border_color = borderColor,
                 border_width = borderWidth,
                 bgcolor = color.new(
                      centerColor,
                      boxTransparency
                 )
            )
 
            onLowerBox := box.new(
                 left = onLeft,
                 top = lowerTop,
                 right = time,
                 bottom = lowerBottom,
                 xloc = xloc.bar_time,
                 extend = extend.right,
                 border_color = borderColor,
                 border_width = borderWidth,
                 bgcolor = color.new(
                      lowerInactiveColor,
                      boxTransparency
                 )
            )
 
        //-------------------------------------------------------------
        // UPDATE WHILE RANGE DEVELOPS
        //-------------------------------------------------------------
        if inOvernight
 
            box.set_top(
                 onUpperBox,
                 upperTop
            )
 
            box.set_bottom(
                 onUpperBox,
                 upperBottom
            )
 
            box.set_top(
                 onCenterBox,
                 centerTop
            )
 
            box.set_bottom(
                 onCenterBox,
                 centerBottom
            )
 
            box.set_top(
                 onLowerBox,
                 lowerTop
            )
 
            box.set_bottom(
                 onLowerBox,
                 lowerBottom
            )
 
        //-------------------------------------------------------------
        // MIDLINES
        //-------------------------------------------------------------
        if showMidline
 
            if na(onUpperMidBox)
 
                onUpperMidBox := box.new(
                     left = onLeft,
                     top = upperMid + halfMidThickness,
                     right = time,
                     bottom = upperMid - halfMidThickness,
                     xloc = xloc.bar_time,
                     extend = extend.right,
                     border_color = midlineColor,
                     border_width = 1,
                     bgcolor = midlineColor
                )
 
            else
 
                box.set_top(
                     onUpperMidBox,
                     upperMid + halfMidThickness
                )
 
                box.set_bottom(
                     onUpperMidBox,
                     upperMid - halfMidThickness
                )
 
            if na(onCenterMidBox)
 
                onCenterMidBox := box.new(
                     left = onLeft,
                     top = centerMid + halfMidThickness,
                     right = time,
                     bottom = centerMid - halfMidThickness,
                     xloc = xloc.bar_time,
                     extend = extend.right,
                     border_color = midlineColor,
                     border_width = 1,
                     bgcolor = midlineColor
                )
 
            else
 
                box.set_top(
                     onCenterMidBox,
                     centerMid + halfMidThickness
                )
 
                box.set_bottom(
                     onCenterMidBox,
                     centerMid - halfMidThickness
                )
 
            if na(onLowerMidBox)
 
                onLowerMidBox := box.new(
                     left = onLeft,
                     top = lowerMid + halfMidThickness,
                     right = time,
                     bottom = lowerMid - halfMidThickness,
                     xloc = xloc.bar_time,
                     extend = extend.right,
                     border_color = midlineColor,
                     border_width = 1,
                     bgcolor = midlineColor
                )
 
            else
 
                box.set_top(
                     onLowerMidBox,
                     lowerMid + halfMidThickness
                )
 
                box.set_bottom(
                     onLowerMidBox,
                     lowerMid - halfMidThickness
                )
 
        //-------------------------------------------------------------
        // COLORS
        //-------------------------------------------------------------
        bool priceInUpper =
             close >= upperBottom and
             close <= upperTop
 
        bool priceInLower =
             close >= lowerBottom and
             close <= lowerTop
 
        box.set_bgcolor(
             onUpperBox,
             priceInUpper
                 ? color.new(
                      upperActiveColor,
                      activeTransparency
                   )
                 : color.new(
                      upperInactiveColor,
                      boxTransparency
                   )
        )
 
        box.set_bgcolor(
             onCenterBox,
             color.new(
                  centerColor,
                  boxTransparency
             )
        )
 
        box.set_bgcolor(
             onLowerBox,
             priceInLower
                 ? color.new(
                      lowerActiveColor,
                      activeTransparency
                   )
                 : color.new(
                      lowerInactiveColor,
                      boxTransparency
                   )
        )
 
        //-------------------------------------------------------------
        // AUTO EXTEND UP
        //-------------------------------------------------------------
        if onRangeLocked and alertConfirmed
 
            int upCount =
                 array.size(onUpExt)
 
            float nextUpBreak =
                 upperTop +
                 onRange * upCount
 
            if close > nextUpBreak and
               upCount < maxContinuationBricks
 
                float newBottom =
                     nextUpBreak
 
                float newTop =
                     newBottom + onRange
 
                float newMid =
                     newBottom + onRange / 2.0
 
                box newBox = box.new(
                     left = onLeft,
                     top = newTop,
                     right = time,
                     bottom = newBottom,
                     xloc = xloc.bar_time,
                     extend = extend.right,
                     border_color = borderColor,
                     border_width = borderWidth,
                     bgcolor = color.new(
                          upperActiveColor,
                          activeTransparency
                     )
                )
 
                array.push(
                     onUpExt,
                     newBox
                )
 
                if showMidline
 
                    box newMidBox = box.new(
                         left = onLeft,
                         top = newMid + halfMidThickness,
                         right = time,
                         bottom = newMid - halfMidThickness,
                         xloc = xloc.bar_time,
                         extend = extend.right,
                         border_color = midlineColor,
                         border_width = 1,
                         bgcolor = midlineColor
                    )
 
                    array.push(
                         onUpMidExt,
                         newMidBox
                    )
 
        //-------------------------------------------------------------
        // AUTO EXTEND DOWN
        //-------------------------------------------------------------
        if onRangeLocked and alertConfirmed
 
            int downCount =
                 array.size(onDownExt)
 
            float nextDownBreak =
                 lowerBottom -
                 onRange * downCount
 
            if close < nextDownBreak and
               downCount < maxContinuationBricks
 
                float newTop =
                     nextDownBreak
 
                float newBottom =
                     newTop - onRange
 
                float newMid =
                     newBottom + onRange / 2.0
 
                box newBox = box.new(
                     left = onLeft,
                     top = newTop,
                     right = time,
                     bottom = newBottom,
                     xloc = xloc.bar_time,
                     extend = extend.right,
                     border_color = borderColor,
                     border_width = borderWidth,
                     bgcolor = color.new(
                          lowerActiveColor,
                          activeTransparency
                     )
                )
 
                array.push(
                     onDownExt,
                     newBox
                )
 
                if showMidline
 
                    box newMidBox = box.new(
                         left = onLeft,
                         top = newMid + halfMidThickness,
                         right = time,
                         bottom = newMid - halfMidThickness,
                         xloc = xloc.bar_time,
                         extend = extend.right,
                         border_color = midlineColor,
                         border_width = 1,
                         bgcolor = midlineColor
                    )
 
                    array.push(
                         onDownMidExt,
                         newMidBox
                    )
 
//#####################################################################
// TOGGLE 2 — 9:30AM → 4PM
//#####################################################################
 
//=====================================================================
// RESET RTH
//=====================================================================
if rthStart
 
    if not na(rthUpperBox)
        box.delete(rthUpperBox)
 
    if not na(rthCenterBox)
        box.delete(rthCenterBox)
 
    if not na(rthLowerBox)
        box.delete(rthLowerBox)
 
    if not na(rthUpperMidBox)
        box.delete(rthUpperMidBox)
 
    if not na(rthCenterMidBox)
        box.delete(rthCenterMidBox)
 
    if not na(rthLowerMidBox)
        box.delete(rthLowerMidBox)
 
    f_delete_boxes(rthUpExt)
    f_delete_boxes(rthDownExt)
    f_delete_boxes(rthUpMidExt)
    f_delete_boxes(rthDownMidExt)
 
    rthUpperBox := na
    rthCenterBox := na
    rthLowerBox := na
 
    rthUpperMidBox := na
    rthCenterMidBox := na
    rthLowerMidBox := na
 
    rthHigh := high
    rthLow := low
    rthLeft := time
 
//=====================================================================
// MEASURE RTH
//=====================================================================
if inRTH
 
    if na(rthHigh)
        rthHigh := high
 
    if na(rthLow)
        rthLow := low
 
    if na(rthLeft)
        rthLeft := time
 
    rthHigh :=
         math.max(
              rthHigh,
              high
         )
 
    rthLow :=
         math.min(
              rthLow,
              low
         )
 
//=====================================================================
// DRAW TOGGLE 2
//=====================================================================
if showRTH and
   not na(rthHigh) and
   not na(rthLow)
 
    float rthRange =
         rthHigh - rthLow
 
    if rthRange > 0
 
        float upperTop =
             rthHigh + rthRange
 
        float upperBottom =
             rthHigh
 
        float upperMid =
             rthHigh + rthRange / 2.0
 
 
        float centerTop =
             rthHigh
 
        float centerBottom =
             rthLow
 
        float centerMid =
             rthLow + rthRange / 2.0
 
 
        float lowerTop =
             rthLow
 
        float lowerBottom =
             rthLow - rthRange
 
        float lowerMid =
             rthLow - rthRange / 2.0
 
        //-------------------------------------------------------------
        // CREATE ORIGINAL 3
        //-------------------------------------------------------------
        if na(rthCenterBox)
 
            rthUpperBox := box.new(
                 left = rthLeft,
                 top = upperTop,
                 right = time,
                 bottom = upperBottom,
                 xloc = xloc.bar_time,
                 extend = extend.right,
                 border_color = borderColor,
                 border_width = borderWidth,
                 bgcolor = color.new(
                      upperInactiveColor,
                      boxTransparency
                 )
            )
 
            rthCenterBox := box.new(
                 left = rthLeft,
                 top = centerTop,
                 right = time,
                 bottom = centerBottom,
                 xloc = xloc.bar_time,
                 extend = extend.right,
                 border_color = borderColor,
                 border_width = borderWidth,
                 bgcolor = color.new(
                      centerColor,
                      boxTransparency
                 )
            )
 
            rthLowerBox := box.new(
                 left = rthLeft,
                 top = lowerTop,
                 right = time,
                 bottom = lowerBottom,
                 xloc = xloc.bar_time,
                 extend = extend.right,
                 border_color = borderColor,
                 border_width = borderWidth,
                 bgcolor = color.new(
                      lowerInactiveColor,
                      boxTransparency
                 )
            )
 
        //-------------------------------------------------------------
        // UPDATE RTH RANGE
        //-------------------------------------------------------------
        if inRTH
 
            box.set_top(
                 rthUpperBox,
                 upperTop
            )
 
            box.set_bottom(
                 rthUpperBox,
                 upperBottom
            )
 
            box.set_top(
                 rthCenterBox,
                 centerTop
            )
 
            box.set_bottom(
                 rthCenterBox,
                 centerBottom
            )
 
            box.set_top(
                 rthLowerBox,
                 lowerTop
            )
 
            box.set_bottom(
                 rthLowerBox,
                 lowerBottom
            )
 
        //-------------------------------------------------------------
        // MIDLINES
        //-------------------------------------------------------------
        if showMidline
 
            if na(rthUpperMidBox)
 
                rthUpperMidBox := box.new(
                     left = rthLeft,
                     top = upperMid + halfMidThickness,
                     right = time,
                     bottom = upperMid - halfMidThickness,
                     xloc = xloc.bar_time,
                     extend = extend.right,
                     border_color = midlineColor,
                     border_width = 1,
                     bgcolor = midlineColor
                )
 
            else
 
                box.set_top(
                     rthUpperMidBox,
                     upperMid + halfMidThickness
                )
 
                box.set_bottom(
                     rthUpperMidBox,
                     upperMid - halfMidThickness
                )
 
            if na(rthCenterMidBox)
 
                rthCenterMidBox := box.new(
                     left = rthLeft,
                     top = centerMid + halfMidThickness,
                     right = time,
                     bottom = centerMid - halfMidThickness,
                     xloc = xloc.bar_time,
                     extend = extend.right,
                     border_color = midlineColor,
                     border_width = 1,
                     bgcolor = midlineColor
                )
 
            else
 
                box.set_top(
                     rthCenterMidBox,
                     centerMid + halfMidThickness
                )
 
                box.set_bottom(
                     rthCenterMidBox,
                     centerMid - halfMidThickness
                )
 
            if na(rthLowerMidBox)
 
                rthLowerMidBox := box.new(
                     left = rthLeft,
                     top = lowerMid + halfMidThickness,
                     right = time,
                     bottom = lowerMid - halfMidThickness,
                     xloc = xloc.bar_time,
                     extend = extend.right,
                     border_color = midlineColor,
                     border_width = 1,
                     bgcolor = midlineColor
                )
 
            else
 
                box.set_top(
                     rthLowerMidBox,
                     lowerMid + halfMidThickness
                )
 
                box.set_bottom(
                     rthLowerMidBox,
                     lowerMid - halfMidThickness
                )
 
        //-------------------------------------------------------------
        // ACTIVE COLORS
        //-------------------------------------------------------------
        bool priceInUpper =
             close >= upperBottom and
             close <= upperTop
 
        bool priceInLower =
             close >= lowerBottom and
             close <= lowerTop
 
        box.set_bgcolor(
             rthUpperBox,
             priceInUpper
                 ? color.new(
                      upperActiveColor,
                      activeTransparency
                   )
                 : color.new(
                      upperInactiveColor,
                      boxTransparency
                   )
        )
 
        box.set_bgcolor(
             rthCenterBox,
             color.new(
                  centerColor,
                  boxTransparency
             )
        )
 
        box.set_bgcolor(
             rthLowerBox,
             priceInLower
                 ? color.new(
                      lowerActiveColor,
                      activeTransparency
                   )
                 : color.new(
                      lowerInactiveColor,
                      boxTransparency
                   )
        )
 
        //-------------------------------------------------------------
        // AUTO EXTEND UP
        //-------------------------------------------------------------
        if rthRangeLocked and alertConfirmed
 
            int upCount =
                 array.size(rthUpExt)
 
            float nextUpBreak =
                 upperTop +
                 rthRange * upCount
 
            if close > nextUpBreak and
               upCount < maxContinuationBricks
 
                float newBottom =
                     nextUpBreak
 
                float newTop =
                     newBottom + rthRange
 
                float newMid =
                     newBottom + rthRange / 2.0
 
                box newBox = box.new(
                     left = rthLeft,
                     top = newTop,
                     right = time,
                     bottom = newBottom,
                     xloc = xloc.bar_time,
                     extend = extend.right,
                     border_color = borderColor,
                     border_width = borderWidth,
                     bgcolor = color.new(
                          upperActiveColor,
                          activeTransparency
                     )
                )
 
                array.push(
                     rthUpExt,
                     newBox
                )
 
                if showMidline
 
                    box newMidBox = box.new(
                         left = rthLeft,
                         top = newMid + halfMidThickness,
                         right = time,
                         bottom = newMid - halfMidThickness,
                         xloc = xloc.bar_time,
                         extend = extend.right,
                         border_color = midlineColor,
                         border_width = 1,
                         bgcolor = midlineColor
                    )
 
                    array.push(
                         rthUpMidExt,
                         newMidBox
                    )
 
        //-------------------------------------------------------------
        // AUTO EXTEND DOWN
        //-------------------------------------------------------------
        if rthRangeLocked and alertConfirmed
 
            int downCount =
                 array.size(rthDownExt)
 
            float nextDownBreak =
                 lowerBottom -
                 rthRange * downCount
 
            if close < nextDownBreak and
               downCount < maxContinuationBricks
 
                float newTop =
                     nextDownBreak
 
                float newBottom =
                     newTop - rthRange
 
                float newMid =
                     newBottom + rthRange / 2.0
 
                box newBox = box.new(
                     left = rthLeft,
                     top = newTop,
                     right = time,
                     bottom = newBottom,
                     xloc = xloc.bar_time,
                     extend = extend.right,
                     border_color = borderColor,
                     border_width = borderWidth,
                     bgcolor = color.new(
                          lowerActiveColor,
                          activeTransparency
                     )
                )
 
                array.push(
                     rthDownExt,
                     newBox
                )
 
                if showMidline
 
                    box newMidBox = box.new(
                         left = rthLeft,
                         top = newMid + halfMidThickness,
                         right = time,
                         bottom = newMid - halfMidThickness,
                         xloc = xloc.bar_time,
                         extend = extend.right,
                         border_color = midlineColor,
                         border_width = 1,
                         bgcolor = midlineColor
                    )
 
                    array.push(
                         rthDownMidExt,
                         newMidBox
                    )
 
//#####################################################################
// TOGGLE 3 — PREVIOUS WEEK SWING
//#####################################################################
 
//=====================================================================
// HIDE WEEKLY WHEN TOGGLE OFF
//=====================================================================
if not showWeekly
 
    if not na(weekUpperBox)
        box.delete(weekUpperBox)
        weekUpperBox := na
 
    if not na(weekCenterBox)
        box.delete(weekCenterBox)
        weekCenterBox := na
 
    if not na(weekLowerBox)
        box.delete(weekLowerBox)
        weekLowerBox := na
 
    if not na(weekUpperMidBox)
        box.delete(weekUpperMidBox)
        weekUpperMidBox := na
 
    if not na(weekCenterMidBox)
        box.delete(weekCenterMidBox)
        weekCenterMidBox := na
 
    if not na(weekLowerMidBox)
        box.delete(weekLowerMidBox)
        weekLowerMidBox := na
 
    f_delete_boxes(weekUpExt)
    f_delete_boxes(weekDownExt)
    f_delete_boxes(weekUpMidExt)
    f_delete_boxes(weekDownMidExt)
 
    storedWeekStart := na
 
//=====================================================================
// RESET AT ACTUAL START OF CURRENT WEEK
//=====================================================================
bool needNewWeeklyStructure =
     showWeekly and
     (
          na(storedWeekStart) or
          storedWeekStart != currentWeekStart
     )
 
if needNewWeeklyStructure
 
    if not na(weekUpperBox)
        box.delete(weekUpperBox)
 
    if not na(weekCenterBox)
        box.delete(weekCenterBox)
 
    if not na(weekLowerBox)
        box.delete(weekLowerBox)
 
    if not na(weekUpperMidBox)
        box.delete(weekUpperMidBox)
 
    if not na(weekCenterMidBox)
        box.delete(weekCenterMidBox)
 
    if not na(weekLowerMidBox)
        box.delete(weekLowerMidBox)
 
    f_delete_boxes(weekUpExt)
    f_delete_boxes(weekDownExt)
    f_delete_boxes(weekUpMidExt)
    f_delete_boxes(weekDownMidExt)
 
    weekUpperBox := na
    weekCenterBox := na
    weekLowerBox := na
 
    weekUpperMidBox := na
    weekCenterMidBox := na
    weekLowerMidBox := na
 
    storedWeekStart :=
         currentWeekStart
 
//=====================================================================
// DRAW WEEKLY SWING
// CENTER = PREVIOUS WEEK'S ACTUAL HIGH / LOW
// LEFT EDGE = CURRENT WEEK START
//=====================================================================
if showWeekly and
   not na(previousWeekHigh) and
   not na(previousWeekLow)
 
    float weekRange =
         previousWeekHigh -
         previousWeekLow
 
    if weekRange > 0
 
        //-------------------------------------------------------------
        // PREVIOUS WEEK CENTER BRICK
        //-------------------------------------------------------------
        float weekCenterTop =
             previousWeekHigh
 
        float weekCenterBottom =
             previousWeekLow
 
        float weekCenterMid =
             previousWeekLow +
             weekRange / 2.0
 
        //-------------------------------------------------------------
        // IDENTICAL CLONE ABOVE
        //-------------------------------------------------------------
        float weekUpperBottom =
             previousWeekHigh
 
        float weekUpperTop =
             previousWeekHigh +
             weekRange
 
        float weekUpperMid =
             previousWeekHigh +
             weekRange / 2.0
 
        //-------------------------------------------------------------
        // IDENTICAL CLONE BELOW
        //-------------------------------------------------------------
        float weekLowerTop =
             previousWeekLow
 
        float weekLowerBottom =
             previousWeekLow -
             weekRange
 
        float weekLowerMid =
             previousWeekLow -
             weekRange / 2.0
 
        //-------------------------------------------------------------
        // CREATE EXACT 3-BRICK WEEKLY STRUCTURE
        //-------------------------------------------------------------
        if na(weekCenterBox)
 
            weekUpperBox := box.new(
                 left = currentWeekStart,
                 top = weekUpperTop,
                 right = time,
                 bottom = weekUpperBottom,
                 xloc = xloc.bar_time,
                 extend = extend.right,
                 border_color = borderColor,
                 border_width = borderWidth,
                 bgcolor = color.new(
                      upperInactiveColor,
                      boxTransparency
                 )
            )
 
            weekCenterBox := box.new(
                 left = currentWeekStart,
                 top = weekCenterTop,
                 right = time,
                 bottom = weekCenterBottom,
                 xloc = xloc.bar_time,
                 extend = extend.right,
                 border_color = borderColor,
                 border_width = borderWidth,
                 bgcolor = color.new(
                      centerColor,
                      boxTransparency
                 )
            )
 
            weekLowerBox := box.new(
                 left = currentWeekStart,
                 top = weekLowerTop,
                 right = time,
                 bottom = weekLowerBottom,
                 xloc = xloc.bar_time,
                 extend = extend.right,
                 border_color = borderColor,
                 border_width = borderWidth,
                 bgcolor = color.new(
                      lowerInactiveColor,
                      boxTransparency
                 )
            )
 
        //-------------------------------------------------------------
        // WEEKLY MIDLINES
        //-------------------------------------------------------------
        if showMidline
 
            if na(weekUpperMidBox)
 
                weekUpperMidBox := box.new(
                     left = currentWeekStart,
                     top = weekUpperMid + halfMidThickness,
                     right = time,
                     bottom = weekUpperMid - halfMidThickness,
                     xloc = xloc.bar_time,
                     extend = extend.right,
                     border_color = midlineColor,
                     border_width = 1,
                     bgcolor = midlineColor
                )
 
            if na(weekCenterMidBox)
 
                weekCenterMidBox := box.new(
                     left = currentWeekStart,
                     top = weekCenterMid + halfMidThickness,
                     right = time,
                     bottom = weekCenterMid - halfMidThickness,
                     xloc = xloc.bar_time,
                     extend = extend.right,
                     border_color = midlineColor,
                     border_width = 1,
                     bgcolor = midlineColor
                )
 
            if na(weekLowerMidBox)
 
                weekLowerMidBox := box.new(
                     left = currentWeekStart,
                     top = weekLowerMid + halfMidThickness,
                     right = time,
                     bottom = weekLowerMid - halfMidThickness,
                     xloc = xloc.bar_time,
                     extend = extend.right,
                     border_color = midlineColor,
                     border_width = 1,
                     bgcolor = midlineColor
                )
 
        else
 
            if not na(weekUpperMidBox)
                box.delete(weekUpperMidBox)
                weekUpperMidBox := na
 
            if not na(weekCenterMidBox)
                box.delete(weekCenterMidBox)
                weekCenterMidBox := na
 
            if not na(weekLowerMidBox)
                box.delete(weekLowerMidBox)
                weekLowerMidBox := na
 
        //-------------------------------------------------------------
        // ACTIVE GREEN / RED
        //-------------------------------------------------------------
        bool weekPriceInUpper =
             close >= weekUpperBottom and
             close <= weekUpperTop
 
        bool weekPriceInLower =
             close >= weekLowerBottom and
             close <= weekLowerTop
 
        box.set_bgcolor(
             weekUpperBox,
             weekPriceInUpper
                 ? color.new(
                      upperActiveColor,
                      activeTransparency
                   )
                 : color.new(
                      upperInactiveColor,
                      boxTransparency
                   )
        )
 
        box.set_bgcolor(
             weekCenterBox,
             color.new(
                  centerColor,
                  boxTransparency
             )
        )
 
        box.set_bgcolor(
             weekLowerBox,
             weekPriceInLower
                 ? color.new(
                      lowerActiveColor,
                      activeTransparency
                   )
                 : color.new(
                      lowerInactiveColor,
                      boxTransparency
                   )
        )
 
        //-------------------------------------------------------------
        // WEEKLY CONTINUATION UP
        //-------------------------------------------------------------
        if alertConfirmed
 
            int weekUpCount =
                 array.size(weekUpExt)
 
            float nextWeekUp =
                 weekUpperTop +
                 weekRange * weekUpCount
 
            if close > nextWeekUp and
               weekUpCount < maxContinuationBricks
 
                float newBottom =
                     nextWeekUp
 
                float newTop =
                     newBottom + weekRange
 
                float newMid =
                     newBottom + weekRange / 2.0
 
                box newBox = box.new(
                     left = currentWeekStart,
                     top = newTop,
                     right = time,
                     bottom = newBottom,
                     xloc = xloc.bar_time,
                     extend = extend.right,
                     border_color = borderColor,
                     border_width = borderWidth,
                     bgcolor = color.new(
                          upperActiveColor,
                          activeTransparency
                     )
                )
 
                array.push(
                     weekUpExt,
                     newBox
                )
 
                if showMidline
 
                    box newMidBox = box.new(
                         left = currentWeekStart,
                         top = newMid + halfMidThickness,
                         right = time,
                         bottom = newMid - halfMidThickness,
                         xloc = xloc.bar_time,
                         extend = extend.right,
                         border_color = midlineColor,
                         border_width = 1,
                         bgcolor = midlineColor
                    )
 
                    array.push(
                         weekUpMidExt,
                         newMidBox
                    )
 
        //-------------------------------------------------------------
        // WEEKLY CONTINUATION DOWN
        //-------------------------------------------------------------
        if alertConfirmed
 
            int weekDownCount =
                 array.size(weekDownExt)
 
            float nextWeekDown =
                 weekLowerBottom -
                 weekRange * weekDownCount
 
            if close < nextWeekDown and
               weekDownCount < maxContinuationBricks
 
                float newTop =
                     nextWeekDown
 
                float newBottom =
                     newTop - weekRange
 
                float newMid =
                     newBottom + weekRange / 2.0
 
                box newBox = box.new(
                     left = currentWeekStart,
                     top = newTop,
                     right = time,
                     bottom = newBottom,
                     xloc = xloc.bar_time,
                     extend = extend.right,
                     border_color = borderColor,
                     border_width = borderWidth,
                     bgcolor = color.new(
                          lowerActiveColor,
                          activeTransparency
                     )
                )
 
                array.push(
                     weekDownExt,
                     newBox
                )
 
                if showMidline
 
                    box newMidBox = box.new(
                         left = currentWeekStart,
                         top = newMid + halfMidThickness,
                         right = time,
                         bottom = newMid - halfMidThickness,
                         xloc = xloc.bar_time,
                         extend = extend.right,
                         border_color = midlineColor,
                         border_width = 1,
                         bgcolor = midlineColor
                    )
 
                    array.push(
                         weekDownMidExt,
                         newMidBox
                    )
 
        //-------------------------------------------------------------
        // WEEKLY EXTENSION ACTIVE COLORS
        //-------------------------------------------------------------
        int totalWeekUp =
             array.size(weekUpExt)
 
        if totalWeekUp > 0
 
            for i = 0 to totalWeekUp - 1
 
                box b =
                     array.get(
                          weekUpExt,
                          i
                     )
 
                float bBottom =
                     weekUpperTop +
                     weekRange * i
 
                float bTop =
                     bBottom +
                     weekRange
 
                bool inside =
                     close >= bBottom and
                     close <= bTop
 
                box.set_bgcolor(
                     b,
                     inside
                         ? color.new(
                              upperActiveColor,
                              activeTransparency
                           )
                         : color.new(
                              upperInactiveColor,
                              boxTransparency
                           )
                )
 
        int totalWeekDown =
             array.size(weekDownExt)
 
        if totalWeekDown > 0
 
            for i = 0 to totalWeekDown - 1
 
                box b =
                     array.get(
                          weekDownExt,
                          i
                     )
 
                float bTop =
                     weekLowerBottom -
                     weekRange * i
 
                float bBottom =
                     bTop -
                     weekRange
 
                bool inside =
                     close >= bBottom and
                     close <= bTop
 
                box.set_bgcolor(
                     b,
                     inside
                         ? color.new(
                              lowerActiveColor,
                              activeTransparency
                           )
                         : color.new(
                              lowerInactiveColor,
                              boxTransparency
                           )
                )
 
//#####################################################################
// TOGGLE 4 — PREVIOUS MONTH SWING
//#####################################################################
 
//=====================================================================
// HIDE MONTHLY WHEN TOGGLE OFF
//=====================================================================
if not showMonthly
 
    if not na(monthUpperBox)
        box.delete(monthUpperBox)
        monthUpperBox := na
 
    if not na(monthCenterBox)
        box.delete(monthCenterBox)
        monthCenterBox := na
 
    if not na(monthLowerBox)
        box.delete(monthLowerBox)
        monthLowerBox := na
 
    if not na(monthUpperMidBox)
        box.delete(monthUpperMidBox)
        monthUpperMidBox := na
 
    if not na(monthCenterMidBox)
        box.delete(monthCenterMidBox)
        monthCenterMidBox := na
 
    if not na(monthLowerMidBox)
        box.delete(monthLowerMidBox)
        monthLowerMidBox := na
 
    f_delete_boxes(monthUpExt)
    f_delete_boxes(monthDownExt)
    f_delete_boxes(monthUpMidExt)
    f_delete_boxes(monthDownMidExt)
 
    storedMonthStart := na
 
//=====================================================================
// RESET AT ACTUAL START OF CURRENT MONTH
//=====================================================================
bool needNewMonthlyStructure =
     showMonthly and
     (
          na(storedMonthStart) or
          storedMonthStart != currentMonthStart
     )
 
if needNewMonthlyStructure
 
    if not na(monthUpperBox)
        box.delete(monthUpperBox)
 
    if not na(monthCenterBox)
        box.delete(monthCenterBox)
 
    if not na(monthLowerBox)
        box.delete(monthLowerBox)
 
    if not na(monthUpperMidBox)
        box.delete(monthUpperMidBox)
 
    if not na(monthCenterMidBox)
        box.delete(monthCenterMidBox)
 
    if not na(monthLowerMidBox)
        box.delete(monthLowerMidBox)
 
    f_delete_boxes(monthUpExt)
    f_delete_boxes(monthDownExt)
    f_delete_boxes(monthUpMidExt)
    f_delete_boxes(monthDownMidExt)
 
    monthUpperBox := na
    monthCenterBox := na
    monthLowerBox := na
 
    monthUpperMidBox := na
    monthCenterMidBox := na
    monthLowerMidBox := na
 
    storedMonthStart :=
         currentMonthStart
 
//=====================================================================
// DRAW MONTHLY SWING
// CENTER = PREVIOUS MONTH'S ACTUAL HIGH / LOW
// LEFT EDGE = CURRENT MONTH START
//=====================================================================
if showMonthly and
   not na(previousMonthHigh) and
   not na(previousMonthLow)
 
    float monthRange =
         previousMonthHigh -
         previousMonthLow
 
    if monthRange > 0
 
        //-------------------------------------------------------------
        // PREVIOUS MONTH CENTER BRICK
        //-------------------------------------------------------------
        float monthCenterTop =
             previousMonthHigh
 
        float monthCenterBottom =
             previousMonthLow
 
        float monthCenterMid =
             previousMonthLow +
             monthRange / 2.0
 
        //-------------------------------------------------------------
        // IDENTICAL CLONE ABOVE
        //-------------------------------------------------------------
        float monthUpperBottom =
             previousMonthHigh
 
        float monthUpperTop =
             previousMonthHigh +
             monthRange
 
        float monthUpperMid =
             previousMonthHigh +
             monthRange / 2.0
 
        //-------------------------------------------------------------
        // IDENTICAL CLONE BELOW
        //-------------------------------------------------------------
        float monthLowerTop =
             previousMonthLow
 
        float monthLowerBottom =
             previousMonthLow -
             monthRange
 
        float monthLowerMid =
             previousMonthLow -
             monthRange / 2.0
 
        //-------------------------------------------------------------
        // CREATE EXACT 3-BRICK MONTHLY STRUCTURE
        //-------------------------------------------------------------
        if na(monthCenterBox)
 
            monthUpperBox := box.new(
                 left = currentMonthStart,
                 top = monthUpperTop,
                 right = time,
                 bottom = monthUpperBottom,
                 xloc = xloc.bar_time,
                 extend = extend.right,
                 border_color = borderColor,
                 border_width = borderWidth,
                 bgcolor = color.new(
                      upperInactiveColor,
                      boxTransparency
                 )
            )
 
            monthCenterBox := box.new(
                 left = currentMonthStart,
                 top = monthCenterTop,
                 right = time,
                 bottom = monthCenterBottom,
                 xloc = xloc.bar_time,
                 extend = extend.right,
                 border_color = borderColor,
                 border_width = borderWidth,
                 bgcolor = color.new(
                      centerColor,
                      boxTransparency
                 )
            )
 
            monthLowerBox := box.new(
                 left = currentMonthStart,
                 top = monthLowerTop,
                 right = time,
                 bottom = monthLowerBottom,
                 xloc = xloc.bar_time,
                 extend = extend.right,
                 border_color = borderColor,
                 border_width = borderWidth,
                 bgcolor = color.new(
                      lowerInactiveColor,
                      boxTransparency
                 )
            )
 
        //-------------------------------------------------------------
        // MONTHLY MIDLINES
        //-------------------------------------------------------------
        if showMidline
 
            if na(monthUpperMidBox)
 
                monthUpperMidBox := box.new(
                     left = currentMonthStart,
                     top = monthUpperMid + halfMidThickness,
                     right = time,
                     bottom = monthUpperMid - halfMidThickness,
                     xloc = xloc.bar_time,
                     extend = extend.right,
                     border_color = midlineColor,
                     border_width = 1,
                     bgcolor = midlineColor
                )
 
            if na(monthCenterMidBox)
 
                monthCenterMidBox := box.new(
                     left = currentMonthStart,
                     top = monthCenterMid + halfMidThickness,
                     right = time,
                     bottom = monthCenterMid - halfMidThickness,
                     xloc = xloc.bar_time,
                     extend = extend.right,
                     border_color = midlineColor,
                     border_width = 1,
                     bgcolor = midlineColor
                )
 
            if na(monthLowerMidBox)
 
                monthLowerMidBox := box.new(
                     left = currentMonthStart,
                     top = monthLowerMid + halfMidThickness,
                     right = time,
                     bottom = monthLowerMid - halfMidThickness,
                     xloc = xloc.bar_time,
                     extend = extend.right,
                     border_color = midlineColor,
                     border_width = 1,
                     bgcolor = midlineColor
                )
 
        else
 
            if not na(monthUpperMidBox)
                box.delete(monthUpperMidBox)
                monthUpperMidBox := na
 
            if not na(monthCenterMidBox)
                box.delete(monthCenterMidBox)
                monthCenterMidBox := na
 
            if not na(monthLowerMidBox)
                box.delete(monthLowerMidBox)
                monthLowerMidBox := na
 
        //-------------------------------------------------------------
        // ACTIVE GREEN / RED
        //-------------------------------------------------------------
        bool monthPriceInUpper =
             close >= monthUpperBottom and
             close <= monthUpperTop
 
        bool monthPriceInLower =
             close >= monthLowerBottom and
             close <= monthLowerTop
 
        box.set_bgcolor(
             monthUpperBox,
             monthPriceInUpper
                 ? color.new(
                      upperActiveColor,
                      activeTransparency
                   )
                 : color.new(
                      upperInactiveColor,
                      boxTransparency
                   )
        )
 
        box.set_bgcolor(
             monthCenterBox,
             color.new(
                  centerColor,
                  boxTransparency
             )
        )
 
        box.set_bgcolor(
             monthLowerBox,
             monthPriceInLower
                 ? color.new(
                      lowerActiveColor,
                      activeTransparency
                   )
                 : color.new(
                      lowerInactiveColor,
                      boxTransparency
                   )
        )
 
        //-------------------------------------------------------------
        // MONTHLY CONTINUATION UP
        //-------------------------------------------------------------
        if alertConfirmed
 
            int monthUpCount =
                 array.size(monthUpExt)
 
            float nextMonthUp =
                 monthUpperTop +
                 monthRange * monthUpCount
 
            if close > nextMonthUp and
               monthUpCount < maxContinuationBricks
 
                float newBottom =
                     nextMonthUp
 
                float newTop =
                     newBottom + monthRange
 
                float newMid =
                     newBottom + monthRange / 2.0
 
                box newBox = box.new(
                     left = currentMonthStart,
                     top = newTop,
                     right = time,
                     bottom = newBottom,
                     xloc = xloc.bar_time,
                     extend = extend.right,
                     border_color = borderColor,
                     border_width = borderWidth,
                     bgcolor = color.new(
                          upperActiveColor,
                          activeTransparency
                     )
                )
 
                array.push(
                     monthUpExt,
                     newBox
                )
 
                if showMidline
 
                    box newMidBox = box.new(
                         left = currentMonthStart,
                         top = newMid + halfMidThickness,
                         right = time,
                         bottom = newMid - halfMidThickness,
                         xloc = xloc.bar_time,
                         extend = extend.right,
                         border_color = midlineColor,
                         border_width = 1,
                         bgcolor = midlineColor
                    )
 
                    array.push(
                         monthUpMidExt,
                         newMidBox
                    )
 
        //-------------------------------------------------------------
        // MONTHLY CONTINUATION DOWN
        //-------------------------------------------------------------
        if alertConfirmed
 
            int monthDownCount =
                 array.size(monthDownExt)
 
            float nextMonthDown =
                 monthLowerBottom -
                 monthRange * monthDownCount
 
            if close < nextMonthDown and
               monthDownCount < maxContinuationBricks
 
                float newTop =
                     nextMonthDown
 
                float newBottom =
                     newTop - monthRange
 
                float newMid =
                     newBottom + monthRange / 2.0
 
                box newBox = box.new(
                     left = currentMonthStart,
                     top = newTop,
                     right = time,
                     bottom = newBottom,
                     xloc = xloc.bar_time,
                     extend = extend.right,
                     border_color = borderColor,
                     border_width = borderWidth,
                     bgcolor = color.new(
                          lowerActiveColor,
                          activeTransparency
                     )
                )
 
                array.push(
                     monthDownExt,
                     newBox
                )
 
                if showMidline
 
                    box newMidBox = box.new(
                         left = currentMonthStart,
                         top = newMid + halfMidThickness,
                         right = time,
                         bottom = newMid - halfMidThickness,
                         xloc = xloc.bar_time,
                         extend = extend.right,
                         border_color = midlineColor,
                         border_width = 1,
                         bgcolor = midlineColor
                    )
 
                    array.push(
                         monthDownMidExt,
                         newMidBox
                    )
 
        //-------------------------------------------------------------
        // MONTHLY EXTENSION ACTIVE COLORS
        //-------------------------------------------------------------
        int totalMonthUp =
             array.size(monthUpExt)
 
        if totalMonthUp > 0
 
            for i = 0 to totalMonthUp - 1
 
                box b =
                     array.get(
                          monthUpExt,
                          i
                     )
 
                float bBottom =
                     monthUpperTop +
                     monthRange * i
 
                float bTop =
                     bBottom +
                     monthRange
 
                bool inside =
                     close >= bBottom and
                     close <= bTop
 
                box.set_bgcolor(
                     b,
                     inside
                         ? color.new(
                              upperActiveColor,
                              activeTransparency
                           )
                         : color.new(
                              upperInactiveColor,
                              boxTransparency
                           )
                )
 
        int totalMonthDown =
             array.size(monthDownExt)
 
        if totalMonthDown > 0
 
            for i = 0 to totalMonthDown - 1
 
                box b =
                     array.get(
                          monthDownExt,
                          i
                     )
 
                float bTop =
                     monthLowerBottom -
                     monthRange * i
 
                float bBottom =
                     bTop -
                     monthRange
 
                bool inside =
                     close >= bBottom and
                     close <= bTop
 
                box.set_bgcolor(
                     b,
                     inside
                         ? color.new(
                              lowerActiveColor,
                              activeTransparency
                           )
                         : color.new(
                              lowerInactiveColor,
                              boxTransparency
                           )
                )
 
//#####################################################################
// ALERT LEVELS — 9 BRICK ALERTS
//#####################################################################
// Bull Brick   = upper brick
// Center Brick = center brick
// Bear Brick   = lower brick
//
// NOTE:
// Center Brick Top    = Bull Brick Bottom
// Center Brick Bottom = Bear Brick Top
// They remain separate alert choices by design.
 
//=====================================================================
// TOGGLE 1 — OVERNIGHT LEVELS
//=====================================================================
float onAlertRange =
     not na(onHigh) and not na(onLow)
         ? onHigh - onLow
         : na
 
float onBullTop =
     not na(onAlertRange)
         ? onHigh + onAlertRange
         : na
 
float onBullBottom =
     not na(onAlertRange)
         ? onHigh
         : na
 
float onBullMid =
     not na(onAlertRange)
         ? onHigh + onAlertRange / 2.0
         : na
 
float onCenterTop =
     not na(onAlertRange)
         ? onHigh
         : na
 
float onCenterBottom =
     not na(onAlertRange)
         ? onLow
         : na
 
float onCenterMid =
     not na(onAlertRange)
         ? onLow + onAlertRange / 2.0
         : na
 
float onBearTop =
     not na(onAlertRange)
         ? onLow
         : na
 
float onBearBottom =
     not na(onAlertRange)
         ? onLow - onAlertRange
         : na
 
float onBearMid =
     not na(onAlertRange)
         ? onLow - onAlertRange / 2.0
         : na
 
//=====================================================================
// TOGGLE 2 — RTH LEVELS
//=====================================================================
float rthAlertRange =
     not na(rthHigh) and not na(rthLow)
         ? rthHigh - rthLow
         : na
 
float rthBullTop =
     not na(rthAlertRange)
         ? rthHigh + rthAlertRange
         : na
 
float rthBullBottom =
     not na(rthAlertRange)
         ? rthHigh
         : na
 
float rthBullMid =
     not na(rthAlertRange)
         ? rthHigh + rthAlertRange / 2.0
         : na
 
float rthCenterTop =
     not na(rthAlertRange)
         ? rthHigh
         : na
 
float rthCenterBottom =
     not na(rthAlertRange)
         ? rthLow
         : na
 
float rthCenterMid =
     not na(rthAlertRange)
         ? rthLow + rthAlertRange / 2.0
         : na
 
float rthBearTop =
     not na(rthAlertRange)
         ? rthLow
         : na
 
float rthBearBottom =
     not na(rthAlertRange)
         ? rthLow - rthAlertRange
         : na
 
float rthBearMid =
     not na(rthAlertRange)
         ? rthLow - rthAlertRange / 2.0
         : na
 
//=====================================================================
// TOGGLE 3 — WEEKLY LEVELS
//=====================================================================
float weekAlertRange =
     previousWeekHigh - previousWeekLow
 
float weekBullTop =
     previousWeekHigh + weekAlertRange
 
float weekBullBottom =
     previousWeekHigh
 
float weekBullMid =
     previousWeekHigh + weekAlertRange / 2.0
 
float weekCenterTop =
     previousWeekHigh
 
float weekCenterBottom =
     previousWeekLow
 
float weekCenterMid =
     previousWeekLow + weekAlertRange / 2.0
 
float weekBearTop =
     previousWeekLow
 
float weekBearBottom =
     previousWeekLow - weekAlertRange
 
float weekBearMid =
     previousWeekLow - weekAlertRange / 2.0
 
//=====================================================================
// TOGGLE 4 — MONTHLY LEVELS
//=====================================================================
float monthAlertRange =
     previousMonthHigh - previousMonthLow
 
float monthBullTop =
     previousMonthHigh + monthAlertRange
 
float monthBullBottom =
     previousMonthHigh
 
float monthBullMid =
     previousMonthHigh + monthAlertRange / 2.0
 
float monthCenterTop =
     previousMonthHigh
 
float monthCenterBottom =
     previousMonthLow
 
float monthCenterMid =
     previousMonthLow + monthAlertRange / 2.0
 
float monthBearTop =
     previousMonthLow
 
float monthBearBottom =
     previousMonthLow - monthAlertRange
 
float monthBearMid =
     previousMonthLow - monthAlertRange / 2.0
 
//#####################################################################
// HELPER — LEVEL CROSS
//#####################################################################
// Alerts trigger when the candle CLOSE crosses a level when
// "Require Candle Close" is enabled. If disabled, they can trigger intrabar.
f_level_cross(float level) =>
    not na(level) and ta.cross(close, level)
 
//#####################################################################
// 9 ALERT CONDITIONS
// Each alert works with whichever brick toggle(s) are enabled.
//#####################################################################
bool bullBrickMidlineAlert =
     enableAlerts and alertConfirmed and
     (
          (showON and onRangeLocked and f_level_cross(onBullMid)) or
          (showRTH and rthRangeLocked and f_level_cross(rthBullMid)) or
          (showWeekly and f_level_cross(weekBullMid)) or
          (showMonthly and f_level_cross(monthBullMid))
     )
 
bool centerBrickMidlineAlert =
     enableAlerts and alertConfirmed and
     (
          (showON and onRangeLocked and f_level_cross(onCenterMid)) or
          (showRTH and rthRangeLocked and f_level_cross(rthCenterMid)) or
          (showWeekly and f_level_cross(weekCenterMid)) or
          (showMonthly and f_level_cross(monthCenterMid))
     )
 
bool bearBrickMidlineAlert =
     enableAlerts and alertConfirmed and
     (
          (showON and onRangeLocked and f_level_cross(onBearMid)) or
          (showRTH and rthRangeLocked and f_level_cross(rthBearMid)) or
          (showWeekly and f_level_cross(weekBearMid)) or
          (showMonthly and f_level_cross(monthBearMid))
     )
 
bool centerBrickTopAlert =
     enableAlerts and alertConfirmed and
     (
          (showON and onRangeLocked and f_level_cross(onCenterTop)) or
          (showRTH and rthRangeLocked and f_level_cross(rthCenterTop)) or
          (showWeekly and f_level_cross(weekCenterTop)) or
          (showMonthly and f_level_cross(monthCenterTop))
     )
 
bool centerBrickBottomAlert =
     enableAlerts and alertConfirmed and
     (
          (showON and onRangeLocked and f_level_cross(onCenterBottom)) or
          (showRTH and rthRangeLocked and f_level_cross(rthCenterBottom)) or
          (showWeekly and f_level_cross(weekCenterBottom)) or
          (showMonthly and f_level_cross(monthCenterBottom))
     )
 
bool bullBrickTopAlert =
     enableAlerts and alertConfirmed and
     (
          (showON and onRangeLocked and f_level_cross(onBullTop)) or
          (showRTH and rthRangeLocked and f_level_cross(rthBullTop)) or
          (showWeekly and f_level_cross(weekBullTop)) or
          (showMonthly and f_level_cross(monthBullTop))
     )
 
bool bullBrickBottomAlert =
     enableAlerts and alertConfirmed and
     (
          (showON and onRangeLocked and f_level_cross(onBullBottom)) or
          (showRTH and rthRangeLocked and f_level_cross(rthBullBottom)) or
          (showWeekly and f_level_cross(weekBullBottom)) or
          (showMonthly and f_level_cross(monthBullBottom))
     )
 
bool bearBrickTopAlert =
     enableAlerts and alertConfirmed and
     (
          (showON and onRangeLocked and f_level_cross(onBearTop)) or
          (showRTH and rthRangeLocked and f_level_cross(rthBearTop)) or
          (showWeekly and f_level_cross(weekBearTop)) or
          (showMonthly and f_level_cross(monthBearTop))
     )
 
bool bearBrickBottomAlert =
     enableAlerts and alertConfirmed and
     (
          (showON and onRangeLocked and f_level_cross(onBearBottom)) or
          (showRTH and rthRangeLocked and f_level_cross(rthBearBottom)) or
          (showWeekly and f_level_cross(weekBearBottom)) or
          (showMonthly and f_level_cross(monthBearBottom))
     )
 
//#####################################################################
// ALERTS — EXACT NAMES REQUESTED
//#####################################################################
alertcondition(
     bullBrickMidlineAlert,
     "Bull Brick Midline",
     "{{ticker}} | BULL BRICK MIDLINE | Price {{close}}"
)
 
alertcondition(
     centerBrickMidlineAlert,
     "Center Brick Midline",
     "{{ticker}} | CENTER BRICK MIDLINE | Price {{close}}"
)
 
alertcondition(
     bearBrickMidlineAlert,
     "Bear Brick Midline",
     "{{ticker}} | BEAR BRICK MIDLINE | Price {{close}}"
)
 
alertcondition(
     centerBrickTopAlert,
     "Center Brick Top",
     "{{ticker}} | CENTER BRICK TOP | Price {{close}}"
)
 
alertcondition(
     centerBrickBottomAlert,
     "Center Brick Bottom",
     "{{ticker}} | CENTER BRICK BOTTOM | Price {{close}}"
)
 
alertcondition(
     bullBrickTopAlert,
     "Bull Brick Top",
     "{{ticker}} | BULL BRICK TOP | Price {{close}}"
)
 
alertcondition(
     bullBrickBottomAlert,
     "Bull Brick Bottom",
     "{{ticker}} | BULL BRICK BOTTOM | Price {{close}}"
)
 
alertcondition(
     bearBrickTopAlert,
     "Bear Brick Top",
     "{{ticker}} | BEAR BRICK TOP | Price {{close}}"
)
 
alertcondition(
     bearBrickBottomAlert,
     "Bear Brick Bottom",
     "{{ticker}} | BEAR BRICK BOTTOM | Price {{close}}"
)
 
 
//#####################################################################
// SECONDARY DASHED BRICK LINES
// Adjustable percentage inside every base + continuation brick.
//#####################################################################
 
f_secondary_line(line ln, bool enabled, int leftTime, float y) =>
    line result = ln
    if enabled and not na(leftTime) and not na(y)
        if na(result)
            result := line.new(
                 x1 = leftTime,
                 y1 = y,
                 x2 = time,
                 y2 = y,
                 xloc = xloc.bar_time,
                 extend = extend.right,
                 color = secondaryLineColor,
                 style = line.style_dashed,
                 width = secondaryLineWidth
            )
        else
            line.set_xy1(result, leftTime, y)
            line.set_xy2(result, time, y)
            line.set_color(result, secondaryLineColor)
            line.set_style(result, line.style_dashed)
            line.set_width(result, secondaryLineWidth)
    else
        if not na(result)
            line.delete(result)
            result := na
    result
 
f_sync_secondary_ext(array<line> arr, bool enabled, int leftTime, int desiredCount, float firstBottom, float brickRange, bool upward) =>
    if not enabled or na(leftTime) or na(firstBottom) or na(brickRange) or brickRange <= 0
        int existing = array.size(arr)
        if existing > 0
            for j = 0 to existing - 1
                line oldLine = array.get(arr, j)
                if not na(oldLine)
                    line.delete(oldLine)
        array.clear(arr)
    else
        while array.size(arr) > desiredCount
            line oldLine = array.pop(arr)
            if not na(oldLine)
                line.delete(oldLine)
 
        while array.size(arr) < desiredCount
            int i = array.size(arr)
            float brickBottom = upward
                 ? firstBottom + brickRange * i
                 : firstBottom - brickRange * i
            float y = brickBottom + brickRange * secondaryPct
            line newLine = line.new(
                 x1 = leftTime,
                 y1 = y,
                 x2 = time,
                 y2 = y,
                 xloc = xloc.bar_time,
                 extend = extend.right,
                 color = secondaryLineColor,
                 style = line.style_dashed,
                 width = secondaryLineWidth
            )
            array.push(arr, newLine)
 
        int total = array.size(arr)
        if total > 0
            for i = 0 to total - 1
                line ln = array.get(arr, i)
                float brickBottom = upward
                     ? firstBottom + brickRange * i
                     : firstBottom - brickRange * i
                float y = brickBottom + brickRange * secondaryPct
                line.set_xy1(ln, leftTime, y)
                line.set_xy2(ln, time, y)
                line.set_color(ln, secondaryLineColor)
                line.set_style(ln, line.style_dashed)
                line.set_width(ln, secondaryLineWidth)
 
//=====================================================================
// OVERNIGHT SECONDARY LINES
//=====================================================================
float onSecondaryRange = not na(onHigh) and not na(onLow) ? onHigh - onLow : na
bool onSecondaryEnabled = showSecondaryLine and showON and not na(onSecondaryRange) and onSecondaryRange > 0
 
onBullSecondary := f_secondary_line(onBullSecondary, onSecondaryEnabled, onLeft, onHigh + onSecondaryRange * secondaryPct)
onCenterSecondary := f_secondary_line(onCenterSecondary, onSecondaryEnabled, onLeft, onLow + onSecondaryRange * secondaryPct)
onBearSecondary := f_secondary_line(onBearSecondary, onSecondaryEnabled, onLeft, onLow - onSecondaryRange + onSecondaryRange * secondaryPct)
 
f_sync_secondary_ext(onUpSecondaryExt, onSecondaryEnabled, onLeft, array.size(onUpExt), onHigh + onSecondaryRange, onSecondaryRange, true)
f_sync_secondary_ext(onDownSecondaryExt, onSecondaryEnabled, onLeft, array.size(onDownExt), onLow - onSecondaryRange * 2.0, onSecondaryRange, false)
 
//=====================================================================
// RTH SECONDARY LINES
//=====================================================================
float rthSecondaryRange = not na(rthHigh) and not na(rthLow) ? rthHigh - rthLow : na
bool rthSecondaryEnabled = showSecondaryLine and showRTH and not na(rthSecondaryRange) and rthSecondaryRange > 0
 
rthBullSecondary := f_secondary_line(rthBullSecondary, rthSecondaryEnabled, rthLeft, rthHigh + rthSecondaryRange * secondaryPct)
rthCenterSecondary := f_secondary_line(rthCenterSecondary, rthSecondaryEnabled, rthLeft, rthLow + rthSecondaryRange * secondaryPct)
rthBearSecondary := f_secondary_line(rthBearSecondary, rthSecondaryEnabled, rthLeft, rthLow - rthSecondaryRange + rthSecondaryRange * secondaryPct)
 
f_sync_secondary_ext(rthUpSecondaryExt, rthSecondaryEnabled, rthLeft, array.size(rthUpExt), rthHigh + rthSecondaryRange, rthSecondaryRange, true)
f_sync_secondary_ext(rthDownSecondaryExt, rthSecondaryEnabled, rthLeft, array.size(rthDownExt), rthLow - rthSecondaryRange * 2.0, rthSecondaryRange, false)
 
//=====================================================================
// WEEKLY SECONDARY LINES
//=====================================================================
float weekSecondaryRange = previousWeekHigh - previousWeekLow
bool weekSecondaryEnabled = showSecondaryLine and showWeekly and not na(weekSecondaryRange) and weekSecondaryRange > 0
 
weekBullSecondary := f_secondary_line(weekBullSecondary, weekSecondaryEnabled, currentWeekStart, previousWeekHigh + weekSecondaryRange * secondaryPct)
weekCenterSecondary := f_secondary_line(weekCenterSecondary, weekSecondaryEnabled, currentWeekStart, previousWeekLow + weekSecondaryRange * secondaryPct)
weekBearSecondary := f_secondary_line(weekBearSecondary, weekSecondaryEnabled, currentWeekStart, previousWeekLow - weekSecondaryRange + weekSecondaryRange * secondaryPct)
 
f_sync_secondary_ext(weekUpSecondaryExt, weekSecondaryEnabled, currentWeekStart, array.size(weekUpExt), previousWeekHigh + weekSecondaryRange, weekSecondaryRange, true)
f_sync_secondary_ext(weekDownSecondaryExt, weekSecondaryEnabled, currentWeekStart, array.size(weekDownExt), previousWeekLow - weekSecondaryRange * 2.0, weekSecondaryRange, false)
 
//=====================================================================
// MONTHLY SECONDARY LINES
//=====================================================================
float monthSecondaryRange = previousMonthHigh - previousMonthLow
bool monthSecondaryEnabled = showSecondaryLine and showMonthly and not na(monthSecondaryRange) and monthSecondaryRange > 0
 
monthBullSecondary := f_secondary_line(monthBullSecondary, monthSecondaryEnabled, currentMonthStart, previousMonthHigh + monthSecondaryRange * secondaryPct)
monthCenterSecondary := f_secondary_line(monthCenterSecondary, monthSecondaryEnabled, currentMonthStart, previousMonthLow + monthSecondaryRange * secondaryPct)
monthBearSecondary := f_secondary_line(monthBearSecondary, monthSecondaryEnabled, currentMonthStart, previousMonthLow - monthSecondaryRange + monthSecondaryRange * secondaryPct)
 
f_sync_secondary_ext(monthUpSecondaryExt, monthSecondaryEnabled, currentMonthStart, array.size(monthUpExt), previousMonthHigh + monthSecondaryRange, monthSecondaryRange, true)
f_sync_secondary_ext(monthDownSecondaryExt, monthSecondaryEnabled, currentMonthStart, array.size(monthDownExt), previousMonthLow - monthSecondaryRange * 2.0, monthSecondaryRange, false)
 
 
//#####################################################################
// MIRRORED UPPER SECONDARY DASHED BRICK LINES
// Independent toggle. If lower line is 25%, upper line is 75%.
// Uses the same color and width controls as the secondary dashed line.
//#####################################################################
 
float upperSecondaryPct = 1.0 - secondaryPct
 
f_sync_upper_secondary_ext(array<line> arr, bool enabled, int leftTime, int desiredCount, float firstBottom, float brickRange, bool upward) =>
    if not enabled or na(leftTime) or na(firstBottom) or na(brickRange) or brickRange <= 0
        int existing = array.size(arr)
        if existing > 0
            for j = 0 to existing - 1
                line oldLine = array.get(arr, j)
                if not na(oldLine)
                    line.delete(oldLine)
        array.clear(arr)
    else
        while array.size(arr) > desiredCount
            line oldLine = array.pop(arr)
            if not na(oldLine)
                line.delete(oldLine)
 
        while array.size(arr) < desiredCount
            int i = array.size(arr)
            float brickBottom = upward
                 ? firstBottom + brickRange * i
                 : firstBottom - brickRange * i
            float y = brickBottom + brickRange * upperSecondaryPct
            line newLine = line.new(
                 x1 = leftTime,
                 y1 = y,
                 x2 = time,
                 y2 = y,
                 xloc = xloc.bar_time,
                 extend = extend.right,
                 color = secondaryLineColor,
                 style = line.style_dashed,
                 width = secondaryLineWidth
            )
            array.push(arr, newLine)
 
        int total = array.size(arr)
        if total > 0
            for i = 0 to total - 1
                line ln = array.get(arr, i)
                float brickBottom = upward
                     ? firstBottom + brickRange * i
                     : firstBottom - brickRange * i
                float y = brickBottom + brickRange * upperSecondaryPct
                line.set_xy1(ln, leftTime, y)
                line.set_xy2(ln, time, y)
                line.set_color(ln, secondaryLineColor)
                line.set_style(ln, line.style_dashed)
                line.set_width(ln, secondaryLineWidth)
 
// OVERNIGHT — UPPER MIRRORED DASHED LINES
bool onUpperSecondaryEnabled = showUpperSecondaryLine and showON and not na(onSecondaryRange) and onSecondaryRange > 0
onBullUpperSecondary := f_secondary_line(onBullUpperSecondary, onUpperSecondaryEnabled, onLeft, onHigh + onSecondaryRange * upperSecondaryPct)
onCenterUpperSecondary := f_secondary_line(onCenterUpperSecondary, onUpperSecondaryEnabled, onLeft, onLow + onSecondaryRange * upperSecondaryPct)
onBearUpperSecondary := f_secondary_line(onBearUpperSecondary, onUpperSecondaryEnabled, onLeft, onLow - onSecondaryRange + onSecondaryRange * upperSecondaryPct)
f_sync_upper_secondary_ext(onUpUpperSecondaryExt, onUpperSecondaryEnabled, onLeft, array.size(onUpExt), onHigh + onSecondaryRange, onSecondaryRange, true)
f_sync_upper_secondary_ext(onDownUpperSecondaryExt, onUpperSecondaryEnabled, onLeft, array.size(onDownExt), onLow - onSecondaryRange * 2.0, onSecondaryRange, false)
 
// RTH — UPPER MIRRORED DASHED LINES
bool rthUpperSecondaryEnabled = showUpperSecondaryLine and showRTH and not na(rthSecondaryRange) and rthSecondaryRange > 0
rthBullUpperSecondary := f_secondary_line(rthBullUpperSecondary, rthUpperSecondaryEnabled, rthLeft, rthHigh + rthSecondaryRange * upperSecondaryPct)
rthCenterUpperSecondary := f_secondary_line(rthCenterUpperSecondary, rthUpperSecondaryEnabled, rthLeft, rthLow + rthSecondaryRange * upperSecondaryPct)
rthBearUpperSecondary := f_secondary_line(rthBearUpperSecondary, rthUpperSecondaryEnabled, rthLeft, rthLow - rthSecondaryRange + rthSecondaryRange * upperSecondaryPct)
f_sync_upper_secondary_ext(rthUpUpperSecondaryExt, rthUpperSecondaryEnabled, rthLeft, array.size(rthUpExt), rthHigh + rthSecondaryRange, rthSecondaryRange, true)
f_sync_upper_secondary_ext(rthDownUpperSecondaryExt, rthUpperSecondaryEnabled, rthLeft, array.size(rthDownExt), rthLow - rthSecondaryRange * 2.0, rthSecondaryRange, false)
 
// WEEKLY — UPPER MIRRORED DASHED LINES
bool weekUpperSecondaryEnabled = showUpperSecondaryLine and showWeekly and not na(weekSecondaryRange) and weekSecondaryRange > 0
weekBullUpperSecondary := f_secondary_line(weekBullUpperSecondary, weekUpperSecondaryEnabled, currentWeekStart, previousWeekHigh + weekSecondaryRange * upperSecondaryPct)
weekCenterUpperSecondary := f_secondary_line(weekCenterUpperSecondary, weekUpperSecondaryEnabled, currentWeekStart, previousWeekLow + weekSecondaryRange * upperSecondaryPct)
weekBearUpperSecondary := f_secondary_line(weekBearUpperSecondary, weekUpperSecondaryEnabled, currentWeekStart, previousWeekLow - weekSecondaryRange + weekSecondaryRange * upperSecondaryPct)
f_sync_upper_secondary_ext(weekUpUpperSecondaryExt, weekUpperSecondaryEnabled, currentWeekStart, array.size(weekUpExt), previousWeekHigh + weekSecondaryRange, weekSecondaryRange, true)
f_sync_upper_secondary_ext(weekDownUpperSecondaryExt, weekUpperSecondaryEnabled, currentWeekStart, array.size(weekDownExt), previousWeekLow - weekSecondaryRange * 2.0, weekSecondaryRange, false)
 
// MONTHLY — UPPER MIRRORED DASHED LINES
bool monthUpperSecondaryEnabled = showUpperSecondaryLine and showMonthly and not na(monthSecondaryRange) and monthSecondaryRange > 0
monthBullUpperSecondary := f_secondary_line(monthBullUpperSecondary, monthUpperSecondaryEnabled, currentMonthStart, previousMonthHigh + monthSecondaryRange * upperSecondaryPct)
monthCenterUpperSecondary := f_secondary_line(monthCenterUpperSecondary, monthUpperSecondaryEnabled, currentMonthStart, previousMonthLow + monthSecondaryRange * upperSecondaryPct)
monthBearUpperSecondary := f_secondary_line(monthBearUpperSecondary, monthUpperSecondaryEnabled, currentMonthStart, previousMonthLow - monthSecondaryRange + monthSecondaryRange * upperSecondaryPct)
f_sync_upper_secondary_ext(monthUpUpperSecondaryExt, monthUpperSecondaryEnabled, currentMonthStart, array.size(monthUpExt), previousMonthHigh + monthSecondaryRange, monthSecondaryRange, true)
f_sync_upper_secondary_ext(monthDownUpperSecondaryExt, monthUpperSecondaryEnabled, currentMonthStart, array.size(monthDownExt), previousMonthLow - monthSecondaryRange * 2.0, monthSecondaryRange, false)

← 返回列表