TOLAG Auto Trendline Precision | TGL 8 V5.3

TOLAG · study · 942 行 · 点赞 173 · TradingView 原页

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

Pine Script

//@version=6
indicator("TOLAG Auto Trendline Precision | TGL 8 V5.3", shorttitle="TOLAG TGL8", overlay=true, max_lines_count=400, max_labels_count=300, max_boxes_count=200, max_bars_back=1200)
 
// © 2026 TOLAG Indicators. All rights reserved.
// V5.3: MTF tuple fix, quality-call consistency, runtime-safe structure.
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 01 | PRECISION TRENDLINES
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
string G1 = "01 | Precision Trendlines"
int pivotLen = input.int(9, "Primary pivot strength", minval=3, maxval=35, group=G1)
int pivotMemory = input.int(8, "Stored pivots", minval=3, maxval=12, group=G1)
int minGap = input.int(12, "Minimum anchor separation", minval=3, group=G1)
int maxGap = input.int(220, "Maximum anchor separation", minval=25, maxval=500, group=G1)
float minQuality = input.float(57, "Minimum trendline quality", minval=0, maxval=100, group=G1)
float maxSlope = input.float(0.20, "Maximum slope / ATR per bar", minval=0.01, step=0.01, group=G1)
float touchATR = input.float(0.25, "Touch tolerance / ATR", minval=0.02, step=0.01, group=G1)
float breakATR = input.float(0.16, "Break confirmation / ATR", minval=0.01, step=0.01, group=G1)
int atrLen = input.int(14, "ATR period", minval=2, group=G1)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 02 | TRENDLINE GEOMETRY
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
string G2 = "02 | Trendline Geometry"
bool showPrimary = input.bool(true, "Show primary precision lines", group=G2)
bool showMedium = input.bool(true, "Show medium-term lines", group=G2)
bool showLong = input.bool(true, "Show long-term lines", group=G2)
int mediumLen = input.int(20, "Medium pivot strength", minval=5, maxval=80, group=G2)
int longLen = input.int(45, "Long pivot strength", minval=10, maxval=120, group=G2)
color upColor = input.color(#40E2BA, "UP support", group=G2)
color downColor = input.color(#FFAD85, "DOWN resistance", group=G2)
color mediumColor = input.color(#80A9EE, "Medium-term color", group=G2)
color longColor = input.color(#D4B0FF, "Long-term color", group=G2)
int primaryWidth = input.int(3, "Primary line thickness", minval=1, maxval=5, group=G2)
string rightMode = input.string("Limited", "Right extension", options=["Limited", "None", "Infinite"], group=G2)
int rightBars = input.int(35, "Right extension bars", minval=0, maxval=500, group=G2)
string leftMode = input.string("Anchors", "Left extension", options=["Anchors", "Custom", "Infinite"], group=G2)
int leftBars = input.int(50, "Custom left bars", minval=0, maxval=500, group=G2)
bool showBroken = input.bool(true, "Show historical broken lines", group=G2)
int brokenHistory = input.int(5, "Broken lines per direction", minval=0, maxval=20, group=G2)
string brokenStyle = input.string("Dashed", "Broken line style", options=["Dashed", "Dotted"], group=G2)
int brokenWidth = input.int(1, "Broken line thickness", minval=1, maxval=3, group=G2)
int brokenFade = input.int(75, "Broken line transparency", minval=0, maxval=100, group=G2)
color brokenColor = input.color(#A8B2C1, "Broken line color", group=G2)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 03 | FLUID STRUCTURE
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
string G3 = "03 | Fluid Structure"
bool showFluid = input.bool(true, "Show Fluid Structure drawings", group=G3)
bool showSupply = input.bool(true, "Supply zones", group=G3)
bool showDemand = input.bool(true, "Demand zones", group=G3)
bool showPOI = input.bool(true, "POI lines", group=G3)
bool showBOS = input.bool(true, "BOS conversions", group=G3)
bool showSwings = input.bool(false, "HH / HL / LH / LL labels", group=G3)
bool showZigzag = input.bool(false, "ZigZag structure", group=G3)
int structureLen = input.int(10, "Structure swing strength", minval=2, maxval=50, group=G3)
int zoneHistory = input.int(8, "Zones per direction", minval=1, maxval=25, group=G3)
float zoneWidth = input.float(0.35, "Zone width / ATR", minval=0.05, step=0.05, group=G3)
float zoneSpacing = input.float(1.25, "Minimum zone separation / ATR", minval=0, step=0.25, group=G3)
int zoneFade = input.int(91, "Zone transparency", minval=60, maxval=100, group=G3)
int zoneProjection = input.int(35, "Zone projection bars", minval=1, maxval=300, group=G3)
color supplyColor = input.color(#D7A8C2, "Supply color", group=G3)
color demandColor = input.color(#88B8CD, "Demand color", group=G3)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 04 | CHART SIGNALS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
string G4 = "04 | UP / DOWN Intelligence"
bool showSignals = input.bool(true, "Show UP / DOWN signals", group=G4)
bool useRejection = input.bool(true, "Trendline rejection", group=G4)
bool useSweep = input.bool(true, "Liquidity sweep / reclaim", group=G4)
bool useBreakout = input.bool(true, "Trendline breakout", group=G4)
bool useRetest = input.bool(true, "Breakout retest", group=G4)
bool requireStructure = input.bool(false, "Require nearby Fluid Structure", group=G4)
string confirmation = input.string("Strict", "Confirmation", options=["Balanced", "Strict"], group=G4)
float sweepATR = input.float(0.08, "Sweep penetration / ATR", minval=0.01, step=0.01, group=G4)
float bodyATR = input.float(0.30, "Displacement body / ATR", minval=0.05, step=0.05, group=G4)
int emaLen = input.int(34, "Momentum EMA", minval=2, group=G4)
int cooldownBars = input.int(18, "Signal cooldown bars", minval=0, group=G4)
int retestWindow = input.int(10, "Retest window", minval=2, maxval=50, group=G4)
bool oneSignalPerLine = input.bool(true, "One rejection / sweep per line", group=G4)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 05 | MTF INTELLIGENCE
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
string G5 = "05 | MTF Trendline Intelligence"
bool enableMTF = input.bool(true, "Enable MTF Intelligence", group=G5)
string mtfMode = input.string("Confluence", "Signal mode", options=["Confluence", "Information Only", "Strict Alignment", "Chart TF Only"], group=G5)
string tf1 = input.timeframe("5", "Timeframe 1", group=G5)
string tf2 = input.timeframe("15", "Timeframe 2", group=G5)
string tf3 = input.timeframe("60", "Timeframe 3", group=G5)
string tf4 = input.timeframe("240", "Timeframe 4", group=G5)
int mtfPivot = input.int(7, "MTF pivot strength", minval=2, maxval=30, group=G5)
float mtfTolerance = input.float(0.35, "MTF trendline proximity / ATR", minval=0.05, step=0.05, group=G5)
float confluenceThreshold = input.float(60, "Minimum MTF confluence %", minval=0, maxval=100, group=G5)
bool showMTFLines = input.bool(false, "Show MTF projected trendlines", group=G5)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 06 | MOVEMENT
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
string G6 = "06 | Movement Calculator"
string movementMode = input.string("Entry Triggered", "Movement mode", options=["Entry Triggered", "Continuous"], group=G6)
string movementUnit = input.string("Percentage", "Movement unit", options=["Percentage", "Price Change", "Ticks"], group=G6)
bool showEntryGuide = input.bool(false, "Show entry price guide", group=G6)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 07 | MAIN DASHBOARD
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
string G7 = "07 | Main Decision Console"
bool showDashboard = input.bool(true, "Show main dashboard", group=G7)
string dashPosition = input.string("Top Right", "Position", options=["Top Right", "Top Left", "Bottom Right", "Bottom Left", "Top Center", "Bottom Center", "Middle Right", "Middle Left"], group=G7)
string dashSize = input.string("Medium", "Font size", options=["Tiny", "Small", "Medium", "Large"], group=G7)
string dashLayout = input.string("Detailed", "Layout", options=["Compact", "Detailed"], group=G7)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 08 | MTF DASHBOARD
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
string G8 = "08 | MTF Dashboard"
bool showMTFDashboard = input.bool(true, "Show MTF dashboard", group=G8)
string mtfPosition = input.string("Bottom Right", "Position", options=["Top Right", "Top Left", "Bottom Right", "Bottom Left", "Top Center", "Bottom Center", "Middle Right", "Middle Left"], group=G8)
string mtfSize = input.string("Medium", "Font size", options=["Tiny", "Small", "Medium", "Large"], group=G8)
string mtfLayout = input.string("Detailed", "Layout", options=["Compact", "Detailed"], group=G8)
color dashBg = input.color(#111925, "Dashboard background", group=G8)
color dashAccent = input.color(#7CB9DD, "Dashboard accent", group=G8)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// HELPERS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
f_project(int x1, float y1, int x2, float y2, int x) =>
    x2 > x1 ? y1 + (y2 - y1) * (x - x1) / float(x2 - x1) : na
 
f_left(int x) =>
    leftMode == "Custom" ? math.max(0, x - leftBars) : x
 
f_right(int x) =>
    rightMode == "None" ? x : bar_index + rightBars
 
f_extend() =>
    leftMode == "Infinite" and rightMode == "Infinite" ? extend.both : leftMode == "Infinite" ? extend.left : rightMode == "Infinite" ? extend.right : extend.none
 
f_pos(string p) =>
    switch p
        "Top Left" => position.top_left
        "Bottom Right" => position.bottom_right
        "Bottom Left" => position.bottom_left
        "Top Center" => position.top_center
        "Bottom Center" => position.bottom_center
        "Middle Right" => position.middle_right
        "Middle Left" => position.middle_left
        => position.top_right
 
f_size(string s) =>
    switch s
        "Tiny" => size.tiny
        "Medium" => size.normal
        "Large" => size.large
        => size.small
 
f_measure(float delta, float reference) =>
    string result = "—"
    if not na(delta) and not na(reference)
        if movementUnit == "Percentage"
            result := reference != 0 ? str.tostring(delta / reference * 100, "#.##") + "%" : "—"
        else if movementUnit == "Ticks"
            result := str.tostring(delta / syminfo.mintick, "#.0") + " ticks"
        else
            result := str.tostring(delta, format.mintick)
    result
 
f_trimLines(array<line> a, int maximum) =>
    while array.size(a) > maximum
        line.delete(array.shift(a))
 
f_trimBoxes(array<box> a, int maximum) =>
    while array.size(a) > maximum
        box.delete(array.shift(a))
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// MARKET DATA
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
float atr = ta.atr(atrLen)
float ema = ta.ema(close, emaLen)
bool confirmed = barstate.isconfirmed
bool bull = close > open
bool bear = close < open
bool displacement = math.abs(close - open) >= atr * bodyATR
 
float ph = ta.pivothigh(high, pivotLen, pivotLen)
float pl = ta.pivotlow(low, pivotLen, pivotLen)
float localLow = ta.lowest(low, pivotLen * 2 + 1)
float localHigh = ta.highest(high, pivotLen * 2 + 1)
bool validHigh = not na(ph) and not na(atr[pivotLen]) and ph - localLow >= atr[pivotLen] * 0.9
bool validLow = not na(pl) and not na(atr[pivotLen]) and localHigh - pl >= atr[pivotLen] * 0.9
 
var array<int> highBars = array.new_int()
var array<float> highPrices = array.new_float()
var array<int> lowBars = array.new_int()
var array<float> lowPrices = array.new_float()
 
if confirmed
    if validHigh
        array.unshift(highBars, bar_index - pivotLen)
        array.unshift(highPrices, ph)
        if array.size(highBars) > pivotMemory
            array.pop(highBars)
            array.pop(highPrices)
    if validLow
        array.unshift(lowBars, bar_index - pivotLen)
        array.unshift(lowPrices, pl)
        if array.size(lowBars) > pivotMemory
            array.pop(lowBars)
            array.pop(lowPrices)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// PRECISION QUALITY ENGINE
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
f_quality(int x1, float y1, int x2, float y2, bool supportSide) =>
    float result = -1.0
    int gap = x2 - x1
    if gap >= minGap and gap <= maxGap and atr > 0
        float slope = math.abs((y2 - y1) / gap) / atr
        if slope <= maxSlope
            int violations = 0
            int touches = 0
            int observations = 0
            int lastTouch = -100000
            int firstX = math.max(x1, bar_index - 220)
            for x = firstX to bar_index
                int offset = bar_index - x
                if offset >= 0 and offset < 1200
                    float projected = f_project(x1, y1, x2, y2, x)
                    float localATR = nz(atr[offset], atr)
                    if x >= x2
                        bool broken = supportSide ? close[offset] < projected - localATR * breakATR : close[offset] > projected + localATR * breakATR
                        if broken
                            violations += 1
                        observations += 1
                    bool touched = supportSide ? math.abs(low[offset] - projected) <= localATR * touchATR : math.abs(high[offset] - projected) <= localATR * touchATR
                    if touched and x - lastTouch >= pivotLen
                        touches += 1
                        lastTouch := x
            if observations > 0
                float integrity = math.max(0, 100 * (1 - float(violations) / observations))
                float touchScore = math.min(100, touches * 25.0)
                float gapScore = math.min(100, gap / 80.0 * 100)
                float slopeScore = math.max(0, 100 - slope / maxSlope * 65)
                float recency = math.max(0, 100 - (bar_index - x2) / 220.0 * 100)
                result := integrity * 0.30 + touchScore * 0.27 + gapScore * 0.18 + slopeScore * 0.10 + recency * 0.15
                if violations > observations * 0.10
                    result *= 0.60
    result
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// PRIMARY TRENDLINE STATE
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
type Trend
    int x1
    float y1
    int x2
    float y2
    float quality
    int born
    bool active
    line drawing
 
var Trend support = Trend.new(na, na, na, na, na, na, false, na)
var Trend resistance = Trend.new(na, na, na, na, na, na, false, na)
var array<line> brokenSupports = array.new_line()
var array<line> brokenResistances = array.new_line()
 
float bestSupQ = -1.0
float bestResQ = -1.0
int sx1 = na
int sx2 = na
int rx1 = na
int rx2 = na
float sy1 = na
float sy2 = na
float ry1 = na
float ry2 = na
 
// FIX: Quality calls are evaluated consistently on candidate loops.
if confirmed and validLow and array.size(lowBars) >= 2
    for i = 0 to array.size(lowBars) - 2
        for j = i + 1 to array.size(lowBars) - 1
            int x2 = array.get(lowBars, i)
            int x1 = array.get(lowBars, j)
            float y2 = array.get(lowPrices, i)
            float y1 = array.get(lowPrices, j)
            float q = f_quality(x1, y1, x2, y2, true)
            float projected = f_project(x1, y1, x2, y2, bar_index)
            if y2 > y1 and close >= projected - atr * breakATR and q > bestSupQ
                bestSupQ := q
                sx1 := x1
                sx2 := x2
                sy1 := y1
                sy2 := y2
 
if confirmed and validHigh and array.size(highBars) >= 2
    for i = 0 to array.size(highBars) - 2
        for j = i + 1 to array.size(highBars) - 1
            int x2 = array.get(highBars, i)
            int x1 = array.get(highBars, j)
            float y2 = array.get(highPrices, i)
            float y1 = array.get(highPrices, j)
            float q = f_quality(x1, y1, x2, y2, false)
            float projected = f_project(x1, y1, x2, y2, bar_index)
            if y2 < y1 and close <= projected + atr * breakATR and q > bestResQ
                bestResQ := q
                rx1 := x1
                rx2 := x2
                ry1 := y1
                ry2 := y2
 
if confirmed
    if bestSupQ >= minQuality and not na(sx1)
        if not support.active or support.x1 != sx1 or support.x2 != sx2
            if not na(support.drawing)
                line.delete(support.drawing)
            support := Trend.new(sx1, sy1, sx2, sy2, bestSupQ, bar_index, true, na)
    if bestResQ >= minQuality and not na(rx1)
        if not resistance.active or resistance.x1 != rx1 or resistance.x2 != rx2
            if not na(resistance.drawing)
                line.delete(resistance.drawing)
            resistance := Trend.new(rx1, ry1, rx2, ry2, bestResQ, bar_index, true, na)
 
float supNow = support.active ? f_project(support.x1, support.y1, support.x2, support.y2, bar_index) : na
float resNow = resistance.active ? f_project(resistance.x1, resistance.y1, resistance.x2, resistance.y2, bar_index) : na
bool supEligible = support.active and bar_index > support.born
bool resEligible = resistance.active and bar_index > resistance.born
bool supportBreak = confirmed and supEligible and close < supNow - atr * breakATR
bool resistanceBreak = confirmed and resEligible and close > resNow + atr * breakATR
 
if confirmed
    if support.active
        int xa = f_left(support.x1)
        int xb = math.max(support.x2 + 1, f_right(support.x2))
        float ya = f_project(support.x1, support.y1, support.x2, support.y2, xa)
        float yb = f_project(support.x1, support.y1, support.x2, support.y2, xb)
        if na(support.drawing)
            support.drawing := line.new(xa, ya, xb, yb, extend=f_extend(), color=showPrimary ? upColor : color.new(upColor, 100), width=primaryWidth)
        else
            line.set_xy1(support.drawing, xa, ya)
            line.set_xy2(support.drawing, xb, yb)
            line.set_extend(support.drawing, f_extend())
            line.set_color(support.drawing, showPrimary ? upColor : color.new(upColor, 100))
    if resistance.active
        int xa = f_left(resistance.x1)
        int xb = math.max(resistance.x2 + 1, f_right(resistance.x2))
        float ya = f_project(resistance.x1, resistance.y1, resistance.x2, resistance.y2, xa)
        float yb = f_project(resistance.x1, resistance.y1, resistance.x2, resistance.y2, xb)
        if na(resistance.drawing)
            resistance.drawing := line.new(xa, ya, xb, yb, extend=f_extend(), color=showPrimary ? downColor : color.new(downColor, 100), width=primaryWidth)
        else
            line.set_xy1(resistance.drawing, xa, ya)
            line.set_xy2(resistance.drawing, xb, yb)
            line.set_extend(resistance.drawing, f_extend())
            line.set_color(resistance.drawing, showPrimary ? downColor : color.new(downColor, 100))
 
if supportBreak
    support.active := false
    if not na(support.drawing)
        line.set_extend(support.drawing, extend.none)
        line.set_xy2(support.drawing, bar_index, supNow)
        line.set_style(support.drawing, brokenStyle == "Dashed" ? line.style_dashed : line.style_dotted)
        line.set_width(support.drawing, brokenWidth)
        line.set_color(support.drawing, showBroken ? color.new(brokenColor, brokenFade) : color.new(brokenColor, 100))
        array.push(brokenSupports, support.drawing)
        support.drawing := na
 
if resistanceBreak
    resistance.active := false
    if not na(resistance.drawing)
        line.set_extend(resistance.drawing, extend.none)
        line.set_xy2(resistance.drawing, bar_index, resNow)
        line.set_style(resistance.drawing, brokenStyle == "Dashed" ? line.style_dashed : line.style_dotted)
        line.set_width(resistance.drawing, brokenWidth)
        line.set_color(resistance.drawing, showBroken ? color.new(brokenColor, brokenFade) : color.new(brokenColor, 100))
        array.push(brokenResistances, resistance.drawing)
        resistance.drawing := na
 
f_trimLines(brokenSupports, brokenHistory)
f_trimLines(brokenResistances, brokenHistory)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// MEDIUM / LONG GEOMETRY
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
f_secondary(int length, bool enabled, color c, int w) =>
    float pivotH = ta.pivothigh(high, length, length)
    float pivotL = ta.pivotlow(low, length, length)
    var float h1 = na
    var float h2 = na
    var float l1 = na
    var float l2 = na
    var int hx1 = na
    var int hx2 = na
    var int lx1 = na
    var int lx2 = na
    var line upper = na
    var line lower = na
    if barstate.isconfirmed
        if not na(pivotH)
            h1 := h2
            hx1 := hx2
            h2 := pivotH
            hx2 := bar_index - length
        if not na(pivotL)
            l1 := l2
            lx1 := lx2
            l2 := pivotL
            lx2 := bar_index - length
        if not na(hx1) and not na(hx2) and hx2 > hx1
            int xa = f_left(hx1)
            int xb = math.max(hx2 + 1, f_right(hx2))
            float ya = f_project(hx1, h1, hx2, h2, xa)
            float yb = f_project(hx1, h1, hx2, h2, xb)
            if na(upper)
                upper := line.new(xa, ya, xb, yb, extend=f_extend(), color=color.new(c, enabled ? 40 : 100), width=w, style=line.style_dotted)
            else
                line.set_xy1(upper, xa, ya)
                line.set_xy2(upper, xb, yb)
                line.set_extend(upper, f_extend())
                line.set_color(upper, color.new(c, enabled ? 40 : 100))
        if not na(lx1) and not na(lx2) and lx2 > lx1
            int xa = f_left(lx1)
            int xb = math.max(lx2 + 1, f_right(lx2))
            float ya = f_project(lx1, l1, lx2, l2, xa)
            float yb = f_project(lx1, l1, lx2, l2, xb)
            if na(lower)
                lower := line.new(xa, ya, xb, yb, extend=f_extend(), color=color.new(c, enabled ? 40 : 100), width=w, style=line.style_dotted)
            else
                line.set_xy1(lower, xa, ya)
                line.set_xy2(lower, xb, yb)
                line.set_extend(lower, f_extend())
                line.set_color(lower, color.new(c, enabled ? 40 : 100))
    [not na(hx1) and not na(hx2) ? f_project(hx1, h1, hx2, h2, bar_index) : na, not na(lx1) and not na(lx2) ? f_project(lx1, l1, lx2, l2, bar_index) : na]
 
[mediumRes, mediumSup] = f_secondary(mediumLen, showMedium, mediumColor, 1)
[longRes, longSup] = f_secondary(longLen, showLong, longColor, 2)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// FLUID STRUCTURE
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
float sh = ta.pivothigh(high, structureLen, structureLen)
float sl = ta.pivotlow(low, structureLen, structureLen)
 
var array<box> supplies = array.new_box()
var array<box> demands = array.new_box()
var array<line> supplyPOIs = array.new_line()
var array<line> demandPOIs = array.new_line()
var array<box> bosBoxes = array.new_box()
var array<line> zigLines = array.new_line()
 
var float lastStructureHigh = na
var float lastStructureLow = na
var float lastSupplyPOI = na
var float lastDemandPOI = na
var int zigBar = na
var float zigPrice = na
var int zigType = 0
 
bool bullBOS = false
bool bearBOS = false
 
if confirmed
    if not na(sh)
        int pivotBar = bar_index - structureLen
        float top = sh
        float bottom = top - nz(atr[structureLen], atr) * zoneWidth
        float poi = (top + bottom) / 2
        bool separate = true
        if array.size(supplies) > 0
            for i = 0 to array.size(supplies) - 1
                box existing = array.get(supplies, i)
                if math.abs(box.get_top(existing) - top) < atr * zoneSpacing
                    separate := false
        if separate
            box z = box.new(pivotBar, top, bar_index + zoneProjection, bottom, border_color=color.new(supplyColor, showFluid and showSupply ? 86 : 100), bgcolor=color.new(supplyColor, showFluid and showSupply ? zoneFade : 100), text=showFluid and showSupply ? "SUPPLY" : "", text_color=color.new(supplyColor, 70), text_size=size.tiny)
            line p = line.new(pivotBar, poi, bar_index + zoneProjection, poi, color=color.new(supplyColor, showFluid and showPOI ? 72 : 100), style=line.style_dotted, width=1)
            array.push(supplies, z)
            array.push(supplyPOIs, p)
            lastSupplyPOI := poi
        if showFluid and showSwings
            label.new(pivotBar, top, na(lastStructureHigh) ? "H" : sh > lastStructureHigh ? "HH" : "LH", style=label.style_none, textcolor=color.new(supplyColor, 55), size=size.tiny)
        if showFluid and showZigzag
            if zigType == -1 and not na(zigBar)
                array.push(zigLines, line.new(zigBar, zigPrice, pivotBar, top, color=color.new(supplyColor, 78), width=1))
        zigBar := pivotBar
        zigPrice := top
        zigType := 1
        lastStructureHigh := sh
 
    if not na(sl)
        int pivotBar = bar_index - structureLen
        float bottom = sl
        float top = bottom + nz(atr[structureLen], atr) * zoneWidth
        float poi = (top + bottom) / 2
        bool separate = true
        if array.size(demands) > 0
            for i = 0 to array.size(demands) - 1
                box existing = array.get(demands, i)
                if math.abs(box.get_bottom(existing) - bottom) < atr * zoneSpacing
                    separate := false
        if separate
            box z = box.new(pivotBar, top, bar_index + zoneProjection, bottom, border_color=color.new(demandColor, showFluid and showDemand ? 86 : 100), bgcolor=color.new(demandColor, showFluid and showDemand ? zoneFade : 100), text=showFluid and showDemand ? "DEMAND" : "", text_color=color.new(demandColor, 70), text_size=size.tiny)
            line p = line.new(pivotBar, poi, bar_index + zoneProjection, poi, color=color.new(demandColor, showFluid and showPOI ? 72 : 100), style=line.style_dotted, width=1)
            array.push(demands, z)
            array.push(demandPOIs, p)
            lastDemandPOI := poi
        if showFluid and showSwings
            label.new(pivotBar, bottom, na(lastStructureLow) ? "L" : sl > lastStructureLow ? "HL" : "LL", style=label.style_none, textcolor=color.new(demandColor, 55), size=size.tiny)
        if showFluid and showZigzag
            if zigType == 1 and not na(zigBar)
                array.push(zigLines, line.new(zigBar, zigPrice, pivotBar, bottom, color=color.new(demandColor, 78), width=1))
        zigBar := pivotBar
        zigPrice := bottom
        zigType := -1
        lastStructureLow := sl
 
    if array.size(supplies) > 0
        for i = array.size(supplies) - 1 to 0
            box z = array.get(supplies, i)
            line p = array.get(supplyPOIs, i)
            if close > box.get_top(z)
                bullBOS := true
                if showFluid and showBOS
                    float mid = (box.get_top(z) + box.get_bottom(z)) / 2
                    box.set_top(z, mid)
                    box.set_bottom(z, mid)
                    box.set_right(z, bar_index)
                    box.set_bgcolor(z, color.new(supplyColor, 100))
                    box.set_border_color(z, color.new(supplyColor, 82))
                    box.set_text(z, "BOS")
                    box.set_text_color(z, color.new(supplyColor, 70))
                    array.push(bosBoxes, z)
                else
                    box.delete(z)
                line.delete(p)
                array.remove(supplies, i)
                array.remove(supplyPOIs, i)
            else
                box.set_right(z, bar_index + zoneProjection)
                line.set_x2(p, bar_index + zoneProjection)
 
    if array.size(demands) > 0
        for i = array.size(demands) - 1 to 0
            box z = array.get(demands, i)
            line p = array.get(demandPOIs, i)
            if close < box.get_bottom(z)
                bearBOS := true
                if showFluid and showBOS
                    float mid = (box.get_top(z) + box.get_bottom(z)) / 2
                    box.set_top(z, mid)
                    box.set_bottom(z, mid)
                    box.set_right(z, bar_index)
                    box.set_bgcolor(z, color.new(demandColor, 100))
                    box.set_border_color(z, color.new(demandColor, 82))
                    box.set_text(z, "BOS")
                    box.set_text_color(z, color.new(demandColor, 70))
                    array.push(bosBoxes, z)
                else
                    box.delete(z)
                line.delete(p)
                array.remove(demands, i)
                array.remove(demandPOIs, i)
            else
                box.set_right(z, bar_index + zoneProjection)
                line.set_x2(p, bar_index + zoneProjection)
 
    while array.size(supplies) > zoneHistory
        box.delete(array.shift(supplies))
        line.delete(array.shift(supplyPOIs))
    while array.size(demands) > zoneHistory
        box.delete(array.shift(demands))
        line.delete(array.shift(demandPOIs))
    f_trimBoxes(bosBoxes, zoneHistory * 2)
    f_trimLines(zigLines, 40)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// MTF TRENDLINE ENGINE
// FIX: Return prior values INSIDE the requested expression.
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
f_mtfTrend() =>
    float pivotH = ta.pivothigh(high, mtfPivot, mtfPivot)
    float pivotL = ta.pivotlow(low, mtfPivot, mtfPivot)
    var float h1 = na
    var float h2 = na
    var float l1 = na
    var float l2 = na
    var int ht1 = na
    var int ht2 = na
    var int lt1 = na
    var int lt2 = na
 
    if not na(pivotH)
        h1 := h2
        ht1 := ht2
        h2 := pivotH
        ht2 := time[mtfPivot]
    if not na(pivotL)
        l1 := l2
        lt1 := lt2
        l2 := pivotL
        lt2 := time[mtfPivot]
 
    float res = not na(ht1) and not na(ht2) and ht2 > ht1 ? h2 + (h2 - h1) / float(ht2 - ht1) * (time - ht2) : na
    float sup = not na(lt1) and not na(lt2) and lt2 > lt1 ? l2 + (l2 - l1) / float(lt2 - lt1) * (time - lt2) : na
    float a = ta.atr(14)
    float tolerance = a * mtfTolerance
    bool validSup = not na(sup) and close >= sup - tolerance
    bool validRes = not na(res) and close <= res + tolerance
    int direction = validSup and not validRes ? 1 : validRes and not validSup ? -1 : validSup and validRes ? close >= (sup + res) / 2 ? 1 : -1 : 0
    float chosen = direction == 1 ? sup : direction == -1 ? res : na
    float distance = not na(chosen) and a > 0 ? math.abs(close - chosen) / a : na
    float quality = not na(distance) ? math.max(0, math.min(100, 100 - distance * 22)) : na
 
    [direction, quality, sup, res, close, direction[1], quality[1], sup[1], res[1], close[1]]
 
f_mtf(string tf) =>
    bool higher = timeframe.in_seconds(tf) > timeframe.in_seconds(timeframe.period)
    [dl, ql, slv, rlv, cl, dp, qp, sp, rp, cp] = request.security(syminfo.tickerid, tf, f_mtfTrend(), lookahead=barmerge.lookahead_off)
    [higher ? dp : dl, higher ? qp : ql, higher ? sp : slv, higher ? rp : rlv, higher ? cp : cl]
 
[d1, q1, s1, r1, c1] = f_mtf(tf1)
[d2, q2, s2, r2, c2] = f_mtf(tf2)
[d3, q3, s3, r3, c3] = f_mtf(tf3)
[d4, q4, s4, r4, c4] = f_mtf(tf4)
 
float w1 = 1.0
float w2 = 1.25
float w3 = 1.5
float w4 = 1.75
float availableWeight = (d1 != 0 ? w1 : 0) + (d2 != 0 ? w2 : 0) + (d3 != 0 ? w3 : 0) + (d4 != 0 ? w4 : 0)
float upWeight = (d1 == 1 ? w1 : 0) + (d2 == 1 ? w2 : 0) + (d3 == 1 ? w3 : 0) + (d4 == 1 ? w4 : 0)
float downWeight = (d1 == -1 ? w1 : 0) + (d2 == -1 ? w2 : 0) + (d3 == -1 ? w3 : 0) + (d4 == -1 ? w4 : 0)
float upConfluence = availableWeight > 0 ? upWeight / availableWeight * 100 : na
float downConfluence = availableWeight > 0 ? downWeight / availableWeight * 100 : na
int mtfDirection = availableWeight == 0 ? 0 : upWeight > downWeight ? 1 : downWeight > upWeight ? -1 : 0
float mtfConfluence = mtfDirection == 1 ? upConfluence : mtfDirection == -1 ? downConfluence : na
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// SIGNAL ENGINE
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
bool bullMomentum = close > ema
bool bearMomentum = close < ema
bool bullConfirm = confirmation == "Strict" ? bull and bullMomentum and displacement : bull and (bullMomentum or displacement)
bool bearConfirm = confirmation == "Strict" ? bear and bearMomentum and displacement : bear and (bearMomentum or displacement)
 
bool bullRejection = supEligible and not supportBreak and low <= supNow + atr * touchATR and close > supNow and bull
bool bearRejection = resEligible and not resistanceBreak and high >= resNow - atr * touchATR and close < resNow and bear
bool bullSweep = supEligible and not supportBreak and low < supNow - atr * sweepATR and close > supNow and bull
bool bearSweep = resEligible and not resistanceBreak and high > resNow + atr * sweepATR and close < resNow and bear
 
var float pendingUp = na
var float pendingDown = na
var int pendingUpBar = na
var int pendingDownBar = na
bool bullRetest = false
bool bearRetest = false
 
if confirmed
    if not na(pendingUpBar)
        if bar_index - pendingUpBar > retestWindow or close < pendingUp - atr * touchATR
            pendingUp := na
            pendingUpBar := na
        else if bar_index > pendingUpBar and low <= pendingUp + atr * touchATR and close > pendingUp and bull
            bullRetest := true
            pendingUp := na
            pendingUpBar := na
    if not na(pendingDownBar)
        if bar_index - pendingDownBar > retestWindow or close > pendingDown + atr * touchATR
            pendingDown := na
            pendingDownBar := na
        else if bar_index > pendingDownBar and high >= pendingDown - atr * touchATR and close < pendingDown and bear
            bearRetest := true
            pendingDown := na
            pendingDownBar := na
    if resistanceBreak
        pendingUp := resNow
        pendingUpBar := bar_index
    if supportBreak
        pendingDown := supNow
        pendingDownBar := bar_index
 
bool nearDemand = not na(lastDemandPOI) and math.abs(close - lastDemandPOI) <= atr * 1.5
bool nearSupply = not na(lastSupplyPOI) and math.abs(close - lastSupplyPOI) <= atr * 1.5
bool bullStructureOK = not requireStructure or nearDemand or bullBOS
bool bearStructureOK = not requireStructure or nearSupply or bearBOS
bool rawUp = (useRejection and bullRejection) or (useSweep and bullSweep) or (useBreakout and resistanceBreak) or (useRetest and bullRetest)
bool rawDown = (useRejection and bearRejection) or (useSweep and bearSweep) or (useBreakout and supportBreak) or (useRetest and bearRetest)
 
bool mtfUpOK = not enableMTF or mtfMode == "Chart TF Only" or mtfMode == "Information Only" or (mtfMode == "Confluence" ? not na(upConfluence) and upConfluence >= confluenceThreshold : d1 == 1 and d2 == 1 and d3 == 1 and d4 == 1)
bool mtfDownOK = not enableMTF or mtfMode == "Chart TF Only" or mtfMode == "Information Only" or (mtfMode == "Confluence" ? not na(downConfluence) and downConfluence >= confluenceThreshold : d1 == -1 and d2 == -1 and d3 == -1 and d4 == -1)
 
var int lastSignalBar = na
var int lastDirection = 0
var string lastType = "NONE"
var int signaledSupport = na
var int signaledResistance = na
 
bool cooldownOK = na(lastSignalBar) or bar_index - lastSignalBar > cooldownBars
bool upSignal = false
bool downSignal = false
 
if confirmed and cooldownOK
    bool upReady = rawUp and bullConfirm and bullStructureOK and mtfUpOK
    bool downReady = rawDown and bearConfirm and bearStructureOK and mtfDownOK
    if upReady and not downReady
        bool lineSignal = bullRejection or bullSweep
        bool duplicate = lineSignal and oneSignalPerLine and not na(signaledSupport) and signaledSupport == support.born
        if not duplicate
            upSignal := true
    if downReady and not upReady
        bool lineSignal = bearRejection or bearSweep
        bool duplicate = lineSignal and oneSignalPerLine and not na(signaledResistance) and signaledResistance == resistance.born
        if not duplicate
            downSignal := true
 
if upSignal
    lastSignalBar := bar_index
    lastDirection := 1
    lastType := bullSweep ? "SWEEP" : bullRetest ? "RETEST" : resistanceBreak ? "BREAKOUT" : "REJECTION"
    if bullRejection or bullSweep
        signaledSupport := support.born
if downSignal
    lastSignalBar := bar_index
    lastDirection := -1
    lastType := bearSweep ? "SWEEP" : bearRetest ? "RETEST" : supportBreak ? "BREAKOUT" : "REJECTION"
    if bearRejection or bearSweep
        signaledResistance := resistance.born
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// MOVEMENT
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var float entryPrice = na
var int entryBar = na
var int entryDirection = 0
var float mfe = 0.0
var float mae = 0.0
var line entryGuide = na
 
if upSignal or downSignal
    entryPrice := close
    entryBar := bar_index
    entryDirection := upSignal ? 1 : -1
    mfe := 0
    mae := 0
    if not na(entryGuide)
        line.delete(entryGuide)
        entryGuide := na
    if showEntryGuide
        entryGuide := line.new(bar_index, entryPrice, bar_index + 1, entryPrice, extend=extend.right, color=color.new(upSignal ? upColor : downColor, 55), style=line.style_dotted)
 
if not na(entryPrice) and bar_index > entryBar
    float favorable = entryDirection == 1 ? high - entryPrice : entryPrice - low
    float adverse = entryDirection == 1 ? low - entryPrice : entryPrice - high
    mfe := math.max(mfe, favorable)
    mae := math.min(mae, adverse)
 
float nearest = na
if support.active and resistance.active
    nearest := math.abs(close - supNow) < math.abs(close - resNow) ? supNow : resNow
else if support.active
    nearest := supNow
else if resistance.active
    nearest := resNow
 
float reference = movementMode == "Entry Triggered" ? entryPrice : nearest
float movement = movementMode == "Entry Triggered" ? not na(entryPrice) ? (close - entryPrice) * entryDirection : na : not na(nearest) ? close - nearest : na
string movementText = f_measure(movement, reference)
string mfeText = f_measure(mfe, entryPrice)
string maeText = f_measure(mae, entryPrice)
string barsText = na(entryBar) ? "—" : str.tostring(bar_index - entryBar)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// DECISION CONSOLE
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
string primaryLine = "NONE"
float quality = na
if support.active and resistance.active
    if support.quality >= resistance.quality
        primaryLine := "SUPPORT"
        quality := support.quality
    else
        primaryLine := "RESISTANCE"
        quality := resistance.quality
else if support.active
    primaryLine := "SUPPORT"
    quality := support.quality
else if resistance.active
    primaryLine := "RESISTANCE"
    quality := resistance.quality
 
bool nearSupport = support.active and math.abs(close - supNow) <= atr * 0.6
bool nearResistance = resistance.active and math.abs(close - resNow) <= atr * 0.6
string action = "WAIT"
string reason = "NO CONFIRMED SETUP"
color actionColor = color.silver
 
if upSignal
    action := "UP CONFIRMED"
    reason := lastType
    actionColor := upColor
else if downSignal
    action := "DOWN CONFIRMED"
    reason := lastType
    actionColor := downColor
else if not na(pendingUpBar)
    action := "WATCH UP"
    reason := "AWAIT RETEST"
    actionColor := upColor
else if not na(pendingDownBar)
    action := "WATCH DOWN"
    reason := "AWAIT RETEST"
    actionColor := downColor
else if nearSupport
    action := "UP SETUP"
    reason := "SUPPORT TEST"
    actionColor := upColor
else if nearResistance
    action := "DOWN SETUP"
    reason := "RESISTANCE TEST"
    actionColor := downColor
else if lastDirection != 0 and not na(entryPrice)
    bool favorable = (close - entryPrice) * lastDirection > 0
    action := favorable ? "HOLD / MONITOR" : "REASSESS"
    reason := favorable ? "MOVE FAVORABLE" : "MOVE ADVERSE"
    actionColor := favorable ? upColor : downColor
 
string qualityText = na(quality) ? "—" : str.tostring(quality, "#.0") + "/100"
string lastDirText = lastDirection == 1 ? "UP" : lastDirection == -1 ? "DOWN" : "NONE"
 
plotshape(showSignals and upSignal, title="TOLAG UP", text="UP", style=shape.labelup, location=location.belowbar, color=upColor, textcolor=#102018, size=size.tiny)
plotshape(showSignals and downSignal, title="TOLAG DOWN", text="DOWN", style=shape.labeldown, location=location.abovebar, color=downColor, textcolor=#24170F, size=size.tiny)
plot(support.active ? supNow : na, title="Precision Support", display=display.none)
plot(resistance.active ? resNow : na, title="Precision Resistance", display=display.none)
plot(quality, title="Trendline Quality", display=display.none)
plot(mtfConfluence, title="MTF Confluence", display=display.none)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// MAIN DASHBOARD
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var table dash = table.new(f_pos(dashPosition), 5, 3, bgcolor=dashBg, frame_color=color.new(dashAccent, 55), frame_width=1, border_width=1, border_color=color.new(dashAccent, 88))
 
f_mainCell(int col, int row, string value, color textColor, color bg) =>
    table.cell(dash, col, row, value, text_color=textColor, bgcolor=bg, text_size=f_size(dashSize), text_halign=text.align_center)
 
if barstate.islast
    table.clear(dash, 0, 0, 4, 2)
    if showDashboard
        color header = color.new(dashAccent, 82)
        color panel = color.new(#263445, 28)
        color muted = color.new(color.white, 30)
        f_mainCell(0, 0, "TOLAG ACTION", dashAccent, header)
        f_mainCell(1, 0, "TRENDLINE", dashAccent, header)
        f_mainCell(2, 0, "TRIGGER", dashAccent, header)
        f_mainCell(3, 0, "MOVEMENT", dashAccent, header)
        f_mainCell(4, 0, "STATUS", dashAccent, header)
        f_mainCell(0, 1, action, actionColor, panel)
        f_mainCell(1, 1, primaryLine, color.white, panel)
        f_mainCell(2, 1, lastDirText, lastDirection == 1 ? upColor : lastDirection == -1 ? downColor : muted, panel)
        f_mainCell(3, 1, movementText, na(movement) ? muted : movement >= 0 ? upColor : downColor, panel)
        f_mainCell(4, 1, supportBreak or resistanceBreak ? "LINE BROKEN" : primaryLine == "NONE" ? "NO ACTIVE LINE" : "ACTIVE", color.white, panel)
        if dashLayout == "Detailed"
            f_mainCell(0, 2, reason, muted, dashBg)
            f_mainCell(1, 2, qualityText, muted, dashBg)
            f_mainCell(2, 2, lastType, muted, dashBg)
            f_mainCell(3, 2, "MFE " + mfeText + " / MAE " + maeText, muted, dashBg)
            f_mainCell(4, 2, barsText + " BARS", muted, dashBg)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// MTF DASHBOARD
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var table mtfDash = table.new(f_pos(mtfPosition), 3, 8, bgcolor=dashBg, frame_color=color.new(dashAccent, 55), frame_width=1, border_width=1, border_color=color.new(dashAccent, 88))
 
f_mtfCell(int col, int row, string value, color textColor, color bg) =>
    table.cell(mtfDash, col, row, value, text_color=textColor, bgcolor=bg, text_size=f_size(mtfSize), text_halign=text.align_center)
 
f_direction(int d) =>
    d == 1 ? "UP" : d == -1 ? "DOWN" : "NEUTRAL"
 
f_directionColor(int d) =>
    d == 1 ? upColor : d == -1 ? downColor : color.silver
 
f_qualityText(float q) =>
    na(q) ? "—" : str.tostring(q, "#") + "/100"
 
if barstate.islast
    table.clear(mtfDash, 0, 0, 2, 7)
    if showMTFDashboard and enableMTF
        color header = color.new(dashAccent, 82)
        color panel = color.new(#263445, 28)
        color muted = color.new(color.white, 30)
 
        f_mtfCell(0, 0, "TIMEFRAME", dashAccent, header)
        f_mtfCell(1, 0, "TRENDLINE", dashAccent, header)
        f_mtfCell(2, 0, "QUALITY", dashAccent, header)
 
        f_mtfCell(0, 1, tf1, color.white, panel)
        f_mtfCell(1, 1, f_direction(d1), f_directionColor(d1), panel)
        f_mtfCell(2, 1, f_qualityText(q1), color.white, panel)
 
        f_mtfCell(0, 2, tf2, color.white, panel)
        f_mtfCell(1, 2, f_direction(d2), f_directionColor(d2), panel)
        f_mtfCell(2, 2, f_qualityText(q2), color.white, panel)
 
        f_mtfCell(0, 3, tf3, color.white, panel)
        f_mtfCell(1, 3, f_direction(d3), f_directionColor(d3), panel)
        f_mtfCell(2, 3, f_qualityText(q3), color.white, panel)
 
        f_mtfCell(0, 4, tf4, color.white, panel)
        f_mtfCell(1, 4, f_direction(d4), f_directionColor(d4), panel)
        f_mtfCell(2, 4, f_qualityText(q4), color.white, panel)
 
        string alignText = mtfDirection == 1 ? "ALIGNED UP" : mtfDirection == -1 ? "ALIGNED DOWN" : "MIXED"
        f_mtfCell(0, 5, "CONFLUENCE", dashAccent, header)
        f_mtfCell(1, 5, alignText, f_directionColor(mtfDirection), header)
        f_mtfCell(2, 5, na(mtfConfluence) ? "—" : str.tostring(mtfConfluence, "#") + "%", color.white, header)
 
        string modeText = mtfMode == "Confluence" ? "CONFLUENCE" : mtfMode == "Strict Alignment" ? "STRICT" : mtfMode == "Information Only" ? "INFO ONLY" : "CHART ONLY"
        string mtfAction = upSignal ? "UP CONFIRMED" : downSignal ? "DOWN CONFIRMED" : mtfDirection == 1 ? "WATCH UP" : mtfDirection == -1 ? "WATCH DOWN" : "WAIT"
        f_mtfCell(0, 6, "SIGNAL MODE", muted, dashBg)
        f_mtfCell(1, 6, modeText, color.white, dashBg)
        f_mtfCell(2, 6, mtfAction, upSignal ? upColor : downSignal ? downColor : color.silver, dashBg)
 
        if mtfLayout == "Detailed"
            string stateText = mtfUpOK and mtfDownOK ? "BOTH ALLOWED" : mtfUpOK ? "UP ALLOWED" : mtfDownOK ? "DOWN ALLOWED" : "FILTERED"
            f_mtfCell(0, 7, "ENTRY FILTER", muted, dashBg)
            f_mtfCell(1, 7, stateText, color.white, dashBg)
            f_mtfCell(2, 7, str.tostring(confluenceThreshold, "#") + "% MIN", muted, dashBg)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// ALERTS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
alertcondition(upSignal, "TOLAG TGL 8 UP", "TOLAG TGL 8 confirmed UP | {{ticker}} | {{interval}} | {{close}}")
alertcondition(downSignal, "TOLAG TGL 8 DOWN", "TOLAG TGL 8 confirmed DOWN | {{ticker}} | {{interval}} | {{close}}")
alertcondition(upSignal or downSignal, "TOLAG TGL 8 ANY SIGNAL", "TOLAG TGL 8 confirmed directional signal | {{ticker}} | {{interval}}")
alertcondition(supportBreak, "TOLAG SUPPORT BREAK", "TOLAG TGL 8 support trendline broken | {{ticker}} | {{interval}}")
alertcondition(resistanceBreak, "TOLAG RESISTANCE BREAK", "TOLAG TGL 8 resistance trendline broken | {{ticker}} | {{interval}}")
 
// END — TOLAG AUTO TRENDLINE PRECISION | TGL 8 V5.3

← 返回列表