//@version=6 indicator("KONATUS Atlas · Integrated Research 0.1.0", "K Atlas", overlay = true, max_bars_back = 2000) // Copyright (c) 2026 Kutty Stauder. Research software; no established trading edge. // Built from frozen Bearing 0.3.1 and Anatomy 0.1.0 engines. See SPEC.md. string atlasPolicy = input.string("Observe only", "Anatomy entry policy", options = ["Observe only", "Require direction", "Require organized direction"], group = "00 · Atlas", tooltip = "Observe preserves Bearing entries. Optional policies require valid Anatomy context, no Anatomy shock and matching direction. Organized also requires efficiency >= 0.55. Changes new entry candidates only; exits and queued fills remain active. These policies are unvalidated research rules.") string atlasCorner = input.string("Top right", "Dashboard position", options = ["Top right", "Top left", "Bottom right", "Bottom left"], group = "00 · Atlas") string atlasDensity = input.string("Compact", "Dashboard detail", options = ["Compact", "Detailed", "Hidden"], group = "00 · Atlas") string atlasFont = input.string("Small", "Dashboard text", options = ["Small", "Tiny", "Normal"], group = "00 · Atlas") bool atlasCandles = input.bool(true, "Color confirmed candles", group = "00 · Atlas") bool atlasAnatomyLine = input.bool(false, "Show Anatomy filtered price", group = "00 · Atlas") bool atlasEnvelope = input.bool(false, "Show Anatomy descriptive envelope", group = "00 · Atlas") bool atlasVwap = input.bool(false, "Show Anatomy calendar VWAP", group = "00 · Atlas") bool atlasScenario = input.bool(true, "Show Anatomy scenario boundary", group = "00 · Atlas") bool atlasEvents = input.bool(false, "Show Anatomy observation markers", group = "00 · Atlas") // === ANATOMY ENGINE === // One common measurement system; horizon is always measured in chart bars. int a_horizon = input.int(20, "Observation horizon (bars)", minval = 5, maxval = 200, group = "A · Understanding") string a_volumeInput = input.string("Auto", "Volume meaning", options = ["Auto", "Trade units", "Tick count", "Quote value", "Off"], group = "A · Volume and anchors", tooltip = "Auto follows feed metadata. Only declared trade units enable VWAP. Unknown volume stays unverified; tick activity is not traded quantity.") string a_anchorInput = input.string("Auto", "VWAP calendar anchor", options = ["Auto", "Day", "Week", "Month", "Year", "Off"], group = "A · Volume and anchors", tooltip = "Exchange-calendar boundaries on the bars loaded in the chart. Auto: intraday/day, daily/month, weekly or monthly/year. First partial anchor is withheld. This is not a regular-session filter.") a_f_number(float value) => na(value) ? "Unavailable" : str.tostring(value, "#.###") color a_upColor = color.rgb(38, 171, 145) color a_downColor = color.rgb(224, 102, 108) color a_cautionColor = color.rgb(213, 158, 66) color a_neutralColor = color.new(chart.fg_color, 25) bool a_timedChart = timeframe.isseconds or timeframe.isminutes or timeframe.isdaily or timeframe.isweekly or timeframe.ismonthly bool a_supported = chart.is_standard and a_timedChart bool a_validPrice = a_supported and not na(open) and not na(high) and not na(low) and not na(close) and low <= math.min(open, close) and high >= math.max(open, close) var int a_priceCount = 0 a_priceCount := a_validPrice ? a_priceCount + 1 : 0 bool a_previousValid = a_validPrice[1] float a_trueRange = a_validPrice ? (a_previousValid ? math.max(high - low, math.max(math.abs(high - close[1]), math.abs(low - close[1]))) : high - low) : na float a_shortRange = ta.sma(a_trueRange, a_horizon) float a_longRange = ta.sma(a_trueRange, 4 * a_horizon) float a_scale = a_shortRange[1] bool a_warm = a_priceCount >= 4 * a_horizon + 2 bool a_scaleKnown = a_warm and not na(a_scale) and a_scale > 0 // Two-pole SuperSmoother in signed price space. No log-price clipping. float a_decay = math.exp(-math.sqrt(2.0) * math.pi / a_horizon) float a_c2 = 2.0 * a_decay * math.cos(math.sqrt(2.0) * math.pi / a_horizon) float a_c3 = -a_decay * a_decay float a_c1 = 1.0 - a_c2 - a_c3 var float a_level = na float a_level1 = a_previousValid ? nz(a_level[1], close) : close float a_level2 = a_previousValid ? nz(a_level[2], a_level1) : close a_level := a_validPrice ? a_c1 * (close + (a_previousValid ? close[1] : close)) / 2.0 + a_c2 * a_level1 + a_c3 * a_level2 : na float a_velocity = a_scaleKnown ? (a_level - a_level1) / a_scale : na float a_acceleration = a_scaleKnown ? (a_level - 2.0 * a_level1 + a_level2) / a_scale : na float a_curvature = a_scaleKnown ? a_acceleration / math.pow(1.0 + a_velocity * a_velocity, 1.5) : na float a_extension = a_scaleKnown ? (close - a_level) / a_scale : na float a_distance = math.sum(math.abs(close - close[1]), a_horizon) float a_efficiency = a_warm ? (a_distance > 0 ? math.abs(close - close[a_horizon]) / a_distance : 0.0) : na float a_volatility = a_warm and a_longRange > 0 ? a_shortRange / a_longRange : na float a_shockRatio = a_scaleKnown ? a_trueRange / a_scale : na bool a_shock = a_scaleKnown and a_shockRatio >= 3.0 int a_direction = a_scaleKnown ? (a_velocity > 0.08 ? 1 : a_velocity < -0.08 ? -1 : 0) : 0 // Volume semantics remain separate from directional evidence. string a_volumeKind = a_volumeInput == "Auto" ? (syminfo.volumetype == "base" ? "Trade units" : syminfo.volumetype == "tick" ? "Tick count" : syminfo.volumetype == "quote" ? "Quote value" : "Unverified") : a_volumeInput bool a_validVolume = a_validPrice and not na(volume) and volume >= 0 var int a_volumeCount = 0 a_volumeCount := a_validVolume ? a_volumeCount + 1 : 0 float a_volumeMean = ta.sma(a_validVolume ? volume : na, a_horizon)[1] float a_relativeVolume = a_volumeInput != "Off" and a_volumeCount >= a_horizon + 1 and a_volumeMean > 0 ? volume / a_volumeMean : na string a_anchorTf = switch a_anchorInput "Day" => "1D" "Week" => "1W" "Month" => "1M" "Year" => "12M" => timeframe.isintraday ? "1D" : timeframe.isdaily ? "1M" : "12M" float a_chartSeconds = a_timedChart ? timeframe.in_seconds() : na bool a_anchorLonger = a_timedChart and timeframe.in_seconds(a_anchorTf) > a_chartSeconds bool a_anchorEnabled = a_supported and a_anchorInput != "Off" and a_volumeKind == "Trade units" and a_anchorLonger bool a_anchorChanged = timeframe.change(a_anchorTf) and not barstate.isfirst var bool a_anchorComplete = false var bool a_anchorPoisoned = false var float a_anchorWeight = 0.0 var float a_anchorMean = 0.0 if a_anchorChanged a_anchorComplete := true a_anchorPoisoned := false a_anchorWeight := 0.0 a_anchorMean := 0.0 if not a_validVolume a_anchorPoisoned := true else if volume > 0 and a_anchorEnabled float a_totalWeight = a_anchorWeight + volume a_anchorMean += volume / a_totalWeight * (hlc3 - a_anchorMean) a_anchorWeight := a_totalWeight float a_vwapReference = a_anchorEnabled and a_anchorComplete and not a_anchorPoisoned and a_anchorWeight > 0 ? a_anchorMean : na // A scenario freezes a previously observable boundary. It is not a trade ledger. float a_priorHigh = ta.highest(high, a_horizon)[1] float a_priorLow = ta.lowest(low, a_horizon)[1] var int a_scenario = 0 var float a_boundary = na bool a_invalidated = false int a_breakout = 0 if not a_scaleKnown a_scenario := 0 a_boundary := na else if a_scenario != 0 and (close - a_boundary) * a_scenario < 0 a_invalidated := true a_scenario := 0 a_boundary := na else if a_scenario == 0 if close > a_priorHigh a_scenario := 1 a_boundary := a_priorHigh a_breakout := 1 else if close < a_priorLow a_scenario := -1 a_boundary := a_priorLow a_breakout := -1 // Each message is a direct explanation of a measurement or a named hypothesis. string a_state = not a_supported ? "UNSUPPORTED CHART" : not a_validPrice ? "INVALID PRICE DATA" : not a_warm ? "BUILDING HISTORY" : not a_scaleKnown ? (a_trueRange == 0 ? "FLAT" : "SCALE UNAVAILABLE") : a_direction > 0 ? "UPWARD" : a_direction < 0 ? "DOWNWARD" : "BALANCED" string a_organization = not a_warm ? "Awaiting history" : a_efficiency >= 0.55 ? "Directional path" : a_efficiency < 0.25 ? "Backtracking path" : "Mixed path" float a_directionalAcceleration = a_acceleration * a_direction string a_pace = not a_scaleKnown ? "Unavailable" : a_direction == 0 ? "No directional pace" : a_directionalAcceleration > 0.015 ? "Gaining pace" : a_directionalAcceleration < -0.015 ? "Losing pace" : "Steady pace" string a_volatilityText = not a_warm ? "Awaiting history" : a_shock ? "SHOCK / " + a_f_number(a_shockRatio) + " x prior range" : na(a_volatility) ? "No range" : a_volatility > 1.3 ? "Expanding" : a_volatility < 0.7 ? "Contracting" : "Near longer baseline" string a_locationText = not a_scaleKnown ? "Unavailable" : (math.abs(a_extension) >= 1.5 ? "Extended / " : "Near reference / ") + a_f_number(a_extension) + " range units" string a_participation = a_volumeInput == "Off" ? "Off / price-only context" : not a_validVolume ? "Missing volume" : na(a_relativeVolume) ? "Baseline unavailable" : a_f_number(a_relativeVolume) + " x / " + a_volumeKind if timeframe.isintraday and a_volumeInput != "Off" a_participation += "\nNot time-of-day adjusted" string a_anchorText = a_anchorInput == "Off" ? "Off" : a_volumeKind != "Trade units" ? "Requires declared trade units" : not a_anchorLonger ? "Anchor must exceed chart interval" : not a_anchorComplete ? "First partial anchor withheld" : a_anchorPoisoned ? "Anchor has missing data" : a_anchorWeight <= 0 ? "No positive anchor volume" : (close > a_vwapReference ? "Above " : close < a_vwapReference ? "Below " : "At ") + a_anchorTf + " VWAP" string a_scenarioText = a_invalidated ? "Prior breakout failed" : a_scenario > 0 ? "Upward range breakout" : a_scenario < 0 ? "Downward range breakout" : "No active breakout scenario" string a_failureText = a_scenario > 0 ? "Close below " + str.tostring(a_boundary, format.mintick) : a_scenario < 0 ? "Close above " + str.tostring(a_boundary, format.mintick) : "No scenario boundary" string a_reading = not a_warm ? "Waiting for " + str.tostring(4 * a_horizon + 2) + " consecutive valid bars." : not a_scaleKnown ? "Normalized movement is unavailable." : a_shock ? "Range jumped relative to its prior baseline.\nThe previous pace may no longer describe conditions." : a_direction != 0 and a_efficiency < 0.25 ? "The smoother points one way; raw price backtracks.\nDirection and path organization conflict." : a_direction != 0 and math.abs(a_extension) >= 1.5 ? "Price is far from the smoothed reference.\nExtension alone does not imply reversal." : a_direction != 0 ? "The filtered path is directional.\nRead pace and participation separately." : "Directional movement is weak under this definition.\nA balanced reading does not predict a breakout." string a_hypothesis = not a_scaleKnown ? "Insufficient normalized evidence." : a_shock ? "Information arrival or a liquidity change are possible.\nThe chart does not identify the cause." : a_direction != 0 and a_efficiency >= 0.55 ? "Persistent execution demand is one possible explanation.\nParticipant identity and intent are unobserved." : "Two-sided trade is one possible explanation.\nOHLCV cannot identify who supplied liquidity." color a_stateColor = not a_warm or not a_scaleKnown ? a_neutralColor : a_direction > 0 ? a_upColor : a_direction < 0 ? a_downColor : a_neutralColor // === BEARING ENGINE === // Copyright (c) 2026 Kontaus. Experimental kb-0.3; no established market edge. bool b_allowShort = input.bool(false, "Enable short entries", group = "B · 00 · Entry direction", tooltip = "Long entries are enabled. Turn this on to also allow red short-entry triangles and short plans. Signals still require all setup and risk conditions. This control is in the cross-market 0.3.1 indicator; the old 0.2 baseline is long-only.") string b_profileInput = input.string("Auto", "Instrument profile", options = ["Auto", "Stocks", "Bonds", "Futures", "Forex", "Crypto", "Generic"], group = "B · 01 · Market") string b_profile = b_profileInput == "Auto" ? (syminfo.type == "stock" or syminfo.type == "fund" ? "Stocks" : syminfo.type == "futures" ? "Futures" : syminfo.type == "forex" ? "Forex" : syminfo.type == "crypto" ? "Crypto" : "Generic") : b_profileInput string b_volumePolicy = input.string("Profile", "Participation policy", options = ["Profile", "Required", "Price only"], group = "B · 01 · Market", tooltip = "Profile requires volume for Stocks/Futures/Crypto. Bonds/Forex/Generic use price only. Missing required volume blocks new plans.") string b_volumeMode = input.string("Prior EW", "Volume baseline", options = ["Prior EW", "Session slot"], group = "B · 01 · Market", tooltip = "Prior EW uses 20 earlier volume observations. Session slot uses at least 5 earlier trading days at this exchange-local minute. Minute or hourly charts only; no current-bar volume in the baseline.") bool b_vwapGate = input.bool(false, "Require session VWAP alignment", group = "B · 01 · Market", tooltip = "Requires a fully observed trading-day anchor and positive current volume. VWAP is context, not order flow.") int b_resetAt = input.time(0, "Reset model at contract/data boundary", group = "B · 01 · Market", tooltip = "Optional timestamp. Resets analytical history once; never cancels an open illustrative stop. Does not construct or adjust a futures roll.") string b_setupMode = input.string("Breakout", "Setup", options = ["Breakout", "Pullback", "Either"], group = "B · 02 · Signals") float b_decay = input.float(0.9, "Evidence memory", minval = 0.01, maxval = 0.99, step = 0.01, group = "B · 02 · Signals") float b_persistenceMin = input.float(20, "Minimum directional evidence", minval = 0, maxval = 100, group = "B · 02 · Signals") float b_extensionLimit = input.float(1.5, "Maximum entry extension · ATR", minval = 0.1, group = "B · 02 · Signals") float b_efficiencyMin = input.float(0.25, "Minimum directional efficiency", minval = 0, maxval = 1, group = "B · 02 · Signals") float b_shockAtr = input.float(4, "Shock threshold · prior ATR", minval = 0.1, group = "B · 02 · Signals") int b_cooldown = input.int(3, "Shock cooldown · bars", minval = 0, maxval = 100, group = "B · 02 · Signals") float b_account = input.float(100000, "Reference account", minval = 1, group = "B · 03 · Risk") float b_riskPct = input.float(1, "Planned risk %", minval = 0, maxval = 100, group = "B · 03 · Risk") float b_stopAtr = input.float(3, "Frozen distance · ATR", minval = 0.1, group = "B · 03 · Risk") float b_conversion = input.float(1, "Account currency per quote currency", minval = 0.00000001, group = "B · 03 · Risk", tooltip = "Explicit fixed conversion for the illustration, not an FX feed. Use 1 only when account and quote currency match. Recompute when conversion changes.") float b_pointOverride = input.float(0, "Point-value override · 0 = symbol", minval = 0, group = "B · 03 · Risk") float b_pointValue = b_pointOverride > 0 ? b_pointOverride : syminfo.pointvalue float b_tick = syminfo.mintick float b_lot = input.float(1, "Quantity increment", minval = 0.00000001, group = "B · 03 · Risk", tooltip = "Quantity uses symbol units/contracts, not broker-defined FX lots. Confirm the point value and increment for this instrument.") float b_margin = input.float(0, "Capacity per unit · account currency", minval = 0, group = "B · 03 · Risk", tooltip = "Required for Futures and nonpositive-price plans. Enter a conservative per-contract allocation. It is not a live broker margin model. Zero uses cash notional for other positive-price instruments.") float b_capitalFraction = input.float(1, "Maximum capacity · account fraction", minval = 0, maxval = 1, group = "B · 03 · Risk") float b_costBps = input.float(5, "One-way notional costs · bps", minval = 0, group = "B · 03 · Risk") float b_feePerUnit = input.float(0, "One-way fee per unit · quote currency", minval = 0, group = "B · 03 · Risk") int b_slipTicks = input.int(1, "Adverse slippage · ticks", minval = 0, maxval = 100, group = "B · 03 · Risk") string b_theme = input.string("Auto", "Theme", options = ["Auto", "Dark", "Light"], group = "B · 04 · Appearance") if not chart.is_standard or timeframe.isticks runtime.error("Konatus requires standard time-based OHLC charts.") if na(b_pointValue) or na(b_tick) or math.sign(b_pointValue) <= 0 or math.sign(b_tick) <= 0 runtime.error("A positive tick and point value are required.") if b_volumeMode == "Session slot" and (not timeframe.isintraday or timeframe.in_seconds() < 60) runtime.error("Session-slot volume needs intraday time bars of at least one minute.") bool b_needsVolume = b_volumePolicy == "Required" or (b_volumePolicy == "Profile" and (b_profile == "Stocks" or b_profile == "Futures" or b_profile == "Crypto")) if b_vwapGate and not timeframe.isintraday runtime.error("Session VWAP gating requires intraday time bars. Disable it on daily and higher charts.") // Shared confirmed-bar analytical engine. Price units allow zero/negative prices. var float b_level = na var float b_drift = 0 var float b_p00 = 0 var float b_p01 = 0 var float b_p11 = 0 var float b_atr = 0 var float b_trSum = 0 var float b_previous = na var float b_evidence = 0 var int b_count = 0 var int b_direction = 0 var int b_runLength = 0 var int b_pause = 0 var array b_highs = array.new_float() var array b_lows = array.new_float() var array b_closes = array.new_float() var array b_slotMean = array.new_float(1440, 0) var array b_slotCount = array.new_int(1440, 0) var array b_slotAnchor = array.new_int(1440, na) var float b_volMean = 0 var int b_volCount = 0 var int b_anchor = na var bool b_anchorComplete = false var bool b_anchorValid = true var float b_pv = 0 var float b_vSum = 0 var float b_vwap = na var float b_relativeVolume = na var float b_efficiency = 0 var float b_extension = na var float b_surprise = na var float b_predictiveSd = na var float b_distance = 0 var float b_quantity = 0 var string b_volumeStatus = "WARMUP" var string b_condition = "WARMUP" var string b_entryStatus = "WARMUP" var string b_setupName = "NONE" var int b_breakoutSide = 0 var float b_breakoutLevel = na var bool b_ready = false int b_signal = 0 bool b_valid = not na(open) and not na(high) and not na(low) and not na(close) and (math.min(open, close) - low) / b_tick >= 0 and (high - math.max(open, close)) / b_tick >= 0 bool b_resetNow = b_resetAt > 0 and time >= b_resetAt and (na(time[1]) or time[1] < b_resetAt) if barstate.isconfirmed if not b_valid or b_resetNow b_level := na b_drift := 0 b_p00 := 0 b_p01 := 0 b_p11 := 0 b_atr := 0 b_trSum := 0 b_previous := na b_evidence := 0 b_count := 0 b_direction := 0 b_runLength := 0 b_pause := 0 array.clear(b_highs) array.clear(b_lows) array.clear(b_closes) array.fill(b_slotMean, 0) array.fill(b_slotCount, 0) array.fill(b_slotAnchor, na) b_volMean := 0 b_volCount := 0 b_anchor := na b_anchorComplete := false b_anchorValid := true b_pv := 0 b_vSum := 0 b_vwap := na b_breakoutSide := 0 b_ready := false b_quantity := 0 b_distance := 0 b_extension := na b_efficiency := 0 b_surprise := na b_predictiveSd := na b_relativeVolume := na b_volumeStatus := "UNAVAILABLE" b_condition := "INVALID DATA" b_entryStatus := "INVALID DATA" b_setupName := "NONE" if b_valid float b_priorLevel = b_level float b_tr = na(b_previous) ? high - low : math.max(high - low, math.abs(high - b_previous), math.abs(low - b_previous)) float b_scale = math.max(b_count >= 14 ? b_atr : b_count > 0 ? b_trSum / b_count : b_tr, b_tick) float b_variance = b_scale * b_scale float b_observation = 0.25 * b_variance if na(b_level) b_level := close b_p00 := b_observation b_p11 := b_observation b_surprise := 0 b_predictiveSd := math.sqrt(2 * b_observation) else float b_a = b_p00 + 2 * b_p01 + b_p11 + 0.01 * b_variance float b_b = b_p01 + b_p11 float b_d = b_p11 + 0.0001 * b_variance float b_predictive = b_a + b_observation float b_innovation = close - b_level - b_drift b_surprise := b_innovation / math.sqrt(b_predictive) b_predictiveSd := math.sqrt(b_predictive) float b_k0 = b_a / b_predictive float b_k1 = b_b / b_predictive float b_m = 1 - b_k0 b_level += b_drift + b_k0 * b_innovation b_drift += b_k1 * b_innovation b_p00 := b_m * b_m * b_a + b_k0 * b_k0 * b_observation b_p01 := b_m * (b_b - b_k1 * b_a) + b_k0 * b_k1 * b_observation b_p11 := b_d - 2 * b_k1 * b_b + b_k1 * b_k1 * b_a + b_k1 * b_k1 * b_observation b_count += 1 if b_count <= 14 b_trSum += b_tr b_atr := b_trSum / b_count else b_atr += (b_tr - b_atr) / 14 int b_priorDirection = b_direction b_direction := b_drift / b_tick > 0.000001 ? 1 : b_drift / b_tick < -0.000001 ? -1 : 0 b_runLength := b_direction != 0 and b_direction == b_priorDirection ? b_runLength + 1 : b_direction != 0 ? 1 : 0 b_evidence := b_decay * b_evidence + (1 - b_decay) * math.max(-1, math.min(1, b_drift / (0.1 * b_scale))) array.push(b_closes, close) if array.size(b_closes) > 21 array.shift(b_closes) float b_travel = 0 if array.size(b_closes) > 1 for j = 1 to array.size(b_closes) - 1 b_travel += math.abs(array.get(b_closes, j) - array.get(b_closes, j - 1)) b_efficiency := b_travel > 0 ? math.abs(close - array.get(b_closes, 0)) / b_travel : 0 b_extension := math.abs(close - b_level) / math.max(b_atr, b_tick) bool b_shock = not na(b_previous) and math.abs(close - b_previous) / b_scale > b_shockAtr b_pause := b_shock ? b_cooldown : math.max(0, b_pause - 1) b_ready := b_count >= 40 and b_atr / b_tick > 0.000001 b_condition := b_count < 40 ? "WARMUP" : not b_ready ? "FLAT" : b_shock or b_pause > 0 ? "SHOCK" : b_efficiency < b_efficiencyMin ? "CONGESTION" : "TREND" bool b_haveVolume = not na(volume) and volume >= 0 int b_slot = hour(time, syminfo.timezone) * 60 + minute(time, syminfo.timezone) int b_dayAnchor = time_tradingday float b_baseline = b_volumeMode == "Session slot" ? array.get(b_slotMean, b_slot) : b_volMean int b_samples = b_volumeMode == "Session slot" ? array.get(b_slotCount, b_slot) : b_volCount int b_lastAnchor = array.get(b_slotAnchor, b_slot) bool b_duplicateSlot = b_volumeMode == "Session slot" and not na(b_lastAnchor) and b_lastAnchor == b_dayAnchor bool b_enough = b_samples >= (b_volumeMode == "Session slot" ? 5 : 20) b_relativeVolume := b_haveVolume and b_enough and b_baseline > 0 and not b_duplicateSlot ? volume / b_baseline : na b_volumeStatus := not b_haveVolume ? "VOLUME MISSING" : b_duplicateSlot ? "SLOT REPEATED" : volume == 0 ? "ZERO VOLUME" : na(b_relativeVolume) ? "VOLUME WARMUP" : "AVAILABLE" if b_haveVolume and not b_duplicateSlot float b_updated = b_samples == 0 ? volume : b_baseline + (volume - b_baseline) * 2 / 21 if b_volumeMode == "Session slot" array.set(b_slotMean, b_slot, b_updated) array.set(b_slotCount, b_slot, b_samples + 1) array.set(b_slotAnchor, b_slot, b_dayAnchor) else b_volMean := b_updated b_volCount += 1 if not b_needsVolume b_volumeStatus := "PRICE ONLY" bool b_volumeOk = not b_needsVolume or (b_volumeStatus == "AVAILABLE" and b_relativeVolume >= 1) if na(b_anchor) or b_dayAnchor != b_anchor b_anchorComplete := not na(b_anchor) b_anchor := b_dayAnchor b_anchorValid := true b_pv := 0 b_vSum := 0 if not b_haveVolume b_anchorValid := false if b_haveVolume and volume > 0 b_pv += hlc3 * volume b_vSum += volume b_vwap := b_vSum > 0 ? b_pv / b_vSum : na bool b_contextOk = not b_vwapGate or (b_anchorValid and b_anchorComplete and not na(b_vwap) and b_haveVolume and volume > 0 and b_direction * (close - b_vwap) / b_tick > 0) int b_fire = 0 if not b_ready or b_shock or b_pause > 0 b_breakoutSide := 0 else if b_breakoutSide != 0 if b_breakoutSide * (close - b_breakoutLevel) / b_tick > 0 b_fire := b_breakoutSide b_breakoutSide := 0 else if array.size(b_highs) == 20 if (close - array.max(b_highs)) / b_tick > 0 b_breakoutSide := 1 b_breakoutLevel := array.max(b_highs) else if (array.min(b_lows) - close) / b_tick > 0 b_breakoutSide := -1 b_breakoutLevel := array.min(b_lows) int b_pull = not na(b_previous) and not na(b_priorLevel) and b_direction * (b_previous - b_priorLevel) / b_tick <= 0 and b_direction * (close - b_level) / b_tick > 0 ? b_direction : 0 int b_setupSide = b_setupMode == "Breakout" ? b_fire : b_setupMode == "Pullback" ? b_pull : b_fire != 0 ? b_fire : b_pull b_setupName := b_setupSide != 0 and b_setupSide == b_fire ? "BREAKOUT" : b_setupSide != 0 ? "PULLBACK" : "NONE" b_distance := math.ceil(b_stopAtr * b_atr / b_tick - 1e-9) * b_tick float b_slip = b_slipTicks * b_tick float b_fees = 2 * b_feePerUnit + (2 * math.abs(close) + b_distance + 2 * b_slip) * b_pointValue * b_costBps / 10000 float b_unitRisk = ((b_distance + b_slip + b_tick) * b_pointValue + b_fees) * b_conversion float b_capacity = b_profile == "Futures" or math.sign(close) <= 0 ? b_margin : b_margin > 0 ? b_margin : (math.abs(close) + b_slip) * b_pointValue * b_conversion float b_capacityWithFees = b_capacity + (b_feePerUnit + (math.abs(close) + b_slip) * b_pointValue * b_costBps / 10000) * b_conversion b_quantity := math.sign(b_capacity) > 0 and math.sign(b_distance) > 0 and math.sign(b_unitRisk) > 0 ? math.max(0, math.floor(math.min(b_account * b_riskPct / 100 / b_unitRisk, b_account * b_capitalFraction / b_capacityWithFees) / b_lot) * b_lot) : 0 b_entryStatus := b_count < 40 ? "WARMUP" : not b_ready ? "FLAT" : b_condition == "SHOCK" ? "SHOCK PAUSE" : b_condition == "CONGESTION" ? "CONGESTION" : b_direction == 0 or b_direction * b_evidence * 100 < b_persistenceMin ? "WEAK EVIDENCE" : b_direction < 0 and not b_allowShort ? "SHORT DISABLED" : not b_volumeOk and b_volumeStatus != "AVAILABLE" ? b_volumeStatus : not b_volumeOk ? "LOW PARTICIPATION" : not b_contextOk ? "VWAP CONTEXT" : b_extension > b_extensionLimit ? "EXTENDED" : b_quantity <= 0 ? "SIZE UNAVAILABLE" : b_setupSide == b_direction ? "READY" : "WAIT SETUP" b_signal := b_entryStatus == "READY" ? b_direction : 0 array.push(b_highs, high) array.push(b_lows, low) if array.size(b_highs) > 20 array.shift(b_highs) array.shift(b_lows) b_previous := close // Integration changes candidate entries only; existing plans keep their original ledger. var string atlasGateStatus = "OBSERVE ONLY" var bool atlasBlocked = false if barstate.isconfirmed atlasBlocked := false atlasGateStatus := atlasPolicy == "Observe only" ? "OBSERVE ONLY" : not a_scaleKnown ? "ANATOMY WARMUP / DATA" : a_shock ? "ANATOMY SHOCK" : a_direction == 0 or a_direction != b_direction ? "DIRECTION CONFLICT" : atlasPolicy == "Require organized direction" and (na(a_efficiency) or a_efficiency < 0.55) ? "PATH NOT ORGANIZED" : "CONTEXT ALIGNED" if atlasPolicy != "Observe only" and b_signal != 0 and atlasGateStatus != "CONTEXT ALIGNED" b_signal := 0 b_entryStatus := atlasGateStatus atlasBlocked := true // Illustrative next-open ledger. Orders are not sent to a broker. var int b_heldSide = 0 var int b_pendingSide = 0 var float b_pendingQuantity = 0 var float b_pendingDistance = 0 var float b_heldQuantity = 0 var float b_entryPrice = na var float b_stopPrice = na var float b_heldDistance = na var int b_reversalCount = 0 var bool b_pendingExit = false var bool b_capacityBreached = false bool b_entryIntent = false bool b_exitIntent = false bool b_entered = false bool b_exited = false string b_exitReason = "" if barstate.isconfirmed and b_valid bool b_dueExit = b_pendingExit b_pendingExit := false float b_slip = b_slipTicks * b_tick if b_heldSide != 0 if b_heldSide * (open - b_stopPrice) / b_tick <= 0 b_exited := true b_exitReason := "GAP_STOP" else if b_dueExit b_exited := true b_exitReason := "REVERSAL" if b_heldSide == 0 and b_pendingSide != 0 b_heldSide := b_pendingSide b_heldQuantity := b_pendingQuantity b_heldDistance := b_pendingDistance b_entryPrice := open + b_heldSide * b_slip float b_rawStop = b_entryPrice - b_heldSide * b_heldDistance b_stopPrice := (b_heldSide > 0 ? math.floor(b_rawStop / b_tick + 1e-9) : math.ceil(b_rawStop / b_tick - 1e-9)) * b_tick float b_entryFee = b_heldQuantity * (b_feePerUnit + math.abs(b_entryPrice) * b_pointValue * b_costBps / 10000) * b_conversion float b_filledCapacity = b_margin > 0 ? b_margin : math.abs(b_entryPrice) * b_pointValue * b_conversion b_capacityBreached := b_filledCapacity * b_heldQuantity + b_entryFee > b_account * b_capitalFraction b_pendingSide := 0 b_entered := true if b_heldSide != 0 and not b_exited and (b_heldSide > 0 ? (b_stopPrice - low) / b_tick >= 0 : (high - b_stopPrice) / b_tick >= 0) b_exited := true b_exitReason := "STOP" if b_exited b_heldSide := 0 b_reversalCount := 0 if b_heldSide != 0 b_reversalCount := b_direction == -b_heldSide ? b_reversalCount + 1 : 0 if b_reversalCount >= 2 b_pendingExit := true b_exitIntent := true else if not b_exited and b_signal != 0 b_pendingSide := b_signal b_pendingQuantity := b_quantity b_pendingDistance := b_distance b_entryIntent := true // Alerts are decision events. Namespace separates configurations/alert instances. string b_alertNamespace = input.string("default", "Alert instance ID", group = "B · 05 · Alerts", tooltip = "Use a distinct ID for each configuration. Allowed characters: letters, numbers, dash and underscore. Recreate TradingView alerts after settings change.") if str.length(b_alertNamespace) == 0 or str.match(b_alertNamespace, "^[A-Za-z0-9_-]+$") != b_alertNamespace runtime.error("Alert instance ID must contain only letters, numbers, dash or underscore.") if b_entryIntent or b_exitIntent string b_eventName = b_entryIntent ? "ENTRY_INTENT" : "EXIT_INTENT" int b_eventSide = b_entryIntent ? b_pendingSide : b_heldSide string b_eventId = "atlas-0.1:" + b_alertNamespace + ":" + syminfo.tickerid + ":" + timeframe.period + ":" + str.tostring(time_close) + ":" + b_eventName + ":" + str.tostring(b_eventSide) string b_payload = '{"version":"atlas-0.1-experimental","id":"' + b_eventId + '","event":"' + b_eventName + '","symbol":"' + syminfo.tickerid + '","timeframe":"' + timeframe.period + '","time_close":' + str.tostring(time_close) + ',"side":' + str.tostring(b_eventSide) + ',"quantity":' + str.tostring(b_entryIntent ? b_pendingQuantity : b_heldQuantity, "#.########") + ',"distance":' + str.tostring(b_entryIntent ? b_pendingDistance : b_heldDistance, "#.########") + ',"illustrative":true}' alert(b_payload, alert.freq_once_per_bar_close) // === ATLAS PRESENTATION: one dashboard, one candle-color owner === bool atlasConfirmed = barstate.isconfirmed bool atlasDark = b_theme == "Dark" or (b_theme == "Auto" and color.r(chart.bg_color) + color.g(chart.bg_color) + color.b(chart.bg_color) < 384) color atlasSurface = atlasDark ? #101B24 : #F8F6EF color atlasInk = atlasDark ? #F3EAD6 : #202D35 color atlasMuted = atlasDark ? #A7B9BD : #4C6069 color atlasUp = atlasDark ? #63D4B7 : #096A55 color atlasDown = atlasDark ? #F1A394 : #9B322C color atlasGold = atlasDark ? #E5C078 : #755308 color atlasBorder = atlasDark ? #34464C : #B6C4C2 color atlasBearingColor = not b_ready or math.abs(b_evidence * 100) < b_persistenceMin ? atlasMuted : b_direction > 0 ? atlasUp : atlasDown color atlasAnatomyColor = a_direction > 0 ? atlasUp : a_direction < 0 ? atlasDown : atlasMuted bool atlasDisplayValid = atlasConfirmed ? b_valid : b_valid[1] string atlasState = not atlasDisplayValid ? "DATA UNAVAILABLE" : b_pendingExit ? "EXIT QUEUED" : b_heldSide != 0 ? (b_heldSide > 0 ? "LONG PLAN" : "SHORT PLAN") : b_pendingSide != 0 ? "ENTRY QUEUED" : b_entryStatus string atlasReason = b_heldSide != 0 ? (not atlasDisplayValid ? "Data invalid; last stop retained" : b_capacityBreached ? "Capacity exceeded at illustrative fill" : "Illustrative stop remains active") : b_pendingSide != 0 ? "Illustrative next-open fill queued" : atlasBlocked ? "Anatomy policy blocked this entry candidate" : b_entryStatus == "EXTENDED" ? "Bearing: price exceeds entry extension limit" : b_entryStatus == "SIZE UNAVAILABLE" ? "Review contract, capacity and risk inputs" : b_entryStatus == "WAIT SETUP" ? "Bearing conditions available; wait for setup" : "Read conditions before interpreting a setup" string atlasPosition = atlasCorner == "Top right" ? position.top_right : atlasCorner == "Top left" ? position.top_left : atlasCorner == "Bottom right" ? position.bottom_right : position.bottom_left string atlasTextSize = atlasFont == "Tiny" ? size.tiny : atlasFont == "Normal" ? size.normal : size.small bool atlasDetailed = atlasDensity == "Detailed" var table atlasPanel = table.new(atlasPosition, 2, atlasDetailed ? 23 : 14, bgcolor = atlasSurface, frame_color = atlasBorder, frame_width = 1) atlas_row(int n, string caption, string value, color tone) => table.cell(atlasPanel, 0, n, " " + caption + " ", text_color = atlasMuted, bgcolor = atlasSurface, text_size = atlasTextSize, text_halign = text.align_left) table.cell(atlasPanel, 1, n, " " + value + " ", text_color = tone, bgcolor = atlasSurface, text_size = atlasTextSize, text_halign = text.align_right) if barstate.isfirst table.merge_cells(atlasPanel, 0, 1, 1, 1) table.merge_cells(atlasPanel, 0, 2, 1, 2) table.merge_cells(atlasPanel, 0, atlasDetailed ? 22 : 13, 1, atlasDetailed ? 22 : 13) if barstate.islast table.clear(atlasPanel, 0, 0, 1, atlasDetailed ? 22 : 13) if atlasDensity != "Hidden" or (b_heldSide != 0 and (b_capacityBreached or not atlasDisplayValid)) int snap = atlasConfirmed ? 0 : 1 bool anatomyAvailable = a_scaleKnown[snap] bool agreement = anatomyAvailable and b_ready and b_direction != 0 and b_direction == a_direction[snap] string alignment = not anatomyAvailable or not b_ready ? "Awaiting valid history" : b_direction == 0 or a_direction[snap] == 0 ? "At least one is balanced" : agreement ? "Directions agree / shared data" : "Directions disagree" string clockText = na(time_close[snap]) ? "No confirmed bar" : str.format_time(time_close[snap], "MM-dd HH:mm", syminfo.timezone) atlas_row(0, "KONATUS ATLAS", syminfo.ticker + " / " + timeframe.period, atlasGold) table.cell(atlasPanel, 0, 1, " " + atlasState + " ", text_color = b_heldSide != 0 ? atlasBearingColor : atlasGold, bgcolor = atlasSurface, text_size = atlasFont == "Tiny" ? size.normal : size.large, text_halign = text.align_left) table.cell(atlasPanel, 0, 2, " " + atlasReason + " ", text_color = atlasMuted, bgcolor = atlasSurface, text_size = atlasTextSize, text_halign = text.align_left) atlas_row(3, "BEARING / ANATOMY", (b_direction > 0 ? "Up" : b_direction < 0 ? "Down" : "Balanced") + " / " + a_state[snap], atlasInk) atlas_row(4, "ENTRY POLICY", atlasGateStatus, atlasGateStatus == "CONTEXT ALIGNED" ? atlasUp : atlasGold) atlas_row(5, "PACE / RAW PATH", a_pace[snap] + " / " + a_organization[snap], atlasInk) atlas_row(6, "ANATOMY VOLATILITY", a_volatilityText[snap], a_shock[snap] ? atlasGold : atlasInk) atlas_row(7, "BEARING NEW ENTRY", b_entryStatus, atlasInk) atlas_row(8, "ILLUSTRATIVE STOP", b_heldSide != 0 ? str.tostring(b_stopPrice, format.mintick) : "No open plan", atlasGold) atlas_row(9, "ACTIVE / QUEUED QTY", str.tostring(b_heldSide != 0 ? b_heldQuantity : b_pendingSide != 0 ? b_pendingQuantity : 0, "#.########"), atlasInk) atlas_row(10, "ALIGNMENT", alignment, agreement ? atlasUp : atlasMuted) atlas_row(11, "ACTIVITY / ROLLING", a_participation[snap], atlasMuted) atlas_row(12, "CONFIRMED THROUGH", clockText + " / " + syminfo.timezone, atlasMuted) if atlasDetailed atlas_row(13, "ANATOMY READING", a_reading[snap], atlasInk) atlas_row(14, "POSSIBLE MECHANISM", a_hypothesis[snap], atlasMuted) atlas_row(15, "VELOCITY / ACCELERATION", a_f_number(a_velocity[snap]) + " / " + a_f_number(a_acceleration[snap]), atlasInk) atlas_row(16, "CURVATURE / EFFICIENCY", a_f_number(a_curvature[snap]) + " / " + a_f_number(a_efficiency[snap]), atlasInk) atlas_row(17, "ANATOMY LOCATION", a_locationText[snap], atlasInk) atlas_row(18, "BEARING EXTENSION", str.tostring(b_extension, "0.00") + " ATR", atlasInk) atlas_row(19, "SCENARIO / NOT A STOP", a_scenarioText[snap] + "\n" + a_failureText[snap], atlasMuted) atlas_row(20, "ANATOMY ANCHOR", a_anchorText[snap], atlasMuted) atlas_row(21, "BEARING PARTICIPATION", b_volumeStatus, atlasMuted) table.cell(atlasPanel, 0, atlasDetailed ? 22 : 13, " ATLAS 0.1 / RESEARCH / ILLUSTRATIVE PLANS ", text_color = atlasMuted, bgcolor = atlasSurface, text_size = size.tiny) // Restrain overlays. Gold = illustrative stop; dotted teal = descriptive scenario. plot(b_level, "Bearing price", color = atlasBearingColor, linewidth = 2) plot(atlasConfirmed and atlasAnatomyLine and a_warm ? a_level : na, "Anatomy filtered price", color = atlasMuted) atlasUpper = plot(atlasConfirmed and atlasEnvelope and a_scaleKnown ? a_level + 1.5 * a_scale : na, "Anatomy upper envelope", color = color.new(atlasMuted, 80)) atlasLower = plot(atlasConfirmed and atlasEnvelope and a_scaleKnown ? a_level - 1.5 * a_scale : na, "Anatomy lower envelope", color = color.new(atlasMuted, 80)) fill(atlasUpper, atlasLower, color = color.new(atlasAnatomyColor, 94), title = "Anatomy descriptive range") plot(atlasConfirmed and atlasVwap ? a_vwapReference : na, "Anatomy calendar VWAP", color = atlasMuted) plot(atlasConfirmed and atlasScenario ? a_boundary : na, "Anatomy scenario / NOT stop", color = atlasUp, style = plot.style_circles) plot(b_heldSide != 0 ? b_entryPrice : na, "Illustrative entry", color = atlasMuted, style = plot.style_linebr) plot(b_heldSide != 0 ? b_stopPrice : na, "Bearing illustrative frozen stop", color = atlasGold, linewidth = 2, style = plot.style_linebr) barcolor(atlasCandles and atlasConfirmed ? atlasBearingColor : na) plotshape(b_entryIntent and b_pendingSide == 1, "Long plan intent", shape.triangleup, location.belowbar, atlasUp, size = size.tiny) plotshape(b_entryIntent and b_pendingSide == -1, "Short plan intent", shape.triangledown, location.abovebar, atlasDown, size = size.tiny) plotshape(b_exited, "Illustrative plan exit", shape.xcross, location.abovebar, atlasGold, size = size.tiny) plotshape(atlasEvents and atlasConfirmed and a_breakout != 0, "Anatomy breakout observation", shape.circle, location.belowbar, atlasMuted, size = size.tiny) // Selected Data Window diagnostics, deliberately within the plot budget. plot(atlasConfirmed ? a_velocity : na, "Anatomy velocity", display = display.data_window) plot(atlasConfirmed ? a_acceleration : na, "Anatomy acceleration", display = display.data_window) plot(atlasConfirmed ? a_curvature : na, "Anatomy curvature", display = display.data_window) plot(atlasConfirmed and a_warm ? a_efficiency : na, "Anatomy raw efficiency", display = display.data_window) plot(atlasConfirmed ? a_scale : na, "Anatomy prior SMA range", display = display.data_window) plot(atlasConfirmed ? a_relativeVolume : na, "Anatomy rolling activity", display = display.data_window) plot(b_evidence * 100, "Bearing signed persistence", display = display.data_window) plot(b_atr, "Bearing ATR", display = display.data_window) plot(b_signal, "Atlas filtered candidate", display = display.data_window) plot(b_heldSide, "Illustrative held side", display = display.data_window) plot(b_quantity, "Bearing candidate quantity", display = display.data_window) plot(atlasBlocked ? 1 : 0, "Atlas context blocked candidate", display = display.data_window) bool atlasDirectionChanged = a_scaleKnown and a_scaleKnown[1] and a_direction != a_direction[1] alertcondition(atlasConfirmed and atlasDirectionChanged, "Atlas: Anatomy direction changed", "ATLAS {{ticker}} {{interval}}: confirmed Anatomy direction changed; not an order.") alertcondition(atlasConfirmed and a_shock and not a_shock[1], "Atlas: Anatomy volatility shock", "ATLAS {{ticker}} {{interval}}: new Anatomy range shock.") alertcondition(atlasConfirmed and a_breakout != 0, "Atlas: Anatomy breakout observed", "ATLAS {{ticker}} {{interval}}: descriptive range breakout, not a plan entry.") alertcondition(atlasConfirmed and a_invalidated, "Atlas: Anatomy scenario invalidated", "ATLAS {{ticker}} {{interval}}: descriptive scenario invalidated, not a plan exit.") alertcondition(atlasConfirmed and atlasBlocked, "Atlas: candidate blocked by context", "ATLAS {{ticker}} {{interval}}: Anatomy entry policy blocked a Bearing candidate.")