OPEN-SOURCE SCRIPT
Aktualisiert

SwiftLevels

2 213
SwiftLevels is a clean, all-in-one overlay indicator that keeps the most important price reference levels and daily moving averages visible at a glance — without cluttering your chart.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
PRIOR DAY & PRIOR WEEK LEVELS
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
On intraday charts, SwiftLevels draws horizontal lines for the prior day high/low and prior week high/low. Lines are anchored to the prior session's open so they don't clutter the left side of the chart. Labels float at the right edge of the current session and update each bar close to show the live percentage distance from price — positive when price is above, negative when below.

Example: PRIOR DAY (+1.24%) PRIOR WEEK (-0.87%)

Colors and label visibility are fully configurable per level group.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
DAILY MOVING AVERAGES (5 fully configurable)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Five independent moving averages, each calculated from daily chart data regardless of your current timeframe.

On intraday charts:
• Each MA is drawn as a clean horizontal line starting at today's session open and extending right — no stair-stepping history, no noise from previous sessions.
• Labels appear just before the line starts, showing the MA name and live % distance from price, updated each bar close.
• Example: 20d SMA (+2.11%) 50d SMA (-0.44%)

On the daily chart:
• MAs are displayed as traditional full-history plots so you can see the curve over time.
• Can be toggled on/off with the "Display on Daily" checkbox.

On weekly/monthly charts:
• MAs are hidden to keep those timeframes uncluttered.

Each moving average is independently configurable:
• Enable / disable
• Length (default: 5, 10, 20, 50, 200)
• SMA or EMA toggle
• Custom color
• Line width
Versionshinweise

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
NEW: DAILY MOVING AVERAGES
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Added 5 fully configurable daily moving averages. Each MA is calculated from daily chart data and displayed as a clean horizontal line on intraday charts — starting at today's session open with no historical stair-stepping. On the daily chart they render as traditional full-history plots. Hidden on weekly/monthly to keep those views clean.

Each MA is independently configurable: enable/disable, length, SMA or EMA, color, and line width. Defaults are 5, 10, 20, 50, and 200 period.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
NEW: STATUS DATA BOX
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
A compact table in the top-right corner shows where price stands relative to every level and moving average, updated on each bar close.

🟢 above 🔴 below 🟡 proximity alert

For level rows (Prior Day / Prior Week), yellow indicates price is currently trading inside the prior week range. For MA rows, yellow triggers when price is within ±0.20% of the MA — signalling a near-touch or active test of that average. Each row also shows the live percentage distance, color-coded to match.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
IMPROVED: LABELS
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
All labels now include a live percentage distance from the current price, updated on bar close. Labels for Prior Day and Prior Week levels float at the right edge of the session. MA labels are anchored just before the line starts on the left side. Label text updated to "PRIOR DAY" and "PRIOR WEEK" for clarity.
Versionshinweise
SwiftLevels — Version 2.1 Changes

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
IMPROVED: DATA BOX — LEVEL ROWS
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Prior Day and Prior Week are now each a single combined row instead of separate high/low rows. The status dot reflects the full range:

🟢 price is above the range high
🔴 price is below the range low
🟡 price is inside the range

When price is inside the range, the percentage column now shows "Inside" instead of a dash, so it's immediately clear what the yellow dot means without hovering.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
NEW: DATA BOX — SLOPE COLUMN
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
A fourth column has been added to the data box showing the daily slope direction for each moving average:

▲ green — MA is trending higher today vs. yesterday
▼ red — MA is trending lower today vs. yesterday

Slope is calculated by comparing today's daily MA value against yesterday's confirmed daily close — so the direction reflects actual daily momentum, not intraday noise.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
NEW: DATA BOX — HOVER TOOLTIPS
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Hovering over cells in the data box now shows context-sensitive detail:

Status dot — plain-English description of price position relative to the level
(e.g. "Price is above the Prior Day range (+1.24% above the high)")
Label cell — shows the actual price values for the level or MA
(e.g. "Prior Day · High: 5,412.00 Low: 5,387.50")
Slope arrow — confirms direction
(e.g. "20d SMA is sloping up")

Tooltips are fully dynamic and update with each bar close.
Versionshinweise
SwiftLevels — Version 2.2 Changes

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
NEW: PRIOR DAY -2 & PRIOR WEEK -2 LEVELS
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
A second tier of reference levels has been added: the high/low from two days back (Prior Day -2) and two weeks back (Prior Week -2). These draw as dashed lines in a dimmer shade of the existing level colors, so they're clearly secondary to the primary prior-day/prior-week lines. Each has its own input group (color, line width, label toggle) and floating labels with live percentage distance, exactly like the originals.

These appear as lines only — they are not added to the data box.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
NEW: DATA BOX SECTIONS & HEADERS
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
The data box is now split into two labelled sections with header strips:

POSITION — Prior Day, Prior Week, and the 5 moving averages
PERFORMANCE — period gains (see below)

Each section can be shown or hidden independently from the new "Data Box" settings group. Hiding POSITION slides PERFORMANCE up to the top; hiding both removes the data box entirely.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
NEW: PERFORMANCE GAINS
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
A new PERFORMANCE section shows how far price has moved over five horizons, each measured against the prior completed period's close:

Day Gain — vs prior daily close
Week Gain — vs prior weekly close
Month Gain — vs prior monthly close
YTD Gain — vs prior-year close
1-Year Gain — vs the close ~252 trading days ago

Each row has a 🟢/🔴 dot, a sign-colored percentage, and a hover tooltip showing the reference price.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
IMPROVED: PERFORMANCE (UNDER THE HOOD)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
All higher-timeframe data requests were consolidated from 23 separate security calls down to 5 by bundling same-timeframe values into single tuple requests. Security calls are the dominant cost in Pine, so the indicator now loads and runs noticeably lighter with no change to behavior.
Versionshinweise
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
NEW: REGULAR HOURS MODE (FOR FUTURES)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Futures trade nearly around the clock, so the symbol's own daily bar spans the overnight session. A thin overnight spike would become the "prior day high" even though it never traded during regular hours, and the levels re-anchored at the 18:00 Globex open instead of the 09:30 cash open.

A new "Session" settings group adds "Enforce Regular Hours Only (for Futures)". With it ticked, the prior day and prior week levels are rebuilt from regular-hours bars only, and the session redraw follows the cash open. The session window and timezone are both editable (default 09:30–16:00 New York), so the same switch serves index futures, FX, or any non-US exchange.

Off by default — leave it off and the indicator behaves exactly as before, which is already correct for stocks.

Scope of the switch:

Affected — prior day/week high & low (both tiers), redraw and line
anchoring, weekday names, and the Day Gain reference close
Not affected — the daily moving averages, and the Week / Month / YTD /
1-Year gains

The moving averages are excluded deliberately: rebuilding a 200-day average from regular hours would require 200 days of intraday bars on the chart, and a daily MA is conventionally computed on the full session in any case.

Because the levels are accumulated from bars loaded on your chart, Prior Week -2 needs roughly ten sessions of history and may be unavailable on a 1-minute chart. Any level that cannot be built yet is left undrawn rather than drawn from incomplete data.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
NEW: PER-LEVEL VISIBILITY TOGGLES
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Every level group now has an "Enable" checkbox that hides both its lines and labels, plus separate "Show High" and "Show Low" checkboxes. You can run prior day high only, drop the -2 tier entirely, or any combination.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
NEW: CONFIGURABLE LABEL OFFSETS
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
A "Label Offsets" group sets how far right of the last bar each set of labels floats, independently for Prior Day, Prior Day -2, Prior Week, Prior Week -2, and the moving averages. Give two groups different offsets to stagger them into separate columns when their prices sit close together.

Offsets are measured in bars rather than pixels, so the on-screen gap scales with chart zoom. Note that labels sitting beyond the last bar need chart room — if your "Bars to the right" margin is smaller than the offset, they will be off-screen until you scroll.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
IMPROVED: MOVING AVERAGE LABELS
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
MA labels have moved from the far left of their lines to the right edge, in line with the Prior Day and Prior Week labels, and now track the right edge as new bars print. They default to a wider offset than the level labels so the two form separate columns.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
IMPROVED: LEVEL LABEL TEXT
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Labels now name the level explicitly and, for the daily levels, the weekday the session fell on:

PRIOR DAY HIGH (-3.13%) MON PRIOR WEEK HIGH (-2.11%)
FRI HIGH (-1.32%) 2 WEEKS AGO HIGH (-6.32%)

The day-2 levels are labelled by weekday alone and the week-2 levels as "2 weeks ago". Weekday names are resolved from the session the level actually came from, so after a long weekend the prior-day label reads FRI rather than a calendar guess, and holiday closures are skipped correctly.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
CHANGED: DEFAULTS & SETTINGS LAYOUT
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Moving Average 3 now defaults to a 21 EMA instead of a 20 SMA. The Data Box section checkboxes have moved to the top of the settings panel.

Note that changing a default only affects new additions of the indicator — a chart with saved settings keeps its stored values until reset.

Haftungsausschluss

Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.