OPEN-SOURCE SCRIPT
Updated

Moving Average Retest Planner [AGPro Series]

822
Moving Average Retest Planner [AGPro Series]

🧠 Core Idea

Is a moving average retest clean enough to act as trend support or resistance, or is the reaction too weak to plan around?


📌 Overview / What it does

Moving Average Retest Planner is a chart-first planning tool built around one practical workflow: price moves away from an active moving average, returns into a controlled retest pocket, and the script evaluates whether that reaction has enough quality to deserve attention.

The script produces a moving average reference, a retest distance band, concept-native retest pockets, hold / watch / fail labels, invalidation rails, target rails, continuation markers, and a compact AGPro decision panel. It converts moving average slope, retest depth, wick response, close quality, relative volume, and target room into a normalized 0-100 Reaction Score.

It does not predict future price movement, automate trading, or claim that a moving average touch is automatically meaningful. Its role is to organize the current retest context into a clearer decision-support workflow.


🎯 Purpose & Design Philosophy

This script was built because many moving average tools stop at the most basic question: is price above or below the average?

That is rarely enough for real chart planning. A retest can be too early, too deep, too weak, or too close to nearby obstruction. The purpose of this script is to help traders evaluate whether the retest itself is clean, controlled, and supported by the surrounding structure.

The design supports traders who use moving averages as contextual references but want a more structured way to assess reaction quality, risk edge, and next action.


⚡ Why This Script Is Different

Most moving average tools focus on crossovers, ribbon direction, fixed EMA reclaim events, or simple above / below filters.

This script does NOT clone a 200 EMA reclaim map, a moving average ribbon stress model, a Hull MA zone tool, or a KAMA efficiency framework.

Instead, it focuses on one narrower decision layer: after price has moved away from an active configurable moving average, is the return into that average being defended or rejected with enough quality to become a valid planning area?


⚙️ Methodology

1. Context Detection
The script calculates the active moving average and checks whether the average has a meaningful slope. It separates bullish, bearish, and neutral contexts.

2. Reference Mapping
An ATR-normalized retest band is built around the active moving average. This band is used as the planning pocket rather than as a generic support / resistance zone.

3. Reaction Evaluation
When price returns into the band after moving away from it, the script evaluates slope quality, retest depth, wick response, close location, relative volume, and target room.

4. Visual Output
Qualified reactions can create retest pockets, hold / watch / fail labels, invalidation rails, target rails, continuation markers, alerts, and panel updates.


🗺️ How to Read the Chart

Zones = the active moving average retest pocket where price is being evaluated.

Labels = compact event markers for watch, hold, failure, and follow-through states.

Colors = bullish states use teal, bearish states use pink, neutral / waiting states use amber, and projected target context uses indigo.

Panel = summarizes MA Retest, Trend Side, Reaction Score, Risk Edge, and Action.


🚦 Signals & States

• WATCH → price is reacting near the moving average, but quality is below the READY threshold.

• READY → the retest score meets the required quality threshold.

• WAIT RETEST → trend context exists, but no clean retest is active yet.

• INVALIDATED → the active retest lost its invalidation edge.

• FOLLOW-THROUGH → price moved far enough from the trigger close to mark continuation after the retest.

• NO PLAN → the current chart does not contain a usable MA retest context.


🔔 Alerts Logic

Alerts can trigger when a READY retest appears, when an active retest invalidates, when follow-through is detected, or when the planner state changes.

These alerts are attention markers. They are not trade instructions, entry signals, or automated recommendations.


🧩 Confluence Logic

The strongest context appears when MA slope, controlled retest depth, clean wick response, strong close quality, relative volume support, and target room align at the same time.

When those components improve together, the Reaction Score rises. When the retest becomes too deep, too weak, or too close to obstruction, the score remains lower.


📊 When to Use

• Trending markets where price repeatedly returns to an active moving average

• Pullback continuation contexts

• Trend support or trend resistance evaluation

• Markets with enough liquidity for moving average reactions to be readable

• Multi-timeframe review where one average acts as a workflow reference


⚠️ When NOT to Use

• Very low-liquidity symbols

• Flat, noisy, low-range conditions

• Extreme news-driven volatility

• Charts where the selected moving average has no meaningful slope

• Situations where price is chopping through the average without clean reaction behavior


🎛️ Key Inputs

• MA Type and MA Length → define the active retest reference.

• Sensitivity → controls retest pocket width and required prior distance.

• Confirmation Mode → controls how strict the close-side hold must be.

• Minimum READY Score → sets the threshold for a high-quality retest state.

• Target R → defines the projected target rail from the invalidation edge.

• Label Cooldown and Max Visible Event Sets → manage label density and chart cleanliness.

• Panel Location, Panel Theme, Panel Font Size, and Label Font Size → control publication-ready presentation.


🖥️ Interface & Visual Design

The interface is built around a clean chart-first hierarchy.

The moving average and distance band show the active reference. Retest pockets highlight only qualified reaction areas. Labels sit above or below candles using ATR offsets so they remain readable. The panel gives the current planning answer without turning the script into a crowded dashboard.


🧪 Practical Usage Workflow

1. Read the panel to identify the current Action.

2. Check whether the moving average has a clear bullish or bearish trend side.

3. Look for a retest pocket and review the Reaction Score.

4. Compare the invalidation rail and target rail to judge the risk edge.

5. Treat alerts as prompts for review, not standalone decisions.


🔍 Interpretation Guidelines

The script should be read as a structured context model.

A high score means the detected retest has stronger alignment across the script's rules. A low score means the reaction is weaker, late, noisy, or poorly positioned. A failed retest means the active planning edge was lost according to the selected inputs.

The output is most useful when combined with broader structure, timeframe context, liquidity, and the trader's own risk process.


🚫 What This Script Is NOT

• Not a prediction engine

• Not financial advice

• Not an auto trading system

• Not a guaranteed signal tool

• Not a replacement for risk management

• Not a generic moving average crossover indicator


⚠️ Limitations & Transparency

Moving averages are lagging references. The selected length, asset, timeframe, volatility profile, and liquidity conditions can all affect how clean or noisy the retest behavior appears.

In strong trends, price may continue without giving a clean retest. In choppy markets, price may touch the average many times without creating meaningful structure. The score should be interpreted as a rule-based quality read, not certainty.


🧠 Market Context Notes

Moving average retests are most useful when the average represents an active path of value or trend behavior. The cleaner the slope and the more controlled the return into the average, the more useful the retest context usually becomes.

Liquidity, volatility, and nearby structural levels still matter. A strong-looking retest with poor target room may be less useful than a moderate retest with cleaner space.


🧾 Use Case Examples

When price trends above the selected average, pulls back into the retest band, rejects lower prices with a clear wick, closes back above the average, and has enough target room, the panel may move into READY.

When price returns to the average but closes weakly through the band or later crosses the invalidation rail, the retest can move into INVALIDATED.


🧱 System Philosophy

Moving Average Retest Planner follows the AGPro decision-engine approach: show the setup context, score its quality, define the risk edge, map the target area, and state the next action.

The goal is not to add another signal to the chart. The goal is to help traders read whether the current retest is organized enough to deserve attention.


🔐 Non-Promise Statement

No certainty.

No guaranteed continuation.

No guaranteed reversal.

No automated decision.


📉 Risk Disclosure

Trading involves risk. Market conditions can change quickly, and any indicator can produce false or incomplete readings.

This script is for educational and analytical purposes only. It does not provide financial advice, investment advice, or guaranteed trading outcomes.

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


📚 Educational Note

Use this tool to study how price behaves when it returns to an active moving average. The most important output is not a label by itself, but the relationship between retest quality, invalidation, target room, and broader market context.
Release Notes
UPDATE NOTES - 1.3

This update focuses on chart readability, panel consistency, zone ownership, and publication-ready visual polish.

The core purpose of the script remains unchanged.
This release improves how the existing moving average retest 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
------------------------

* Reworked retest pocket text
Retest pocket text is now shown through separate centered badges instead of box text.

* Standardized the AG Pro panel
The panel now uses the current single merged blue header row format.

* Expanded panel controls
Panel location options now include top, middle, and bottom center positions.

* Added modern panel themes
Elite Dark, Slate, and Clean Light themes are now available.

* Expanded font controls
Label and panel font-size controls now include Tiny, Small, Normal, Large, and Huge.

* Added rail tags
Target and invalidation rails can now show compact right-side price tags.


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

* Added centered BULL HOLD / BEAR HOLD and BULL WATCH / BEAR WATCH badges

* Improved pocket readability without relying on embedded box text

* Reduced default event-set count for a cleaner public chart

* Increased default label offset so event labels sit farther from candles

* Preserved a lively chart while reducing stale object dominance


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

* Added Show Centered Pocket Badges control

* Added Show Rail Tags control

* Improved panel row contrast across dark and light themes

* Added live panel-position updates through table.set_position

* Kept Show Panel enabled by default


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

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

The goal is to improve readability, interface consistency, and publication polish.

Users should interpret outputs as moving-average retest planning context, not trade instructions.


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

The script remains a rule-based analytical tool.

Moving-average reactions can vary across timeframe, volatility, liquidity, and trend condition.

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.
Release Notes
🔧 UPDATE NOTES - 1.7

This update further improves badge-to-tag spacing across all timeframes.

The core purpose of the script remains unchanged.
This release only adjusts label placement and does not alter the retest, scoring,
risk, or Hold Rate logic.

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

• Pocket badge anchored near its left edge
The HOLD pocket badge now sits close to where the retest actually happened, on the
left side of its pocket. This guarantees clear spacing from the right-side Target and
Invalid rail tags even on zoomed-out higher timeframes, where labels visually cover
more bars and previously still touched.

• Consistent spacing on every timeframe
The badge and rail tags now read as separate elements on lower and higher timeframes
alike, instead of only on tightly zoomed views.


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

• Removed remaining overlap between pocket badges and rail tags on higher timeframes

• Improved first-glance readability of each READY hold zone at any zoom level

• Kept every drawn zone paired with its centered badge

• Preserved the moving average, band, rails, Hold Rate, and panel unchanged


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

• Improved label spacing for a more premium presentation across timeframes

• Kept all settings, reads, and statistics exactly as before

• Enhanced overall user experience without changing core logic


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

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

Only the horizontal position of the centered pocket badge changed; scoring, the Hold
Rate, and all panel reads are unchanged.


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

The script remains a rule-based analytical tool.

Market conditions such as volatility, liquidity, and timeframe differences may affect
how retests and the Hold Rate 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.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.