本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
// This source code is subject to the terms of the Mozilla Public License 2.0
// https://mozilla.org/MPL/2.0/
// Original indicator/presentation: Keyvan Khodakhah
//@description View-only renderers extracted from K1 Swing v14.31 Visionary R3.2. No signal, trading, target, or alert authority. Preserves the original panel colors, text, dimensions, and table contents.
library("ITBFVisionaryView", overlay=true, dynamic_requests=false)
// PHASE 1: This library is presentation ONLY.
// The importing main indicator owns table IDs, table merge topology, barstate
// invocation, all inputs, signal lifecycle, K1 notifications, and all plots.
// No global state, inputs, request.*(), plots, or alert() calls exist here.
//@type Realtime preview table inputs. Must be constructed by the main indicator.
export type LiveTablePacket
bool showLivePreview
bool liveEval
int livePreviewState
string liveMode
int livePersistCount
export type SignalPanelPacket
bool showSignalTable
bool compactPanel
int mainSignalState
bool activePlan
int planDir
int planState
float planEntry
float planSL
float planT1
float planT2
int planStartBar
bool t1Seen
int lastResultCode
int lastResultDir
int lastSignalDir
string lastSignalGrade
int lastSignalTime
string lastT1Source
string lastT2Source
float lastSignalT2R
bool effectiveCap
float practicalT1R
bool showLivePreview
bool showLiveWatchInPanel
bool liveEval
int livePreviewState
int trackedSignalDir
int activeSequentialCode
int protectedDir
float mfeR
float maeR
float labelWidth
float signalWidth
float bodyValueWidth
float titleWidth
float bodyHeight
f_v14291_tl_dir_text(int _d) => _d == 1 ? "BUY" : _d == -1 ? "SELL" : "NONE"
f_v14291_tl_state_text(int _s, bool _compact) =>
switch _s
1 => "OPEN"
2 => _compact ? "T1 HIT" : "T1 HIT · REMAINDER OPEN"
3 => _compact ? "T2 DONE" : "TARGET COMPLETE · NO ACTIVE PLAN"
4 => _compact ? "FLAT" : "FLAT · NO ACTIVE PLAN"
5 => _compact ? "CONFLICT" : "CONFLICT · NO ACTIVE PLAN"
7 => _compact ? "INVALID" : "INVALID PLAN GEOMETRY"
=> _compact ? "NO PLAN" : "NO ACTIVE PLAN"
f_v14291_tl_result_text(int _code, int _d, bool _compact) =>
string _dir = f_v14291_tl_dir_text(_d)
switch _code
3 => _compact ? _dir + " · T2" : _dir + " · T2 COMPLETE"
4 => _compact ? _dir + " · INV" : _dir + " · INVALIDATED"
5 => _compact ? _dir + " · CONFLICT" : _dir + " · SAME-BAR CONFLICT"
6 => _compact ? _dir + " · SUPER" : _dir + " · SUPERSEDED"
7 => _compact ? _dir + " · BAD PLAN" : _dir + " · INVALID GEOMETRY"
=> "—"
//@function Draw the exact 6-row amber LIVE warning mini-table into the existing table ID.
//@param _tbl The existing 2-column, 6-row table allocated by the parent indicator.
//@param _p Original LIVE preview display packet.
export renderLiveTable(table _tbl, LiveTablePacket _p) =>
table.clear(_tbl, 0, 0, 1, 5)
bool _lR4Visible = _p.showLivePreview and _p.liveEval and math.abs(_p.livePreviewState) == 2
if _lR4Visible
bool _lR4Buy = _p.livePreviewState == 2
bool _lR4Beta = timeframe.in_seconds(timeframe.period) == 28800
int _lR4Required = _p.liveMode == "High Confidence" ? 4 : 2
int _lR4SecondsToClose = int(math.ceil(math.max(0.0, (time_close - timenow) / 1000.0)))
int _lR4Hours = int(math.floor(_lR4SecondsToClose / 3600))
int _lR4Minutes = int(math.floor((_lR4SecondsToClose % 3600) / 60))
int _lR4Seconds = _lR4SecondsToClose % 60
string _lR4HourTxt = _lR4Hours < 10 ? "0" + str.tostring(_lR4Hours) : str.tostring(_lR4Hours)
string _lR4MinuteTxt = _lR4Minutes < 10 ? "0" + str.tostring(_lR4Minutes) : str.tostring(_lR4Minutes)
string _lR4SecondTxt = _lR4Seconds < 10 ? "0" + str.tostring(_lR4Seconds) : str.tostring(_lR4Seconds)
string _lR4Countdown = _lR4HourTxt + ":" + _lR4MinuteTxt + ":" + _lR4SecondTxt
string _lR4Title = "LIVE SIGNAL" + (_lR4Beta ? " · 8H BETA" : "")
string _lR4Direction = _lR4Buy ? "BUY" : "SELL"
color _lR4HeaderBg = color.new(color.orange, 42)
color _lR4BodyBg = color.new(color.orange, 82)
color _lR4WarnBg = color.new(color.orange, 66)
table.cell(_tbl, 0, 0, _lR4Title, text_color=color.white, text_size=size.small, bgcolor=_lR4HeaderBg, width=7.0, height=1.5)
table.cell(_tbl, 0, 1, "Direction", text_color=color.silver, text_size=size.tiny, bgcolor=_lR4BodyBg, width=6.0, height=1.35)
table.cell(_tbl, 1, 1, _lR4Direction, text_color=color.orange, text_size=size.small, bgcolor=_lR4BodyBg, width=7.0, height=1.35)
table.cell(_tbl, 0, 2, "UNCONFIRMED — BAR OPEN", text_color=color.orange, text_size=size.small, bgcolor=_lR4BodyBg, width=7.0, height=1.45)
table.cell(_tbl, 0, 3, "Closes in", text_color=color.silver, text_size=size.tiny, bgcolor=_lR4BodyBg, width=6.0, height=1.30)
table.cell(_tbl, 1, 3, _lR4Countdown, text_color=color.white, text_size=size.tiny, bgcolor=_lR4BodyBg, width=7.0, height=1.30)
table.cell(_tbl, 0, 4, "Persistence", text_color=color.silver, text_size=size.tiny, bgcolor=_lR4BodyBg, width=6.0, height=1.30)
table.cell(_tbl, 1, 4, str.tostring(_p.livePersistCount) + "/" + str.tostring(_lR4Required), text_color=color.white, text_size=size.tiny, bgcolor=_lR4BodyBg, width=7.0, height=1.30)
table.cell(_tbl, 0, 5, "MAY CANCEL BEFORE CLOSE", text_color=color.black, text_size=size.tiny, bgcolor=_lR4WarnBg, width=7.0, height=1.35)
//@function Draw the exact 15-row Visionary R3.2 signal panel into the existing table ID.
//@param _tbl The existing 3-column, 15-row panel allocated by the parent indicator.
//@param _p Original Visionary display packet; values are determined by parent.
export renderSignalPanel(table _tbl, SignalPanelPacket _p) =>
if _p.showSignalTable
// Confirmed directional context remains persistent even after the current
// trade plan becomes terminal. This is intentionally separate from plan validity.
int _confirmedContextDir = _p.mainSignalState
// TL2 PANEL AUTHORITY FIX:
// The large header represents ACTIONABLE PLAN authority, not persistent context.
// When the plan is terminal/inactive, the header must never continue to say BUY/SELL.
bool _planActive = _p.activePlan
int _headerDir = _planActive ? _p.planDir : 0
bool _planComplete = not _planActive and _p.planState == 3
color _sigBg = _headerDir == 1 ? color.new(color.green, 4) : _headerDir == -1 ? color.new(color.red, 4) : _planComplete ? color.new(color.green, 34) : color.rgb(66, 77, 94)
string _sigTxt = _headerDir == 1 ? "BUY" : _headerDir == -1 ? "SELL" : _planComplete ? (_p.compactPanel ? "DONE" : "COMPLETE") : "FLAT"
string _timeTxt = na(_p.lastSignalTime) ? "—" : str.format_time(_p.lastSignalTime, _p.compactPanel ? "dd MMM HH:mm" : "dd MMM yyyy HH:mm")
// ACTIVE plan levels disappear after structural invalidation, T2 completion,
// conflict or invalid geometry. Frozen historical levels remain internal for
// alerts/history but are no longer presented as actionable current levels.
string _entryTxt = _planActive and not na(_p.planEntry) ? str.tostring(_p.planEntry, format.mintick) : "—"
string _stopTxt = _planActive and not na(_p.planSL) ? str.tostring(_p.planSL, format.mintick) : "—"
string _t1SourceTxt = _p.effectiveCap ? "STRUCT CAP" : _p.lastT1Source == "STRUCT-CAP" ? "STRUCT CAP" : _p.lastT1Source == "STRUCT" ? "STRUCT" : _p.lastT1Source == "R-FALLBACK" ? "R" : _p.lastT1Source
string _t1TxtDesktop = not _planActive or na(_p.planT1) ? "—" : str.tostring(_p.planT1, format.mintick) + " | " + str.tostring(_p.practicalT1R, "#.##") + "R | " + _t1SourceTxt + (_p.t1Seen ? " ✓" : "")
string _t1TxtCompact = not _planActive or na(_p.planT1) ? "—" : str.tostring(_p.planT1, format.mintick) + " | " + str.tostring(_p.practicalT1R, "#.##") + "R" + (_p.t1Seen ? " ✓" : "")
string _t1Txt = _p.compactPanel ? _t1TxtCompact : _t1TxtDesktop
string _t2SourceTxt = _p.lastT2Source == "STRUCT" ? "STRUCT" : _p.lastT2Source == "R-FALLBACK" ? "R" : _p.lastT2Source
string _t2TxtDesktop = not _planActive or na(_p.planT2) ? "—" : str.tostring(_p.planT2, format.mintick) + " | " + str.tostring(_p.lastSignalT2R, "#.##") + "R | " + _t2SourceTxt
string _t2TxtCompact = not _planActive or na(_p.planT2) ? "—" : str.tostring(_p.planT2, format.mintick) + " | " + str.tostring(_p.lastSignalT2R, "#.##") + "R"
string _t2Txt = _p.compactPanel ? _t2TxtCompact : _t2TxtDesktop
float _planRiskForDisplay = _planActive and not na(_p.planEntry) and not na(_p.planSL) ? math.max(math.abs(_p.planEntry - _p.planSL), syminfo.mintick) : na
float _curR = _planActive and not na(_planRiskForDisplay) and _planRiskForDisplay > 0 ? (close - _p.planEntry) * _p.planDir / _planRiskForDisplay : na
string _rTxt = na(_curR) ? "—" : str.tostring(_curR, "#.##") + "R"
int _ageBars = _planActive and not na(_p.planStartBar) ? bar_index - _p.planStartBar : na
string _ageTxt = na(_ageBars) ? "—" : _p.compactPanel ? str.tostring(_ageBars) + "b" : str.tostring(_ageBars) + (_ageBars == 1 ? " bar" : " bars")
string _planStateBase = f_v14291_tl_state_text(_p.planState, _p.compactPanel)
bool _liveBuyPanel = _p.showLivePreview and _p.liveEval and _p.livePreviewState == 2
bool _liveSellPanel = _p.showLivePreview and _p.liveEval and _p.livePreviewState == -2
bool _liveWatchPanel = _p.showLivePreview and _p.showLiveWatchInPanel and _p.liveEval and math.abs(_p.livePreviewState) == 1
string _liveSuffix = _liveBuyPanel ? (_p.compactPanel ? " | L-BUY" : " | LIVE BUY · PROVISIONAL") : _liveSellPanel ? (_p.compactPanel ? " | L-SELL" : " | LIVE SELL · PROVISIONAL") : _liveWatchPanel ? (_p.compactPanel ? " | WATCH" : " | LIVE WATCH · DEVELOPING") : ""
string _stateTxt = _planStateBase + _liveSuffix
color _stateCol = _p.planState == 3 ? color.lime : (_p.planState == 4 or _p.planState == 5 or _p.planState == 7) ? color.orange : _p.planState == 2 ? color.lime : color.white
string _prevTxt = f_v14291_tl_result_text(_p.lastResultCode, _p.lastResultDir, _p.compactPanel)
color _prevCol = _p.lastResultCode == 3 ? color.lime : (_p.lastResultCode == 4 or _p.lastResultCode == 5 or _p.lastResultCode == 7) ? color.orange : color.white
string _titleTxt = "Swing Signals & Structure"
string _authorTxt = "KeyvanKh v14.30 · Visionary"
bool _v1418TrackedCurrent = _p.lastSignalDir != 0 and _p.trackedSignalDir == _p.lastSignalDir
int _v1418DisplayCode = _p.lastSignalDir != 0 and _p.protectedDir == _p.lastSignalDir ? 4 : _v1418TrackedCurrent ? _p.activeSequentialCode : 0
string _gradeTxt = _v1418DisplayCode == 1 ? "FAST · EARLY" : _v1418DisplayCode == 2 ? (_p.compactPanel ? "FAST · CONF" : "FAST · CONFIRMED") : _v1418DisplayCode == 3 ? (_p.compactPanel ? "QUAL · ALIGNED" : "QUALITY · ALIGNED") : _v1418DisplayCode == 4 ? (_p.compactPanel ? "HARD · EST." : "HARD · ESTABLISHED") : _p.lastSignalGrade
color _gradeCol = _v1418DisplayCode == 1 ? color.aqua : (_v1418DisplayCode == 2 or _v1418DisplayCode == 3 or _v1418DisplayCode == 4) ? color.lime : _p.lastSignalGrade == "QUALITY" ? color.lime : color.white
// With no active plan, the grade belongs to persistent directional CONTEXT,
// not to an actionable trade instruction. Show that explicitly in the panel.
string _contextDirTxt = _confirmedContextDir == 1 ? "BUY" : _confirmedContextDir == -1 ? "SELL" : "—"
string _contextAndGradeTxt = _confirmedContextDir == 0 ? _gradeTxt : _contextDirTxt + " · " + _gradeTxt
string _gradeDisplayTxt = _planActive ? _gradeTxt : _contextAndGradeTxt
string _labelGrade = _planActive ? (_p.compactPanel ? "Grade" : "Signal Grade") : (_p.compactPanel ? "Context" : "Confirmed Context")
string _labelTime = _planActive ? "Time" : (_p.compactPanel ? "Ctx Time" : "Context Time")
string _labelStop = _p.compactPanel ? "INV" : "Invalidation"
string _labelCurrent = _p.compactPanel ? "Now" : "Current"
string _labelCurrentR = _p.compactPanel ? "R" : "Current R"
string _labelBestR = _p.compactPanel ? "Best" : "Best R"
string _labelWorstR = _p.compactPanel ? "Worst" : "Worst R"
string _labelPrev = _p.compactPanel ? "Last" : "Last Plan Result"
string _currentTxt = str.tostring(close, format.mintick)
string _mfeTxt = _planActive ? str.tostring(_p.mfeR, "#.##") + "R" : "—"
string _maeTxt = _planActive ? str.tostring(_p.maeR, "#.##") + "R" : "—"
string _headerSize = _p.compactPanel ? size.tiny : size.normal
string _authorSize = _p.compactPanel ? size.tiny : size.small
string _signalSize = _p.compactPanel ? size.small : size.large
string _bodySize = _p.compactPanel ? size.tiny : size.small
int _bodyStart = _p.compactPanel ? 1 : 2
if _p.compactPanel
// Mobile header: branding + BUY/SELL only. Omits the long product title to save space.
table.cell(_tbl, 0, 0, _authorTxt, text_color=color.white, bgcolor=color.rgb(28, 38, 52), text_size=_authorSize, width=_p.titleWidth)
table.cell(_tbl, 2, 0, _sigTxt, text_color=color.white, bgcolor=_sigBg, text_size=_signalSize, width=_p.signalWidth)
else
table.cell(_tbl, 0, 0, _titleTxt, text_color=color.white, bgcolor=color.rgb(28, 38, 52), text_size=_headerSize, width=_p.titleWidth)
table.cell(_tbl, 0, 1, _authorTxt, text_color=color.rgb(202, 211, 224), bgcolor=color.rgb(23, 31, 43), text_size=_authorSize, width=_p.titleWidth)
table.cell(_tbl, 2, 0, _sigTxt, text_color=color.white, bgcolor=_sigBg, text_size=_signalSize, width=_p.signalWidth)
table.cell(_tbl, 0, _bodyStart + 0, _labelTime, text_color=color.rgb(170, 181, 196), bgcolor=color.rgb(38, 47, 61), text_size=_bodySize, width=_p.labelWidth, height=_p.bodyHeight)
table.cell(_tbl, 1, _bodyStart + 0, _timeTxt, text_color=color.white, bgcolor=color.rgb(20, 27, 37), text_size=_bodySize, width=_p.bodyValueWidth, height=_p.bodyHeight)
table.cell(_tbl, 0, _bodyStart + 1, _labelGrade, text_color=color.rgb(170, 181, 196), bgcolor=color.rgb(38, 47, 61), text_size=_bodySize, width=_p.labelWidth, height=_p.bodyHeight)
table.cell(_tbl, 1, _bodyStart + 1, _gradeDisplayTxt, text_color=_gradeCol, bgcolor=color.new(_gradeCol, 88), text_size=_bodySize, width=_p.bodyValueWidth, height=_p.bodyHeight)
color _inactiveKeyCol = color.rgb(150, 160, 174)
color _inactiveLabelBg = color.rgb(35, 43, 56)
color _inactiveValueBg = color.rgb(18, 25, 34)
color _slPanelCol = color.rgb(232, 174, 66)
color _entryKeyCol = _planActive ? color.rgb(170, 181, 196) : _inactiveKeyCol
color _entryValCol = _planActive ? (_headerDir == 1 ? color.lime : color.rgb(255, 120, 120)) : _inactiveKeyCol
color _entryLabelBg = _planActive ? color.new(_headerDir == 1 ? color.green : color.red, 90) : _inactiveLabelBg
color _entryValueBg = _planActive ? color.new(_headerDir == 1 ? color.green : color.red, 94) : _inactiveValueBg
color _stopKeyCol = _planActive ? _slPanelCol : _inactiveKeyCol
color _stopLabelBg = _planActive ? color.new(_slPanelCol, 86) : _inactiveLabelBg
color _stopValueBg = _planActive ? color.new(_slPanelCol, 92) : _inactiveValueBg
color _t1KeyCol = _planActive ? color.rgb(90, 220, 210) : _inactiveKeyCol
color _t1ValCol = _planActive ? (_p.t1Seen ? color.lime : color.rgb(90, 220, 210)) : _inactiveKeyCol
color _t1LabelBg = _planActive ? color.new(color.teal, 87) : _inactiveLabelBg
color _t1ValueBg = _planActive ? color.new(color.teal, 93) : _inactiveValueBg
color _t2KeyCol = _planActive ? color.aqua : _inactiveKeyCol
color _t2LabelBg = _planActive ? color.new(color.blue, 87) : _inactiveLabelBg
color _t2ValueBg = _planActive ? color.new(color.blue, 93) : _inactiveValueBg
table.cell(_tbl, 0, _bodyStart + 2, "Entry", text_color=_entryKeyCol, bgcolor=_entryLabelBg, text_size=_bodySize, width=_p.labelWidth, height=_p.bodyHeight)
table.cell(_tbl, 1, _bodyStart + 2, _entryTxt, text_color=_entryValCol, bgcolor=_entryValueBg, text_size=_bodySize, width=_p.bodyValueWidth, height=_p.bodyHeight)
table.cell(_tbl, 0, _bodyStart + 3, _labelStop, text_color=_stopKeyCol, bgcolor=_stopLabelBg, text_size=_bodySize, width=_p.labelWidth, height=_p.bodyHeight)
table.cell(_tbl, 1, _bodyStart + 3, _stopTxt, text_color=_stopKeyCol, bgcolor=_stopValueBg, text_size=_bodySize, width=_p.bodyValueWidth, height=_p.bodyHeight)
table.cell(_tbl, 0, _bodyStart + 4, "T1", text_color=_t1KeyCol, bgcolor=_t1LabelBg, text_size=_bodySize, width=_p.labelWidth, height=_p.bodyHeight)
table.cell(_tbl, 1, _bodyStart + 4, _t1Txt, text_color=_t1ValCol, bgcolor=_t1ValueBg, text_size=_bodySize, width=_p.bodyValueWidth, height=_p.bodyHeight)
table.cell(_tbl, 0, _bodyStart + 5, "T2", text_color=_t2KeyCol, bgcolor=_t2LabelBg, text_size=_bodySize, width=_p.labelWidth, height=_p.bodyHeight)
table.cell(_tbl, 1, _bodyStart + 5, _t2Txt, text_color=_t2KeyCol, bgcolor=_t2ValueBg, text_size=_bodySize, width=_p.bodyValueWidth, height=_p.bodyHeight)
table.cell(_tbl, 0, _bodyStart + 6, _labelCurrent, text_color=color.rgb(170, 181, 196), bgcolor=color.rgb(35, 43, 56), text_size=_bodySize, width=_p.labelWidth, height=_p.bodyHeight)
table.cell(_tbl, 1, _bodyStart + 6, _currentTxt, text_color=color.white, bgcolor=color.rgb(18, 25, 34), text_size=_bodySize, width=_p.bodyValueWidth, height=_p.bodyHeight)
table.cell(_tbl, 0, _bodyStart + 7, _p.compactPanel ? "Plan" : "Current Plan", text_color=color.rgb(170, 181, 196), bgcolor=color.rgb(35, 43, 56), text_size=_bodySize, width=_p.labelWidth, height=_p.bodyHeight)
table.cell(_tbl, 1, _bodyStart + 7, _stateTxt, text_color=_stateCol, bgcolor=color.new(_stateCol, 89), text_size=_bodySize, width=_p.bodyValueWidth, height=_p.bodyHeight)
table.cell(_tbl, 0, _bodyStart + 8, _labelCurrentR, text_color=color.rgb(170, 181, 196), bgcolor=color.rgb(35, 43, 56), text_size=_bodySize, width=_p.labelWidth, height=_p.bodyHeight)
table.cell(_tbl, 1, _bodyStart + 8, _rTxt, text_color=na(_curR) ? color.white : _curR >= 0 ? color.lime : color.orange, bgcolor=na(_curR) ? color.rgb(18, 25, 34) : color.new(_curR >= 0 ? color.green : color.orange, 91), text_size=_bodySize, width=_p.bodyValueWidth, height=_p.bodyHeight)
table.cell(_tbl, 0, _bodyStart + 9, _labelBestR, text_color=color.rgb(170, 181, 196), bgcolor=color.rgb(35, 43, 56), text_size=_bodySize, width=_p.labelWidth, height=_p.bodyHeight)
table.cell(_tbl, 1, _bodyStart + 9, _mfeTxt, text_color=_planActive ? color.lime : _inactiveKeyCol, bgcolor=_planActive ? color.new(color.green, 93) : _inactiveValueBg, text_size=_bodySize, width=_p.bodyValueWidth, height=_p.bodyHeight)
table.cell(_tbl, 0, _bodyStart + 10, _labelWorstR, text_color=color.rgb(170, 181, 196), bgcolor=color.rgb(35, 43, 56), text_size=_bodySize, width=_p.labelWidth, height=_p.bodyHeight)
table.cell(_tbl, 1, _bodyStart + 10, _maeTxt, text_color=_planActive ? color.orange : _inactiveKeyCol, bgcolor=_planActive ? color.new(color.orange, 93) : _inactiveValueBg, text_size=_bodySize, width=_p.bodyValueWidth, height=_p.bodyHeight)
table.cell(_tbl, 0, _bodyStart + 11, "Age", text_color=color.rgb(170, 181, 196), bgcolor=color.rgb(35, 43, 56), text_size=_bodySize, width=_p.labelWidth, height=_p.bodyHeight)
table.cell(_tbl, 1, _bodyStart + 11, _ageTxt, text_color=color.white, bgcolor=color.rgb(18, 25, 34), text_size=_bodySize, width=_p.bodyValueWidth, height=_p.bodyHeight)
table.cell(_tbl, 0, _bodyStart + 12, _labelPrev, text_color=color.rgb(190, 198, 210), bgcolor=color.rgb(42, 47, 58), text_size=_bodySize, width=_p.labelWidth, height=_p.bodyHeight)
table.cell(_tbl, 1, _bodyStart + 12, _prevTxt, text_color=_prevCol, bgcolor=color.new(_prevCol, 90), text_size=_bodySize, width=_p.bodyValueWidth, height=_p.bodyHeight)
else
table.clear(_tbl, 0, 0, 2, 14)
// Standalone structural-map status panel. No StructureEngine dependency is imported.
export type StructurePanelPacket
string chartTf
string primaryTf
string fartherTf
bool hasPrimary
bool hasFarther
int primaryKnownAt
int storedLocal
int storedPrimary
string method
string eventText
string regime
float nextResistance
float nextSupport
export renderStructurePanel(table id, StructurePanelPacket p, bool visible) =>
table.clear(id, 0, 0, 1, 7)
if visible
color bg = color.rgb(20, 27, 37)
color head = color.rgb(28, 38, 52)
table.cell(id, 0, 0, "ITBF STRUCTURE ENGINE", bgcolor=head, text_color=color.white, text_size=size.small)
table.cell(id, 1, 0, "v1.0 TEST", bgcolor=head, text_color=color.orange, text_size=size.small)
table.cell(id, 0, 1, "Chart / primary / farther", bgcolor=bg, text_color=color.silver, text_size=size.tiny)
table.cell(id, 1, 1, p.chartTf + " / " + p.primaryTf + " / " + p.fartherTf, bgcolor=bg, text_color=color.white, text_size=size.tiny)
table.cell(id, 0, 2, "Stored local / primary zones", bgcolor=bg, text_color=color.silver, text_size=size.tiny)
table.cell(id, 1, 2, str.tostring(p.storedLocal) + " / " + str.tostring(p.storedPrimary), bgcolor=bg, text_color=color.white, text_size=size.tiny)
table.cell(id, 0, 3, "Primary last known close", bgcolor=bg, text_color=color.silver, text_size=size.tiny)
table.cell(id, 1, 3, na(p.primaryKnownAt) ? "WARMUP / OFF" : str.format_time(p.primaryKnownAt, "dd MMM HH:mm", "UTC") + " UTC", bgcolor=bg, text_color=color.white, text_size=size.tiny)
table.cell(id, 0, 4, "Source status / model", bgcolor=bg, text_color=color.silver, text_size=size.tiny)
table.cell(id, 1, 4, (p.hasPrimary ? "PRIMARY READY" : "LOCAL ONLY / WARMUP") + (p.hasFarther ? " + MACRO" : "") + " / " + p.method, bgcolor=bg, text_color=color.white, text_size=size.tiny)
table.cell(id, 0, 5, "Nearest resistance / support", bgcolor=bg, text_color=color.silver, text_size=size.tiny)
table.cell(id, 1, 5, str.tostring(p.nextResistance, format.mintick) + " / " + str.tostring(p.nextSupport, format.mintick), bgcolor=bg, text_color=color.white, text_size=size.tiny)
table.cell(id, 0, 6, p.regime, bgcolor=bg, text_color=color.silver, text_size=size.tiny)
table.cell(id, 1, 6, p.eventText, bgcolor=bg, text_color=color.aqua, text_size=size.tiny)
table.cell(id, 0, 7, "STRUCTURAL CONTEXT", bgcolor=head, text_color=color.orange, text_size=size.tiny)
table.cell(id, 1, 7, "NOT A SWING BUY/SELL", bgcolor=head, text_color=color.orange, text_size=size.tiny)
true