OPEN-SOURCE SCRIPT
מעודכן

Stop Distance Quality [AGPro Series]

708
Stop Distance Quality [AGPro Series]

🧠 Core Idea

Is the invalidation distance structurally reasonable, or is it too tight, too wide, or too exposed to noise?


📌 Overview / What it does

Stop Distance Quality [AGPro Series] is a chart-first risk planning tool built to evaluate stop-distance quality before a setup is treated as clean.

The script studies the active invalidation rail, ATR-normalized stop distance, swing structure fit, wick risk, volatility context, and available target room. It converts those components into a 0-100 risk-quality score and a clear next-action state.

It produces a stop-fit band, an invalidation rail, an ideal-fit guide, compact chart labels, alerts, and a clean AGPro planning panel. It does not select the best stop method, size positions, predict price direction, or automate trade decisions.


🎯 Purpose & Design Philosophy

This script was built to fill a specific planning gap: many tools show where a stop could be placed, but fewer tools ask whether that stop distance is structurally usable.

It helps traders who already have a setup idea and want to evaluate whether the invalidation distance is balanced enough to keep watching.

The design supports disciplined planning: measure the risk first, then decide whether the setup deserves attention.


⚡ Why This Script Is Different

Most tools focus on plotting stop-loss levels, comparing stop-loss methods, or attaching stops to entry signals.

This script does NOT act as a stop-loss optimizer, position-size calculator, target ladder, or directional signal tool.

Instead, it answers one practical planning question: is the current stop distance too tight, too wide, or reasonably aligned with structure and volatility?


⚙️ Methodology

1. Context Detection
The script selects long or short evaluation context using either manual side selection or automatic trend and range-location reading.

2. Reference Mapping
It maps one active swing-based invalidation rail and builds a stop-fit band using minimum, ideal, and maximum ATR-normalized distance boundaries.

3. Reaction Evaluation
It scores stop distance, swing structure fit, wick risk, volatility context, and target room.

4. Visual Output
It displays the stop-fit band, invalidation rail, ideal-fit guide, chart labels, alerts, and AGPro panel state.


🗺️ How to Read the Chart

Zones = the stop-fit band shows the acceptable ATR-normalized area where the active invalidation distance is considered more balanced.

Labels = labels mark FIT, WATCH, TOO TIGHT, TOO WIDE, NO ROOM, or invalidation-check contexts.

Colors = AGPro green highlights balanced fit, pink highlights wide-risk pressure, amber highlights caution, and indigo highlights active watch context.

Panel = the panel summarizes Stop Distance, ATR Context, Structure Fit, Risk Quality, and Action.


🚦 Signals & States

• FIT → stop distance is structurally reasonable enough for active review.

• WATCH → risk quality is improving but not strong enough for FIT.

• TOO TIGHT → invalidation distance is too close relative to ATR and may be vulnerable to normal noise.

• TOO WIDE → invalidation distance is too large relative to the current chart context.

• NO ROOM → target room is not clean enough for the current risk distance.

• WEAK FIT → the current context does not meet the minimum quality threshold.


🔔 Alerts Logic

Alerts trigger when the script enters FIT, WATCH, TOO TIGHT, TOO WIDE, or NO ROOM state.

An additional alert can trigger when price crosses the prior invalidation rail.

Alerts are attention markers only. They are not trade instructions.


🧩 Confluence Logic

The strongest context appears when stop distance sits near the ideal ATR band, swing structure is clear, wick noise is controlled, volatility is readable, and target room remains open.

When several of these conditions align, the risk-quality score improves.


📊 When to Use

• Before evaluating a risk-defined setup

• During pullbacks where invalidation placement matters

• Around breakout retests where stops can be too tight or too wide

• In structured trending or range-extension environments


⚠️ When NOT to Use

• Very low-liquidity symbols with erratic wicks

• Extremely noisy markets where ATR changes too quickly

• News-driven candles or abnormal event spikes

• Charts where no clear swing invalidation exists


🎛️ Key Inputs

• Evaluation Side → controls Auto, Long Context, or Short Context scoring.

• ATR Length → normalizes stop distance, wick risk, target room, and visual offsets.

• Invalidation Lookback → controls the swing rail used as the active invalidation reference.

• Minimum / Ideal / Maximum Stop ATR → define the stop-fit band.

• FIT / WATCH Thresholds → control how selective the planner is.

• Visual settings → control band visibility, guide lines, labels, panel location, theme, and font sizes.


🖥️ Interface & Visual Design

The interface is intentionally narrow and readable.

The chart focuses on one main visual object: the stop-fit band. The panel uses a single merged AGPro header row and keeps the essential risk-quality information visible without turning the script into a dashboard-heavy tool.

Labels are compact, offset from candles, and controlled with cooldown and maximum-visible settings.


🧪 Practical Usage Workflow

1. Read the panel risk-quality state.

2. Check whether the invalidation rail sits inside, below, or beyond the stop-fit band.

3. Review whether the label says FIT, WATCH, TOO TIGHT, TOO WIDE, or NO ROOM.

4. Confirm structure and volatility context before treating the setup as meaningful.


🔍 Interpretation Guidelines

Think of the output as a risk-quality filter, not a trade signal.

A FIT state means the distance is more balanced relative to ATR and structure. It does not mean price must move favorably.

A TOO TIGHT or TOO WIDE state means the risk reference may need more context, more buffer, or a cleaner setup.


🚫 What This Script Is NOT

• Not a prediction engine

• Not financial advice

• Not auto trading

• Not guaranteed signals

• Not a stop-loss optimizer

• Not a position-sizing calculator


⚠️ Limitations & Transparency

Stop-distance quality can change as volatility expands or contracts.

Different timeframes may produce different invalidation rails and ATR readings.

Fast markets, low liquidity, and abnormal wick behavior can reduce the usefulness of any rule-based distance model.


🧠 Market Context Notes

Risk quality is not only about where a stop sits. It also depends on whether volatility is readable, whether the swing reference is meaningful, and whether there is enough room before nearby obstruction.

This script keeps those factors visible without adding unrelated signal logic.


🧾 Use Case Examples

When price pulls back in a trend and the invalidation rail sits inside the stop-fit band, the setup can move into review mode.

When the stop distance is below the minimum ATR boundary, the script may mark TOO TIGHT and suggest waiting for more buffer.

When stop distance is large but target room is limited, the script may mark NO ROOM or TOO WIDE.


🧱 System Philosophy

Stop Distance Quality belongs to the AGPro planner-style family: tools that help traders evaluate context before decisions, rather than simply printing another signal.


🔐 Non-Promise Statement

No output from this script guarantees a result.

No score represents certainty.


📉 Risk Disclosure

Trading involves risk.

Users are responsible for their own decisions, position sizing, and risk management.

This script is for educational and analytical purposes only and does not provide financial advice.


📚 Educational Note

The goal is to make risk distance easier to inspect and compare across changing volatility conditions.
הערות שחרור
UPDATE NOTES - V1.1

This update focuses on chart readability, label density control, panel conformity, and cleaner stop-distance interpretation.

The core purpose of the script remains unchanged.
Stop Distance Quality continues to evaluate whether the active invalidation distance is too tight, too wide, or structurally reasonable by combining ATR-normalized stop distance, swing structure fit, wick risk, volatility context, and target room.

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
------------------------

- Added Engine Presets
Balanced Quality, Cleaner Swing, Active Intraday, and Custom presets were added so users can quickly adapt the script to different chart speeds and visual-density preferences.

- Reduced Default Label Density
Sparse context labels are now disabled by default, label cooldown was increased, and visible label retention was reduced to keep the chart cleaner.

- Refined Stop-Fit Band
The stop-fit band now carries the main SDQ score and state as a centered label, making the chart object self-explanatory.

- Updated Panel Layout
The panel now follows the AGPro standard more closely with a single merged blue title row, stop distance, ATR context, structure fit, risk quality, action, and best-view guidance.

- Added Alert Controls
FIT/WATCH alerts can now be controlled separately from tight, wide, no-room, and invalidation rail warning alerts.

- Preserved Core Logic
The scoring model remains focused on stop distance quality, not prediction, position sizing, or trade automation.


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

- Improved chart readability by making the stop-fit band the primary visual reference.

- Reduced visual clutter from repeated context labels.

- Refined visual hierarchy so the stop-fit band, ideal guide, invalidation rail, and panel values are easier to interpret.

- Adjusted default label behavior to keep important state changes visible without crowding the chart.

- Preserved centered text inside the stop-fit band for cleaner publication screenshots.


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

- Added Engine Preset controls for faster setup.

- Preserved user control for context labels, invalidation labels, state markers, label cooldown, visible label count, and label font size.

- Optimized panel layout for clearer information flow.

- Preserved adjustable panel visibility, panel location, panel theme, and panel font size.


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

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

The main change is visual and workflow-oriented: fewer default labels, cleaner band presentation, and stronger panel readability.

Users who prefer a denser chart can enable sparse context labels, enable invalidation check labels, lower cooldown values, and increase the visible label count.


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

The script remains a rule-based analytical tool.

Market conditions such as volatility, liquidity, timeframe differences, wick-heavy noise, and abrupt news-driven movement may affect how stop-distance states appear.

Stop-distance outputs are analytical references and 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.
הערות שחרור
UPDATE NOTES - Version 1.2

This update focuses on stop-distance clarity, ATR context readability, visual hierarchy, and risk-planning usability.

The core purpose of the script remains unchanged.
Stop Distance Quality continues to evaluate whether an active invalidation distance is too tight, too wide, or structurally reasonable.

This script remains an analytical and visualization tool.
It does not attempt to predict price direction, optimize stop-loss placement, size positions, or provide guaranteed outcomes.


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

* Stronger stop-distance quality presentation
The active stop-distance band now uses a clearer SDQ state label that shows quality score, state, and ATR-normalized stop distance.

* Solid band label
The main band text is now displayed in a solid label box instead of pale text inside a transparent zone.

* Improved guide tags
Right-side tags now make the invalidation rail, ideal stop distance, and target-room context easier to read.

* More professional dashboard panel
The panel now separates Risk Quality, Stop Distance, ATR Context, Structure Fit, Wick Risk, Target Room, Next Action, and Best View.

* Better risk-language hierarchy
FIT, WATCH, TOO TIGHT, TOO WIDE, NO ROOM, and WEAK FIT are now easier to distinguish visually and conceptually.


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

* Improved chart readability by making the active stop-distance band more visible.

* Added stronger separation between stop band, ideal distance, invalidation rail, and target room.

* Reduced the risk of washed-out text on dark and light chart themes.

* Refined event label style so labels read as risk-quality states, not as trade signals.


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

* Panel now reads more like a risk-planning dashboard.

* ATR context is more visible and easier to interpret.

* Stop distance and target room are shown as separate planning dimensions.

* The visual system better supports Trade Management Planner style workflows without changing the script into a paid product clone.


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

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

The output should be interpreted as stop-distance quality context.
It is not a stop-loss recommendation, not a trade entry instruction, and not a position-sizing model.


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

The script remains a rule-based analytical tool.

Market conditions such as volatility, liquidity, symbol behavior, and timeframe selection may affect how states 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.
הערות שחרור
🔧 UPDATE NOTES - Version 1.3

This update focuses on premium chart readability, panel-standard compliance, and cleaner risk-planning presentation.

The core purpose of the script remains unchanged.
Stop Distance Quality continues to evaluate whether active invalidation distance is too tight, too wide, or structurally reasonable.

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
------------------------

• Premium stop-fit band refresh
The stop-fit band now uses a lighter zone style with separate centered solid badges instead of relying on box text.

• Removed box text usage
All stop-fit information is now displayed through label badges, keeping the chart aligned with the AGPro zone-label standard.

• Added Smart Higher-Timeframe Width
The stop-fit projection can stay tighter on weekly and monthly charts to avoid oversized screenshot visuals.

• Expanded panel location options
Top Center, Middle Center, and Bottom Center panel positions were added for better layout flexibility.

• Strengthened panel header rendering
The panel now clears and then re-merges the first row on each last-bar refresh so the blue header remains a single merged row.


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

• Improved first-glance readability by separating the main SDQ state badge from the compact stop/room metric badge.

• Reduced visual heaviness in the stop-fit band while preserving all guide rails and target-room context.

• Refined guide tag hierarchy for Invalidation, Ideal, and Target Room references.

• Improved chart consistency with current AGPro visual standards.


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

• Preserved all existing input groups and risk-quality settings.

• Kept panel visibility, panel theme, panel location, panel font size, label font size, guide tags, and event-label controls.

• Added a new Smart Higher-Timeframe Width visual control.

• Kept all alerts and hidden export plots intact.


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

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

The goal is to improve clarity, usability, and publication quality without changing how the script evaluates stop-distance quality.

Users should interpret outputs the same way as before, but with improved visual hierarchy.


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

The script remains a rule-based analytical tool.

Market conditions such as volatility, liquidity, timeframe differences, and symbol behavior may affect how risk-quality states 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.
הערות שחרור
🔧 UPDATE NOTES - V1.4

This update focuses on readability, visual clarity, and interface structure.

The core purpose of the script remains unchanged.
This release improves how the existing risk-quality logic is presented 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
------------------------

• Consolidated the stop-fit band readout into a single clean badge
The band previously used two separate stacked labels. They are now merged into one centered badge showing the quality score, state, stop distance, and target room together.

• Added an inline quality gauge
A compact 0-100 quality gauge now appears on both the centered band badge and the panel for faster at-a-glance reading.

• Cleaner band presentation
With a single centered badge, the stop-fit band reads more clearly and avoids overlapping text near price.

• Reorganized the panel headline
The Risk Quality row now includes the inline gauge alongside the state for quicker interpretation.


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

• Improved chart readability by replacing two stacked band labels with one centered badge

• Reduced visual clutter so the stop-fit band stays clean at a glance

• Refined visual hierarchy so the score, state, and distance values stand out more clearly

• Kept the centered badge aligned within the band for a balanced, premium look


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

• Added a consistent inline quality gauge for quicker interpretation

• Streamlined the band badge into a single, readable element

• Adjusted default visual presentation for a more balanced appearance

• Enhanced overall readability without changing the core risk-quality logic


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

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

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

Users should interpret outputs the same way as before, but with improved visual structure.


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

The script remains a rule-based analytical tool.

Market conditions such as volatility, liquidity, and timeframe differences may affect how states and 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.
הערות שחרור
UPDATE NOTES - V1.5

This update focuses on on-chart readability and a cleaner, more consistent premium presentation.

The core purpose of the script remains unchanged.
This release improves how the existing risk-quality readout is displayed on the chart and in the panel. It does not change the scoring model, the state logic, or the alerts.

This script continues to function as a chart-first risk planning and visualization tool. It does not attempt to predict price direction or provide guaranteed outcomes.


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

- Cleaner score readout
The small inline bar next to the quality score has been removed. The score now reads as a clean number alongside its state (for example, "SDQ 37 | Too Wide"), which is easier to read at a glance.

- Consistent Title Case
All on-chart state text and panel values now use Title Case (Fit, Watch, Too Tight, Too Wide, No Room, Rail Check) instead of all-caps. This gives the chart a calmer, more professional look.

- Refined band badge and tags
The centered stop-fit band badge and the right-side guide tags (invalidation, ideal, target room) were tidied for clearer first-glance interpretation.

- No logic changes
Stop-distance scoring, structure fit, wick risk, volatility context, target room, state thresholds, and all alerts behave exactly as before.


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

- Improved chart readability by simplifying the quality readout and unifying label casing.

- Reduced visual noise in the band badge so the key numbers stand out.

- Refined the visual hierarchy between the band badge, the invalidation rail, and the guide tags.

- Kept labels offset above and below candles so they do not overlap price.


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

- Cleaner panel value formatting for a more balanced, premium appearance.

- More consistent wording between the panel and the on-chart labels.

- Default visual settings remain tuned for clean public-release screenshots.

- Overall user experience improved without changing core logic.


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

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

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

Users should interpret outputs the same way as before, now with a cleaner and more consistent on-chart readout.


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

The script remains a rule-based analytical tool.

Market conditions such as volatility, liquidity, and timeframe differences may affect how states and distances 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.
הערות שחרור
🔧 UPDATE NOTES - v1.6

This update focuses on decision confidence and proof.

The core purpose of the script remains unchanged.
This release adds a confirmation-anchored proof layer, sharpens the next-action
readout, and standardizes how the headline risk-quality score is presented.

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
------------------------

• Added a Proof Layer (Follow / Hold / React / Flip)
The panel now reports how past FIT confirmations on the current symbol and timeframe
actually resolved. Each FIT confirmation is tracked forward over a configurable horizon:
- Follow Rate : share of FIT confirmations that reached one risk multiple (1R) in the
planned direction before the invalidation rail was breached
- Hold Rate : share where the invalidation rail held through resolution (no breach)
- React Rate : share that produced an early favorable push inside the reaction window
- Flip Rate : share where price breached the invalidation rail within the horizon
A sample size (n) is shown so the rates are read in context, and they display as
"building" until at least one FIT confirmation has resolved.

• Sharpened the Next Action readout
The action line now reads as clear decision language for each state:
Fit - Review, Watch - Monitor, Too Tight - Wait, Too Wide - Wait, No Room - Wait,
and Hold Off, paired with the active direction.

• Standardized the headline score
Risk Quality now displays in the "X / 100" numeric format alongside its state label.
There are no gauge or bar characters anywhere in the script - every score is numeric.

• Added hidden data exports
Follow, Hold, React, and Flip rates are exposed as hidden plots so the proof values can
be referenced by alerts, screeners, or other tools without changing the chart visuals.


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

• Kept the solid stop-fit badge centered, both vertically and horizontally, inside the band.

• Reduced visual clutter so the panel reads as a single, structured decision card.

• Refined visual hierarchy so the risk-quality read and its proof context stand out clearly.

• Maintained candle-clearance offsets so labels stay readable above or below price.


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

• Optimized panel layout for clearer information flow, with the proof block grouped
under a dedicated "Proof @ Confirm" heading.

• Improved label readability for better chart interaction.

• Adjusted default visual settings for a more balanced appearance.

• Added a Proof input group (show/hide, proof horizon bars, reaction window bars,
reaction progress threshold) so the proof layer is fully configurable without
affecting the core scoring logic.


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

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

The proof rates are descriptive statistics of past resolved FIT confirmations on the
current symbol and timeframe. They are not forecasts, and they do not change how stop
distance is scored, classified, or how the invalidation rail is located.

Users should interpret outputs the same way as before, now with added historical context.


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

The script remains a rule-based analytical tool.

Proof rates depend on the amount of available history and on the current symbol and
timeframe; a small sample (low n) should be treated with caution. The proof model tracks
one FIT confirmation at a time, so overlapping FIT episodes are sampled rather than
double-counted. Market conditions such as volatility, liquidity, and timeframe differences
may affect how signals and rates 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.

כתב ויתור

המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.