XZ_MAE_Reference_Content

Steel-Sovereign · library · 455 行 · 点赞 1 · TradingView 原页

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

Pine Script

// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Steel-Sovereign
//@version=6
 
//@description XZ MAE Reference Content v1. User-visible MAE Settings help, deterministic forensic text formatting and caller-resolved Status/Story table presentation. It contains no MA/SMA/BMA discovery, qualification, lifecycle, Story admission/selection/interpretation, registry or source-authority logic.
library("XZ_MAE_Reference_Content", overlay = true)
import Steel-Sovereign/XZ_Table_Primitives/11 as xztbl
 
//==============================================================================
// SETTINGS HELP — USER-VISIBLE COPY ONLY
//==============================================================================
// These constants reproduce text already exposed by the protected MAE source.
// They are presentation/reference content and cannot create or mutate analytical state.
 
export const string TT_MICRO_SOURCE_TIMEFRAME = "Timeframe that owns the complete XZ MAE registry. 15m matches the original Daily→15m Macro/Micro workflow, but the relationship is user-selected. Detection, qualification, lifecycle and reaction history remain source-owned on every host chart timeframe. Changing the chart timeframe changes presentation only."
export const string TT_MINIMUM_CHOP_SWINGS = "Every adjacent opposite CSH/CSL pair creates a fixed close-band hypothesis. The earliest hypothesis containing this many alternating confirmed Chop Swings satisfies MA formation qualification. MA# is created only if that fixed band is entirely outside every previously confirmed persistent MA# band; exact boundary contact is allowed, but any price-band overlap suppresses creation. The rectangle never expands to admit later swings."
export const string TT_ENABLE_SECONDARY_MICRO_AUCTIONS = "Experimental Secondary Micro Auction layer. An opposing F1–F2 Chop pair fixes and retains the SMA hypothesis geometry and historical origin unless its original F1 intrudes into an already-qualified SMA interval. Pending hypotheses keep their original F1 while chronological qualification is arbitrated. The hypothesis receives confirmed SMA# identity only after the user-selected number of Micro Source closes are contained inside/on that fixed band. SMA# may still nest inside an older primary MA#. Once qualified, its independent lifecycle remains governed by the SMA defeat/FBO rules; the underlying C#/MA path continues independently."
export const string TT_SMA_CONTAINMENT_CLOSE_THRESHOLD = "Minimum number of Micro Source candles whose CLOSE is inside or exactly on the fixed F1–F2 band before the hypothesis receives confirmed SMA# identity. The F2 confirmation candle counts when contained. Default 1 preserves immediate F2 qualification for a contained F2 close; raise this value to objectively filter short-lived SMA hypotheses. A hypothesis defeated before reaching the selected count never becomes a displayed/qualified SMA#."
export const string TT_SMA_DEFEAT_CLOSE_THRESHOLD = "Shared finite-auction lifecycle threshold for SMA# and BMA#. This many consecutive Micro Source candles must CLOSE outside the fixed band on the SAME side to confirm Defeat. A close back inside before threshold is an FBO; an opposite-side outside close restarts the sequence from 1. Confirmed Defeat freezes the visible right edge at the open of the first outside candle in the qualifying run."
export const string TT_SHOW_SECONDARY_MICRO_AUCTION_TAGS = "Shows qualified SMA# using the originating C# identity (for example C#2201 → SMA#2201). Hover reports F1–F2 origin, contained-close qualification, fixed geometry, Defeat Developing/confirmed state, SMA-style FBO count and independent MA-qualification outcome."
export const string TT_MAX_VISIBLE_SECONDARY_MICRO_AUCTIONS = "Maximum most-recent qualified SMA# boxes drawn. Unqualified F1–F2 hypotheses are retained only for source-owned qualification/lifecycle bookkeeping and are not displayed. SMA# remains independently visible even when the same originating C# also qualifies as MA#."
export const string TT_ENABLE_BOUNDARY_MICRO_AUCTIONS = "Enables Boundary Micro Auction detection. Two near-equal same-side XZ close pivots establish a frozen shelf. The first valid opposing Chop Swing confirmed after shelf establishment freezes the second boundary and confirms BMA#. If an opposing Trend Swing forms first, the shelf precursor is disqualified. Provisional shelves are internal and not drawn."
export const string TT_SHOW_BOUNDARY_MICRO_AUCTION_TAGS = "Shows compact BMA# hover targets for confirmed Boundary Micro Auctions. Hover reports shelf origin/reinforcement, the post-shelf opposing Chop Swing that fixed the second boundary, immutable geometry, Defeat Developing/confirmed state and BMA-style FBO count."
export const string TT_SHELF_ORIGIN_TOLERANCE_ATR = "Maximum separation between the two same-side XZ close pivots that establish the BMA shelf, expressed as a fraction of source-timeframe ATR. The P1/P2 average freezes the shelf price; later reinforcing pivots do not move it."
export const string TT_SHELF_ORIGIN_MAX_BARS = "Maximum Micro Source bars allowed between P1 and P2 when establishing a shelf. Once established, the shelf remains under scrutiny until an opposing Chop Swing confirms BMA# or an opposing Trend Swing disqualifies the precursor."
export const string TT_SHELF_ATR_LENGTH = "Source-timeframe ATR length used only to normalize the near-equal P1/P2 shelf-origin tolerance."
export const string TT_MAX_VISIBLE_BOUNDARY_MICRO_AUCTIONS = "Maximum most-recent confirmed BMA# boxes drawn. Provisional shelf precursors remain internal and invisible."
export const string TT_SHOW_CONTAINING_AUCTIONS = "Shows retained MA# geometry currently containing price. This is presentation only; hidden MA# records remain fully retained in the analytical registry."
export const string TT_SHOW_ZONES_ABOVE_PRICE = "Number of retained MA# bands to show above current price, ranked strictly by proximity to the nearest boundary. Default 1 keeps the closest overhead Micro Auction visible while all more distant retained auctions stay hidden."
export const string TT_SHOW_ZONES_BELOW_PRICE = "Number of retained MA# bands to show below current price, ranked strictly by proximity to the nearest boundary. Default 1 keeps the closest underlying Micro Auction visible while all more distant retained auctions stay hidden."
export const string TT_SHOW_DEVELOPING_CANDIDATE = "Shows the strongest current unqualified fixed-band hypothesis. A raw close outside does not delete it: the candidate enters Escape Developing and remains visible while MAE waits for either FBO/re-engagement or structural failure away. Geometry never expands."
export const string TT_SHOW_CANDIDATE_AUDIT_TAG = "Adds one compact C# hover target to the displayed leading candidate. Hover shows State, Qualification, fixed Geometry, Resolution, why the candidate remains active during an unresolved escape, and what objectively resolves it. Presentation only."
export const string TT_SHOW_AUCTION_IDS = "Shows a compact MA# audit tag at the CURRENT chart edge for every displayed Micro Auction. Hover the tag for immutable boundaries, qualification evidence and latest lifecycle behaviour. The tag does not remain stranded at the historical origin."
export const string TT_SHOW_QUARTILES = "Shows the immutable 25%, 50% and 75% levels of each displayed Micro Auction. Quartiles are presentation geometry only; they never alter MA qualification, lifecycle or reaction classification."
export const string TT_NARRATIVE_FOCUS_MODE = "Chooses the single qualified MA# whose numbered story is presented on-chart and in the MA Story table. Auto follows the most recently qualified MA#. Manual uses the MA# entered below. Focus changes presentation only; every MA# keeps its full source-owned story ledger."
export const string TT_MANUAL_NARRATIVE_FOCUS_ID = "Used only when Narrative Focus = Manual MA#. Enter the immutable MA# identity to inspect. If that MA# is no longer retained in the current registry snapshot, the Story table reports it unavailable rather than silently switching focus."
export const string TT_SHOW_INTERACTION_AUDIT_MARKERS = "Shows the focused MA# story marker directly on the chart. Formation uses F1..Fn; post-qualification interactions use 1, 2, 3... The marker matches the same row in the MA Story table. Hover gives Event, Evidence, Story Now and concise audit data. On charts coarser than the Micro Source, the exact source event is mapped to the containing host candle for presentation only."
export const string TT_INTERACTION_AUDIT_SCOPE = "Controls which absolute story chapters are presented. Full Story shows every retained chapter. Outside-Origin Focus shows chapters whose candle originated outside the MA. Inside-Origin / Escape Focus shows inside-origin probes, Close Escapes and their causal resolutions. Focus never renumbers chapters."
export const string TT_MAX_INTERACTION_AUDIT_MARKERS = "Maximum recent story markers drawn for the focused MA#, including Formation F# and numbered interaction chapters. The retained source story ledger is unchanged; this is presentation only."
export const string TT_INTERACTION_MARKER_COLOR = "Text colour of focused MA# Formation F# and numbered interaction markers. Presentation only."
export const string TT_STORY_MARKER_TEXT_SIZE = "Text size of MA story markers on the chart. Normal is the first-load default so F# and numbered chapter references remain legible without turning into large labels."
export const string TT_SHOW_STORY_TABLE = "Shows the retained narrative ledger for the focused MA#. Formation chapters F1..Fn preserve promoted candidate history; numbered chapters begin only after qualification. Every row stores its contemporaneous Event, Evidence and immutable Story Now. The table is presentation over the source-owned ledger."
export const string TT_STORY_TABLE_MODE = "Expanded shows # · Time · Event · Evidence · Story Now. Compact shows # · Time · Event · Story Now. Long prose is manually wrapped inside fixed-width columns so all semantic columns remain visible. Evidence and Story Now remain separate immutable ledger fields."
export const string TT_STORY_TIMEZONE_MODE = "Story-table display timezone. Exchange is the default. Choices mirror TradingView's human-readable timezone menu. Named locations are mapped internally to IANA timezones so daylight-saving changes are handled by the timezone engine. Pine cannot read the chart UI's selected timezone automatically."
export const string TT_STORY_TABLE_POSITION = "Screen position of the MA Story table. Bottom Center is the default narrative workspace."
export const string TT_STORY_TABLE_TEXT_SIZE = "Text size used by the MA Story table only."
export const string TT_SECONDARY_MICRO_AUCTION_COLOR = "Presentation colour for containment-qualified SMA# boxes and tags. It has no primary-MA qualification authority."
export const string TT_BOUNDARY_MICRO_AUCTION_COLOR = "Presentation colour for confirmed BMA# boxes and tags. BMA# is a finite secondary auction class and has no persistent MA price-territory authority."
export const string TT_QUARTILE_TRANSPARENCY = "Transparency applied to displayed MA quartile lines. The 50% line is dashed; 25% and 75% are dotted."
export const string TT_SHOW_STATUS_TABLE = "Shows the compact XZ MAE operating table. OFF by default for a clean first load; enable it when you want live registry and source-authority diagnostics."
 
//==============================================================================
// STORY TABLE PRESENTATION — CALLER-RESOLVED COUNTS ONLY
//==============================================================================
 
//@function Formats the Story table scope/history summary from caller-resolved retention facts.
export storyViewText(
     string auditScope, bool historyComplete, int latestChapter, int expectedFormationChapters,
     int retainedFormationChapters, int firstRetainedChapter
 ) =>
    string result = ""
    if auditScope == "Full Story"
        if historyComplete
            result := latestChapter > 0 ?
                 "Full Story · F1–F" + str.tostring(expectedFormationChapters) + " · Ch 1–" + str.tostring(latestChapter) :
                 "Full Story · F1–F" + str.tostring(expectedFormationChapters)
        else if not na(firstRetainedChapter)
            result := "Partial Story · retained F " + str.tostring(retainedFormationChapters) + "/" + str.tostring(expectedFormationChapters) + " · Ch " + str.tostring(firstRetainedChapter) + "–" + str.tostring(latestChapter)
        else
            result := "Partial Story · retained F " + str.tostring(retainedFormationChapters) + "/" + str.tostring(expectedFormationChapters)
    else
        string focusName = auditScope == "Outside-Origin Focus" ? "Outside-Origin" : "Inside-Origin / Escape"
        result := "Chapter Focus · " + focusName + " · Formation retained"
        if not historyComplete and not na(firstRetainedChapter)
            result += " · Partial history Ch " + str.tostring(firstRetainedChapter) + "–" + str.tostring(latestChapter)
    result
 
//==============================================================================
// FORENSIC FORMATTERS — CALLER-RESOLVED FACTS ONLY
//==============================================================================
// The protected MAE source decides all identities, states, relationships and lifecycle facts.
// These functions only assemble user-visible text from those already-decided facts.
 
export auctionAuditTooltip(
     int auctionId, string relationship, string currentStoryEvent, string storySummary, string storyOriginSummary,
     float lower, float upper, int qualifyingSwingCount, int reactionCount,
     int outsideOriginCount, string deepestOutsideOrigin, string latestOutsideOrigin,
     int insideOriginProbeCount, int closeEscapeCount, int fboCount, int fullTraversalCount, int structuralEscapeCount,
     string latestTelemetry
 ) =>
    float width = upper - lower
    "XZ MAE · MA#" + str.tostring(auctionId) +
     "\nRelationship: " + relationship +
     "\nCurrent Story Event: " + currentStoryEvent +
     "\nStory Now: " + storySummary +
     "\nFormation: " + storyOriginSummary +
     "\n\nGEOMETRY" +
     "\nLower: " + str.tostring(lower, format.mintick) +
     "\n25%: " + str.tostring(lower + width * 0.25, format.mintick) +
     "\n50%: " + str.tostring(lower + width * 0.50, format.mintick) +
     "\n75%: " + str.tostring(lower + width * 0.75, format.mintick) +
     "\nUpper: " + str.tostring(upper, format.mintick) +
     "\nQualified By: " + str.tostring(qualifyingSwingCount) + " contained alternating Chop Swings" +
     "\n\nINTERACTION SUMMARY" +
     "\nReaction Episodes: " + str.tostring(reactionCount) +
     "\nOutside-Origin Interactions: " + str.tostring(outsideOriginCount) +
     "\nDeepest Outside-Origin Reach: " + deepestOutsideOrigin +
     "\nLatest Outside-Origin Event: " + latestOutsideOrigin +
     "\nInside-Origin Probes: " + str.tostring(insideOriginProbeCount) +
     "\nClose Escapes: " + str.tostring(closeEscapeCount) +
     "\nFBO Resolutions: " + str.tostring(fboCount) +
     "\nFull Traversals: " + str.tostring(fullTraversalCount) +
     "\nStructural Escapes: " + str.tostring(structuralEscapeCount) +
     "\n\nLATEST EVENT" +
     "\n" + latestTelemetry
 
export chapterTooltip(int auctionId, int chapter, string storyTitle, string evidence, string storyNow, string auditText) =>
    "XZ MAE · MA#" + str.tostring(auctionId) + " · Chapter " + str.tostring(chapter) +
     "\n" + storyTitle +
     "\nEvidence: " + evidence +
     "\nStory Now: " + storyNow +
     "\n\nAUDIT" +
     "\n" + auditText
 
export candidateAuditTooltip(
     int candidateId, string relationship, int swingCount, int minimumChopSwings,
     float lower, float upper, int failedBreakouts, bool escapeOpen, int escapeSide, string lastResolution
 ) =>
    string qualification = str.tostring(swingCount) + "/" + str.tostring(minimumChopSwings) + " contained alternating Chop Swings"
    string resolution = escapeOpen ? "Pending" : lastResolution
    string resolutionPath = ""
    if escapeOpen
        if escapeSide == 1
            resolutionPath :=
                 "Return close inside before structure establishes away → FBO / Re-engaged" +
                 "\nOutside HL → HH or qualifying bullish BOS above → Structural Failure"
        else if escapeSide == -1
            resolutionPath :=
                 "Return close inside before structure establishes away → FBO / Re-engaged" +
                 "\nOutside LH → LL or qualifying bearish BOS below → Structural Failure"
    else
        resolutionPath := "If a later escape occurs, MAE waits for FBO/re-engagement or structural establishment away."
 
    "XZ MAE · C#" + str.tostring(candidateId) +
     "\nState: " + relationship +
     "\nQualification: " + qualification +
     "\nGeometry: Fixed · " + str.tostring(lower, format.mintick) + " → " + str.tostring(upper, format.mintick) +
     "\nCandidate FBOs: " + str.tostring(failedBreakouts) +
     "\nResolution: " + resolution +
     "\n\nWHY IT REMAINS ACTIVE" +
     "\nA close outside does not invalidate a Candidate. Its fixed geometry remains under observation while the escape is unresolved." +
     "\n\nWHAT RESOLVES IT" +
     "\n" + resolutionPath +
     "\nOutside Chop Swing alone → non-terminal evidence" +
     "\n\nOnly a qualified MA# becomes durable historical auction memory."
 
export secondaryAuditTooltip(
     int candidateId, int containedCloseCount, int containmentThreshold, bool containmentQualified,
     float lower, float upper, string relationship,
     bool defeatConfirmed, bool escapeOpen, int escapeSide, int escapeCloseCount, int defeatThreshold, int firstOutsideSide,
     int failedBreakouts, string primaryOutcome, string lastResolution
 ) =>
    string defeatText = defeatConfirmed ?
         "Confirmed " + (firstOutsideSide == 1 ? "Above" : "Below") + " · threshold " + str.tostring(defeatThreshold) + " consecutive same-side outside closes" :
         escapeOpen ? "Developing " + (escapeSide == 1 ? "Above" : "Below") + " · " + str.tostring(escapeCloseCount) + "/" + str.tostring(defeatThreshold) + " consecutive same-side outside closes" : "None"
 
    "XZ MAE · SMA#" + str.tostring(candidateId) +
     "\nOrigin: F1–F2 opposing Chop pair" +
     "\nContainment Qualification: " + str.tostring(containedCloseCount) + "/" + str.tostring(containmentThreshold) + " contained Micro Source closes" +
     "\nQualified: " + (containmentQualified ? "Yes" : "No") +
     "\nGeometry Source: Original F1–F2 opposing Chop pair" +
     "\nGeometry: Fixed · " + str.tostring(lower, format.mintick) + " → " + str.tostring(upper, format.mintick) +
     "\nRelationship: " + relationship +
     "\nDefeat: " + defeatText +
     "\nSMA-style FBOs: " + str.tostring(failedBreakouts) +
     "\nMA Conjunction: " + primaryOutcome +
     "\nLatest SMA Resolution: " + lastResolution +
     "\n\nTEST DOCTRINE" +
     "\nF1–F2 fixes the immutable hypothesis geometry and historical origin. Confirmed SMA# identity requires " + str.tostring(containmentThreshold) + " contained Micro Source closes inside/on that band; the F2 confirmation close counts when contained." +
     "\nEvery admissible F1–F2 hypothesis retains its original F1 while pending. The earliest still-live pending hypothesis has first qualification priority; later ready hypotheses wait without moving their left edge or losing accumulated containment." +
     "\nIf the earlier pending hypothesis is defeated before qualification, the next retained ready hypothesis may qualify from its original F1. A hypothesis whose original F1 overlaps an older qualified SMA interval can never qualify. Once qualified, SMA# may exist inside MA# geometry, and the same fixed geometry may simultaneously carry SMA# and MA# identity." +
     "\nMA qualification never terminates or suspends the SMA# lifecycle. Later F3/F4 evidence can mature the originating C# but never moves the original F1–F2 boundaries." +
     "\nDefeat requires " + str.tostring(defeatThreshold) + " consecutive Micro Source closes outside on the same side. A return inside before threshold is an SMA-style FBO; an opposite-side outside close restarts the count from 1 on that side." +
     "\nOn confirmed Defeat, the visible right edge is the open of the FIRST outside candle in the qualifying run; the threshold-reaching outside close is the exact confirmation event." +
     "\nThe underlying C# / MA path is independent. An MA# may persist after SMA# Defeat, while a defeated SMA# never reopens or re-extends."
 
export boundaryAuditTooltip(
     int bmaId, string shelfSideText, string opposingCode, int originPivotCount,
     float shelfPrice, float originTolerance, float opposingSwingPrice, float lower, float upper, string relationship,
     bool defeatConfirmed, bool escapeOpen, int escapeSide, int escapeCloseCount, int defeatThreshold, int firstOutsideSide,
     int failedBreakouts, string lastResolution
 ) =>
    string defeatText = defeatConfirmed ?
         "Confirmed " + (firstOutsideSide == 1 ? "Above" : "Below") + " · threshold " + str.tostring(defeatThreshold) + " consecutive same-side outside closes" :
         escapeOpen ? "Developing " + (escapeSide == 1 ? "Above" : "Below") + " · " + str.tostring(escapeCloseCount) + "/" + str.tostring(defeatThreshold) + " consecutive same-side outside closes" : "None"
 
    "XZ MAE · BMA#" + str.tostring(bmaId) +
     "\nOrigin: " + shelfSideText +
     "\nShelf Pivots: " + str.tostring(originPivotCount) + " near-equal same-side XZ close pivots" +
     "\nShelf Price: " + str.tostring(shelfPrice, format.mintick) + " · frozen after P2" +
     "\nShelf Origin Tolerance: ±" + str.tostring(originTolerance, format.mintick) +
     "\nOpposing Boundary: " + opposingCode + " @ " + str.tostring(opposingSwingPrice, format.mintick) +
     "\nGeometry: Fixed · " + str.tostring(lower, format.mintick) + " → " + str.tostring(upper, format.mintick) +
     "\nRelationship: " + relationship +
     "\nDefeat: " + defeatText +
     "\nBMA-style FBOs: " + str.tostring(failedBreakouts) +
     "\nLatest BMA Resolution: " + lastResolution +
     "\n\nBMA DOCTRINE" +
     "\nP1 + P2 establish and freeze the shelf; later near-equal pivots only reinforce that same frozen boundary." +
     "\nOnly an opposing Chop Swing confirmed AFTER shelf establishment can freeze the second boundary and confirm BMA#. An opposing Trend Swing first disqualifies the precursor because rejection resolved into trend away rather than bounded auction." +
     "\nThe BMA left edge remains the original P1. Geometry never expands after birth." +
     "\nBMA# may nest inside MA# and may overlap/coexist with SMA#; neither finite secondary class suppresses the other." +
     "\nDefeat uses the same " + str.tostring(defeatThreshold) + "-close consecutive same-side outside-close rule as SMA#. The BMA birth candle participates immediately." +
     "\nOn confirmed Defeat, the visible right edge is the open of the FIRST outside candle in the successful run; defeated BMA# never reopens or re-extends."
 
 
 
//==============================================================================
// MAE PRESENTATION DECODERS — CALLER-RESOLVED STATE ONLY
//==============================================================================
// These functions translate facts already decided by protected MAE into user-visible text.
// They do not create state, qualify auctions, select Story events, rank evidence or mutate lifecycle.
 
export sideText(int side) =>
    side == 1 ? "Upper" : side == -1 ? "Lower" : "Inside"
 
export directionText(int side) =>
    side == 1 ? "Bullish" : side == -1 ? "Bearish" : "Neutral"
 
export establishedRelationshipText(int side) =>
    side == 1 ? "Established Above" : side == -1 ? "Established Below" : "Not Established"
 
export outsideLocationText(int side) =>
    side == 1 ? "Above" : side == -1 ? "Below" : "Inside"
 
export auditCoordinateText(float coordinate) =>
    na(coordinate) ? "—" :
     coordinate > 100.0 ? "Above · " + str.tostring(coordinate - 100.0, "#.0") + "% beyond MA" :
     coordinate < 0.0 ? "Below · " + str.tostring(math.abs(coordinate), "#.0") + "% beyond MA" :
     "Inside · " + str.tostring(coordinate, "#.##") + "%"
 
export narrativeCoordinateText(float coordinate) =>
    na(coordinate) ? "an unavailable coordinate" :
     coordinate > 100.0 ? str.tostring(coordinate - 100.0, "#.0") + "% of MA width beyond the upper boundary" :
     coordinate < 0.0 ? str.tostring(math.abs(coordinate), "#.0") + "% of MA width beyond the lower boundary" :
     "inside at the " + str.tostring(coordinate, "#.##") + "% MA coordinate"
 
export auctionZoneTextById(int zoneId) =>
    zoneId == 0 ? "Lower Boundary Zone" :
     zoneId == 1 ? "Lower Interior Zone" :
     zoneId == 2 ? "Upper Interior Zone" :
     zoneId == 3 ? "Upper Boundary Zone" : ""
 
export auctionQuartileCodeById(int zoneId) =>
    zoneId == 0 ? "Q1" : zoneId == 1 ? "Q2" : zoneId == 2 ? "Q3" : zoneId == 3 ? "Q4" : ""
 
export auctionZoneNarrativeLabelById(int zoneId) =>
    string quartile = auctionQuartileCodeById(zoneId)
    string zone = auctionZoneTextById(zoneId)
    str.length(quartile) > 0 and str.length(zone) > 0 ? quartile + " (" + zone + ")" : zone
 
export probeInsideCoordinateText(float coordinate) =>
    "the " + str.tostring(coordinate, "#.##") + "% MA coordinate"
 
export swingCode(int family, int side) =>
    family == 1 ? (side == 1 ? "TSH" : side == -1 ? "TSL" : "Trend Swing") :
     family == 2 ? (side == 1 ? "CSH" : side == -1 ? "CSL" : "Chop Swing") :
     "None"
 
export boundaryShelfTypeText(int side) =>
    side == 1 ? "Upper Boundary Shelf" : side == -1 ? "Lower Boundary Shelf" : "Boundary Shelf"
 
export boundaryRelationshipText(bool confirmed, bool disqualified, bool defeatConfirmed, int firstOutsideSide, bool escapeOpen, int escapeSide) =>
    not confirmed ? (disqualified ? "Precursor Disqualified" : "Shelf Under Scrutiny") :
     defeatConfirmed ? "Defeated " + (firstOutsideSide == 1 ? "Above" : "Below") :
     escapeOpen ? "Defeat Developing " + (escapeSide == 1 ? "Above" : "Below") :
     "Active Inside"
 
export auctionRelationshipText(bool overcome, int overcomeSide, bool escapeOpen, int escapeSide, int state, int breakoutSide) =>
    overcome ? establishedRelationshipText(overcomeSide) :
     escapeOpen ? "Close Escape Developing " + (escapeSide == 1 ? "Above" : "Below") :
     state == 1 ? "Auction Active" :
     breakoutSide == 1 ? "Departed Above" :
     breakoutSide == -1 ? "Departed Below" :
     "Departed"
 
export candidateRelationshipText(bool escapeOpen, int escapeSide, int failedBreakouts) =>
    escapeOpen ? (escapeSide == 1 ? "Escape Developing Above" : "Escape Developing Below") :
     failedBreakouts > 0 ? "Re-engaged · FBO " + str.tostring(failedBreakouts) :
     "Developing Inside"
 
export secondaryRelationshipText(bool containmentQualified, bool defeatConfirmed, int firstOutsideSide, bool escapeOpen, int escapeSide) =>
    not containmentQualified ? "Qualification Pending" :
     defeatConfirmed ? "Defeated " + (firstOutsideSide == 1 ? "Above" : "Below") :
     escapeOpen ? "Defeat Developing " + (escapeSide == 1 ? "Above" : "Below") :
     "Active Inside"
 
export storyTableColumnWidth(string mode, int column) =>
    mode == "Expanded" ?
         (column == 0 ? 3.0 : column == 1 ? 7.0 : column == 2 ? 16.0 : column == 3 ? 33.0 : 39.0) :
         (column == 0 ? 3.0 : column == 1 ? 8.0 : column == 2 ? 20.0 : 67.0)
 
export liveCloseLocationText(int side) =>
    side == 1 ? "Above" : side == -1 ? "Below" : "Inside"
 
export narrativeFocusModeText(string mode) =>
    mode == "Manual MA#" ? "Manual" : "Auto · Most Recent"
 
 
//==============================================================================
// STATUS COPY — CALLER-RESOLVED COUNTS / THRESHOLDS ONLY
//==============================================================================
 
export secondaryStatusTip(int containmentThreshold, int defeatThreshold) =>
    "F1–F2 fixes and retains the SMA hypothesis geometry/original F1. Confirmed SMA# identity requires " + str.tostring(containmentThreshold) + " contained Micro Source closes inside/on that fixed band; the F2 confirmation close counts when contained. Pending hypotheses retain their original F1 while qualification is arbitrated chronologically. Hypotheses defeated before qualification are not displayed or counted as SMA#. Defeat after qualification requires " + str.tostring(defeatThreshold) + " consecutive same-side source closes outside. MA# and SMA# may coexist on identical geometry and continue under independent lifecycle rules."
 
export boundaryStatusTip(int defeatThreshold) =>
    "P1 + P2 establish and freeze a same-side shelf. The first valid opposing Chop Swing confirmed AFTER shelf establishment freezes the second boundary and immediately confirms BMA#. An opposing Trend Swing first disqualifies the precursor. Confirmed BMA# uses the same " + str.tostring(defeatThreshold) + "-close consecutive same-side outside-close Defeat/FBO lifecycle as SMA#, including birth-candle participation."
 
 
//==============================================================================
// STORY TABLE RENDERING — PRESENTATION ONLY
//==============================================================================
// Caller decides focus, event admission, ordering, Evidence and Story Now. These helpers only
// render caller-resolved text through the shared XZ table contract.
 
export renderStoryHeader(
     table id, string mode, string tableTextSize,
     string focusText, string focusModeText, string viewText, string relationship,
     color accentColor, color textColor, color backgroundColor, color headerBackground
 ) =>
    string sz = xztbl.resolveTextSize(tableTextSize)
    xztbl.cellWithWidth(id, 0, 0, "XZ MAE STORY", storyTableColumnWidth(mode, 0), accentColor, sz, text.align_left, backgroundColor, "")
    xztbl.cellWithWidth(id, 1, 0, focusText, storyTableColumnWidth(mode, 1), textColor, sz, text.align_left, backgroundColor, "")
    xztbl.cellWithWidth(id, 2, 0, focusModeText, storyTableColumnWidth(mode, 2), textColor, sz, text.align_left, backgroundColor, "")
    if mode == "Expanded"
        xztbl.cellWithWidth(id, 3, 0, viewText, storyTableColumnWidth(mode, 3), textColor, sz, text.align_left, backgroundColor, "")
        xztbl.cellWithWidth(id, 4, 0, relationship, storyTableColumnWidth(mode, 4), textColor, sz, text.align_left, backgroundColor, "")
    else
        xztbl.cellWithWidth(id, 3, 0, relationship + " · " + viewText, storyTableColumnWidth(mode, 3), textColor, sz, text.align_left, backgroundColor, "")
 
    xztbl.cellWithWidth(id, 0, 1, "#", storyTableColumnWidth(mode, 0), textColor, sz, text.align_center, headerBackground, "")
    xztbl.cellWithWidth(id, 1, 1, "Time", storyTableColumnWidth(mode, 1), textColor, sz, text.align_left, headerBackground, "")
    xztbl.cellWithWidth(id, 2, 1, "Event", storyTableColumnWidth(mode, 2), textColor, sz, text.align_left, headerBackground, "")
    if mode == "Expanded"
        xztbl.cellWithWidth(id, 3, 1, "Evidence", storyTableColumnWidth(mode, 3), textColor, sz, text.align_left, headerBackground, "")
        xztbl.cellWithWidth(id, 4, 1, "Story Now", storyTableColumnWidth(mode, 4), textColor, sz, text.align_left, headerBackground, "")
    else
        xztbl.cellWithWidth(id, 3, 1, "Story Now", storyTableColumnWidth(mode, 3), textColor, sz, text.align_left, headerBackground, "")
    true
 
export renderStoryMessageRow(table id, int row, string mode, string tableTextSize, string message, color mutedColor) =>
    string sz = xztbl.resolveTextSize(tableTextSize)
    xztbl.cellWithWidth(id, 0, row, "—", storyTableColumnWidth(mode, 0), mutedColor, sz, text.align_center, na, "")
    xztbl.cellWithWidth(id, 1, row, message, storyTableColumnWidth(mode, 1), mutedColor, sz, text.align_left, na, "")
    true
 
export renderStoryChapterRow(
     table id, int row, string mode, string tableTextSize,
     string markerText, string timeText, string eventText, string evidenceText, string storyNowText,
     color accentColor, color textColor
 ) =>
    string sz = xztbl.resolveTextSize(tableTextSize)
    xztbl.cellWithWidth(id, 0, row, markerText, storyTableColumnWidth(mode, 0), accentColor, sz, text.align_center, na, "")
    xztbl.cellWithWidth(id, 1, row, timeText, storyTableColumnWidth(mode, 1), textColor, sz, text.align_left, na, "")
    xztbl.cellWithWidth(id, 2, row, xztbl.wrapWords(eventText, mode == "Expanded" ? 44 : 52), storyTableColumnWidth(mode, 2), textColor, sz, text.align_left, na, eventText)
    if mode == "Expanded"
        xztbl.cellWithWidth(id, 3, row, xztbl.wrapWordsNatural(evidenceText, 58, 96), storyTableColumnWidth(mode, 3), textColor, sz, text.align_left, na, evidenceText)
        xztbl.cellWithWidth(id, 4, row, xztbl.wrapWordsNatural(storyNowText, 64, 108), storyTableColumnWidth(mode, 4), textColor, sz, text.align_left, na, storyNowText)
    else
        xztbl.cellWithWidth(id, 3, row, xztbl.wrapWordsNatural(storyNowText, 76, 132), storyTableColumnWidth(mode, 3), textColor, sz, text.align_left, na, storyNowText)
    true
 
export liveStoryTooltip(int auctionId, string evidenceText, string storyNowText) =>
    "LIVE · Developing" +
     "\nMutable current read for MA#" + str.tostring(auctionId) +
     "\nUpdates only on completed Micro Source candles." +
     "\nNot a confirmed Chapter and not archived." +
     "\n\nEvidence: " + evidenceText +
     "\nStory Now: " + storyNowText
 
export renderStoryLiveRow(
     table id, int row, string mode, string tableTextSize,
     string liveTime, string eventText, string evidenceText, string storyNowText, string liveTip,
     color accentColor, color textColor, color backgroundColor
 ) =>
    string sz = xztbl.resolveTextSize(tableTextSize)
    xztbl.cellWithWidth(id, 0, row, "LIVE", storyTableColumnWidth(mode, 0), accentColor, sz, text.align_center, backgroundColor, liveTip)
    xztbl.cellWithWidth(id, 1, row, liveTime, storyTableColumnWidth(mode, 1), textColor, sz, text.align_left, backgroundColor, liveTip)
    xztbl.cellWithWidth(id, 2, row, xztbl.wrapWords(eventText, mode == "Expanded" ? 44 : 52), storyTableColumnWidth(mode, 2), accentColor, sz, text.align_left, backgroundColor, eventText)
    if mode == "Expanded"
        xztbl.cellWithWidth(id, 3, row, xztbl.wrapWordsNatural(evidenceText, 58, 96), storyTableColumnWidth(mode, 3), textColor, sz, text.align_left, backgroundColor, evidenceText)
        xztbl.cellWithWidth(id, 4, row, xztbl.wrapWordsNatural(storyNowText, 64, 108), storyTableColumnWidth(mode, 4), textColor, sz, text.align_left, backgroundColor, storyNowText)
    else
        xztbl.cellWithWidth(id, 3, row, xztbl.wrapWordsNatural(storyNowText, 76, 132), storyTableColumnWidth(mode, 3), textColor, sz, text.align_left, backgroundColor, storyNowText)
    true
 
 
//==============================================================================
// STATUS TABLE RENDERING — PRESENTATION ONLY
//==============================================================================
// Caller supplies all resolved state/count/value facts. This function owns only static row copy,
// table lifecycle and deterministic cell rendering. It cannot mutate MAE analytical state.
 
export renderStatusTable(
     table id, bool visible, string versionText,
     string microSourceText, string sourceModeText, string candidateSwingsText,
     string candidateStateText, string candidateStateTip,
     bool secondaryEnabled, int qualifiedSecondaryCount, color secondaryColor, int smaContainmentThreshold, int defeatThreshold,
     bool boundaryEnabled, int qualifiedBoundaryCount, color boundaryColor,
     int activeCount, color activeColor, int departedCount, color departedColor, int reactionedCount, color reactionColor,
     string latestMAText, string visibleAllocationText, string latestBehaviourText,
     color accentColor, color textColor, color backgroundColor, color lineColor
 ) =>
    table result = id
    if visible
        if na(result)
            result := xztbl.createStyled("top_right", 2, 13, backgroundColor, lineColor, true)
 
        float labelWidth = 35.0
        float valueWidth = 65.0
        string sz = size.normal
        string smaTip = secondaryStatusTip(smaContainmentThreshold, defeatThreshold)
        string bmaTip = boundaryStatusTip(defeatThreshold)
 
        xztbl.cellWithWidth(result, 0, 0, "XZ MAE", labelWidth, accentColor, sz, text.align_left, na, "")
        xztbl.cellWithWidth(result, 1, 0, versionText, valueWidth, textColor, sz, text.align_right, na, "")
        xztbl.cellWithWidth(result, 0, 1, "Micro Source", labelWidth, textColor, sz, text.align_left, na, "")
        xztbl.cellWithWidth(result, 1, 1, microSourceText, valueWidth, textColor, sz, text.align_left, na, "")
        xztbl.cellWithWidth(result, 0, 2, "Source Mode", labelWidth, textColor, sz, text.align_left, na, "")
        xztbl.cellWithWidth(result, 1, 2, sourceModeText, valueWidth, textColor, sz, text.align_left, na, "")
        xztbl.cellWithWidth(result, 0, 3, "Candidate Swings", labelWidth, textColor, sz, text.align_left, na, "")
        xztbl.cellWithWidth(result, 1, 3, candidateSwingsText, valueWidth, textColor, sz, text.align_left, na, "")
        xztbl.cellWithWidth(result, 0, 4, "Candidate State", labelWidth, textColor, sz, text.align_left, na, candidateStateTip)
        xztbl.cellWithWidth(result, 1, 4, candidateStateText, valueWidth, textColor, sz, text.align_left, na, candidateStateTip)
        xztbl.cellWithWidth(result, 0, 5, "Secondary Micro Auctions", labelWidth, textColor, sz, text.align_left, na, smaTip)
        xztbl.cellWithWidth(result, 1, 5, secondaryEnabled ? str.tostring(qualifiedSecondaryCount) : "Off", valueWidth, secondaryColor, sz, text.align_left, na, smaTip)
        xztbl.cellWithWidth(result, 0, 6, "Boundary Micro Auctions", labelWidth, textColor, sz, text.align_left, na, bmaTip)
        xztbl.cellWithWidth(result, 1, 6, boundaryEnabled ? str.tostring(qualifiedBoundaryCount) : "Off", valueWidth, boundaryColor, sz, text.align_left, na, bmaTip)
        xztbl.cellWithWidth(result, 0, 7, "Active", labelWidth, textColor, sz, text.align_left, na, "")
        xztbl.cellWithWidth(result, 1, 7, str.tostring(activeCount), valueWidth, activeColor, sz, text.align_left, na, "")
        xztbl.cellWithWidth(result, 0, 8, "Departed", labelWidth, textColor, sz, text.align_left, na, "")
        xztbl.cellWithWidth(result, 1, 8, str.tostring(departedCount), valueWidth, departedColor, sz, text.align_left, na, "")
        xztbl.cellWithWidth(result, 0, 9, "Reactioned", labelWidth, textColor, sz, text.align_left, na, "")
        xztbl.cellWithWidth(result, 1, 9, str.tostring(reactionedCount), valueWidth, reactionColor, sz, text.align_left, na, "")
        xztbl.cellWithWidth(result, 0, 10, "Latest MA", labelWidth, textColor, sz, text.align_left, na, "")
        xztbl.cellWithWidth(result, 1, 10, latestMAText, valueWidth, textColor, sz, text.align_left, na, "")
        xztbl.cellWithWidth(result, 0, 11, "Visible Allocation", labelWidth, textColor, sz, text.align_left, na, "")
        xztbl.cellWithWidth(result, 1, 11, visibleAllocationText, valueWidth, textColor, sz, text.align_left, na, "")
        xztbl.cellWithWidth(result, 0, 12, "Latest Behaviour", labelWidth, textColor, sz, text.align_left, na, "")
        xztbl.cellWithWidth(result, 1, 12, latestBehaviourText, valueWidth, textColor, sz, text.align_left, na, "")
    else if not na(result)
        xztbl.deleteTable(result)
        result := na
    result

← 返回列表