OPEN-SOURCE SCRIPT
Aktualisiert

Rolling Midpoint Engine [AGPro Series]

1 021
Rolling Midpoint Engine [AGPro Series]

### Overview

Rolling Midpoint Engine is an on-chart study that converts the geometric midpoint of the last N bars' high-low range into a living control line. The midline is tracked through three behavioral states — Accepted Above, Accepted Below, and Fight — and a fourth modifier (Strong) highlights high-conviction acceptance beyond an ATR threshold. The goal is to surface how price behaves around a single dominant reference level, not to predict direction or issue trade signals.

### Unique Edge

Most midpoint tools plot a static line and let the user eyeball whether price accepts or rejects it. Rolling Midpoint Engine formalises that observation into a finite state machine that requires consecutive body-closes on one side of the midline before declaring acceptance. This filters single-bar noise and distinguishes casual tags from genuine commitment. The ATR-based Strong modifier adds a second axis of information — how firmly the current side is being held — without multiplying states or cluttering the chart with additional lines.

### Methodology

The midline is computed as the average of the highest high and the lowest low over a user-defined rolling window. Optional light EMA smoothing reduces visual jitter without materially shifting the level; a Strict Reset mode disables smoothing for pure rolling output.

Acceptance is evaluated through two streak counters tracking consecutive closes (or full bars, if the user prefers a stricter rule) on each side of the midline. When a streak reaches the Acceptance Bars threshold, the state transitions to Accepted Above or Accepted Below. If the running streak is positive but below threshold, the state is Fight. A Strong flag activates whenever the current distance from the midline exceeds a configurable ATR multiple.

All logic uses confirmed bar closes. The script does not repaint historical states once a bar has closed.

### States & Alerts

States:
- Fight — price is oscillating around the midline without sustained commitment
- Accepted Above — body-closes above the midline for the required number of bars
- Accepted Below — body-closes below the midline for the required number of bars
- Strong (modifier) — current Accepted state is held beyond the ATR threshold

Alerts:
- Midline Crossed Up / Down — raw price cross of the midline
- Accepted Above / Below — state transitions into acceptance
- Midline Rejection — state flip between Accepted Above and Accepted Below, or collapse from an Accepted state back to Fight

### Key Inputs

- Rolling Length — number of bars defining the range window
- Strict Reset Mode — toggle between pure rolling midline and lightly smoothed output
- Acceptance Bars — consecutive body-closes required for acceptance
- Use Body Close vs. Full Bar — strictness of the side-determination rule
- Strong Threshold — ATR multiple that qualifies an accepted side as Strong
- Label Style / Size — Edge Only, Edge + Transitions, or Off
- Panel Location / Theme / Font Size — four corners plus Middle Right, Dark / Light / Auto themes
- Color Midline by State — toggle state-coloring on the dominant line

### How to Use

Apply the indicator to any symbol and timeframe. The midline acts as a rolling control level; the state label on the right edge summarises the current behavior. Treat Accepted Above / Below as evidence that the midline is holding as support or resistance on the corresponding side. A transition into Strong indicates the holding is well beyond routine noise. A rejection event — the state flipping or collapsing back to Fight — suggests the prior control has been compromised.

This is a contextual reading tool. It does not produce entries, exits, targets, or stops, and should not be read as a recommendation to transact.

### Limitations & Transparency

The midline reflects past price data only and will adapt as new highs or lows enter the rolling window. On illiquid or very low-timeframe charts, the streak-based acceptance logic can feel slow; increasing Acceptance Bars on noisier instruments or lowering it on cleaner ones is expected tuning. The Strong Threshold is volatility-relative via ATR but still an arbitrary cut — defaults are calibrated for typical liquid markets and may need adjustment for thinly traded symbols.

The script uses confirmed closes and does not alter historical state once a bar has closed. Intrabar, the displayed state can update in line with current price, as with any live indicator.

### Risk Disclosure

This indicator is an analytical study. It is not a strategy, not a signal service, and not financial advice. It does not forecast future prices and does not guarantee any outcome. Past behavior of price around the midline does not imply future behavior. Every trading decision is the sole responsibility of the user. Use appropriate risk management and test the tool in a non-committed environment before incorporating it into any workflow.
Versionshinweise
UPDATE NOTES - V1.1

This update focuses on visual clarity, panel standardization, label balance, and publication readiness.

The core purpose of the script remains unchanged.
This release improves how the existing rolling midpoint logic is presented, organized, and interpreted on the chart.

This script continues to function as an analytical and visualization tool.
It does not attempt to predict price direction or provide guaranteed outcomes.


------------------------
What Changed
------------------------

* Removed the non-required legal block from the source header.
The script now follows the current AGPro public-free source format without an extra legal header.

* Preserved the original rolling midpoint engine.
The rolling range midpoint, smoothing option, acceptance streak logic, strong ATR threshold, alerts, and core state machine remain intact.

* Added a Balanced label mode.
The chart can now show the right-edge state tag plus controlled transition and strong-acceptance labels, making the script feel more alive without turning it into a noisy signal tool.

* Added label-density controls.
Max Visible Labels, Label Cooldown Bars, Label Offset ATR, and Right Tag Offset were added to control readability across lower and higher timeframes.

* Expanded the range context layer.
The subtle rolling range shell is now enabled by default, and a light state background can highlight accepted-above or accepted-below regimes without hiding candles.


------------------------
Visual Improvements
------------------------

* Improved first-glance chart readability by keeping the midpoint as the dominant structural line.

* Added controlled transition labels so the chart no longer depends on a single right-edge label only.

* Added label offset control to keep labels away from candle bodies.

* Added subtle state background support for accepted-above and accepted-below conditions.

* Kept the range shell faint so it gives context without overpowering the midpoint.


------------------------
Interface & Usability
------------------------

* Rebuilt panel options around the current AGPro standard.

* Added Elite Dark, Slate, and Clean Light panel themes.

* Expanded panel locations to include top, middle, and bottom center positions.

* Added live panel repositioning through table.set_position.

* Panel header now follows the AGPro render order: table.clear -> table.merge_cells -> header.

* Panel header remains a single merged blue row with only the script name.


------------------------
Behavior Notes
------------------------

This update does not change the core analytical logic of the script.

The rolling midpoint, acceptance bars, strong ATR threshold, cross alerts, acceptance alerts, and rejection alerts should be interpreted the same way as before.

The goal is to improve clarity and usability, not to introduce new predictive behavior.


------------------------
Limitations Reminder
------------------------

The script remains a rule-based analytical tool.

Market conditions such as volatility, liquidity, and timeframe differences may affect how often midpoint crosses, acceptance states, and transition labels appear.

Outputs should always be interpreted within broader market context.


------------------------
Risk Reminder
------------------------

This script is for educational and analytical purposes only.

It does not provide financial advice or guaranteed trading outcomes.

Users remain responsible for their own decisions.
Versionshinweise
🔧 UPDATE NOTES - v1.3

This update focuses on clarity, decision-readiness and chart cleanliness.

The core purpose of the script remains unchanged. It still maps the midpoint of
the recent rolling high-low range and tracks how price accepts above, accepts
below, or fights around that equilibrium. This release adds a quantitative read
of how decisively one side is in control and tidies the on-chart presentation.

This script continues to function as an analytical and visualization tool.
It does not attempt to predict price direction or provide guaranteed outcomes.


------------------------
What Changed
------------------------

• Control Score (0-100)
A new score quantifies how decisively one side controls the midpoint. During a
fight it reflects the leading side's progress toward acceptance; once a side is
accepted it builds from a confirmation base plus ATR distance from the midpoint,
midline-slope alignment and how long the state has persisted. The score appears
in the panel and on the right-edge tag, giving an at-a-glance read of control
strength rather than just direction.

• Contrast-aware label text
On-chart label text now derives its color from the badge background luminance,
so state tags stay crisp on every state color and theme. This fixes low-contrast
text on the neutral (fight) badge.

• ATR hardening
A guarded ATR value now drives label spacing, distance measurement and the
Control Score, preventing distortion on illiquid symbols or warm-up bars.


------------------------
Visual Improvements
------------------------

• Zero candle overlap: fight-state transition labels are no longer placed on the
midline where they sat on top of price. All transition labels now sit clearly
above the high or below the low, and the default label offset has been widened
so later candles in a choppy regime are far less likely to reach a past label.

• Refined right-edge tag: the current-state tag now also shows the Control Score,
with automatically balanced text contrast.

• Reduced visual clutter while preserving a lively, populated chart.


------------------------
Interface & Usability
------------------------

• Optimized panel layout: State → Control Score → Mid Slope → Bars in State →
Acceptance → Distance from Mid, with a short legend line for the score.

• Balanced default visual settings and improved label readability.


------------------------
Behavior Notes
------------------------

This update does not change the core midpoint, acceptance or state logic. The
rolling range, acceptance rules and state machine are unchanged. The goal is to
add a clearer quantitative read and improve on-chart presentation.

Users should interpret outputs the same way as before, now with an explicit
Control Score for context strength.


------------------------
Limitations Reminder
------------------------

The script remains a rule-based analytical tool. Market conditions such as
volatility, liquidity and timeframe differences may affect how states and the
Control Score appear. Outputs should always be interpreted within broader
market context.


------------------------
Risk Reminder
------------------------

This script is for educational and analytical purposes only. It does not provide
financial advice or guaranteed trading outcomes. Users remain responsible for
their own decisions.

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.