AG Pro Auto Trendlines (MTF) - Break/Retest - Community - OSAG Pro Auto Trendlines (MTF) - Break/Retest (Community Edition • Open-Source)
OVERVIEW
AG Pro Auto Trendlines (MTF) is a rules-based market structure tool that automatically detects pivot-driven diagonal structure and renders trendlines across multiple timeframes. The primary goal is to standardize how trendline structure is identified, maintained, and interpreted—especially when you work with multi-indicator charts and need clean, consistent visuals.
This script is designed for traders who prefer a systematic approach to structure: identify meaningful swing points, connect them with repeatable rules, and track “break” and “retest” events with optional confirmations. It is not an all-in-one strategy and it does not attempt to predict markets. Instead, it provides a structured lens for trendline-based analysis in a way that reduces subjectivity and chart clutter.
COMMUNITY EDITION NOTE
This is a Community Edition release. The emphasis is on transparency, study, and repeatability. You can review the logic, learn from it, and adapt it to your own workflow within TradingView’s community standards.
WHAT THIS SCRIPT DOES (IN PRACTICAL TERMS)
Detects swing pivots and classifies structure by strength and recency.
Builds diagonal trendlines using deterministic rules.
Supports multi-timeframe (MTF) structure contexts so you can compare “local” and “higher” trendlines.
Tracks break events and (optionally) retest conditions.
Provides clean, minimal labels intended to remain readable without dominating the chart.
Offers profiles and density controls to balance information vs. simplicity.
UNIQUE EDGE (WHY IT’S NOT “JUST ANOTHER TRENDLINE TOOL”)
Many trendline indicators either (1) draw too many lines, (2) require heavy manual tuning, or (3) repaint aggressively with ambiguous rules. This script focuses on:
Rule clarity: trendlines are produced from well-defined pivots and consistent selection rules.
Structure separation: “micro / meso / mega” concept via profiles so you can choose a structural horizon.
Stability controls: optional “Locked” behavior that prioritizes interpretability over constant redraw.
Break/Retest as an interpretation layer: the script doesn’t only draw lines—it helps you observe when structure is challenged and whether price returns to test it.
DESIGN PHILOSOPHY
The chart must remain readable.
Lines must be explainable: if a line exists, the user should be able to infer “why.”
Signals should be optional and conservative (confirmation matters).
Defaults should be sensible for most liquid markets; advanced controls are available for edge cases.
METHODOLOGY (HIGH-LEVEL)
The indicator follows a simple pipeline:
A) Pivot Detection
Swing points are derived from price action using a fixed pivot logic (left/right strength).
Pivots are filtered and ranked to avoid noise dominance.
The objective is to anchor trendlines to “structure-worthy” turning points, not every minor wiggle.
B) Trendline Construction
Trendlines are formed by connecting eligible pivots under deterministic constraints.
Candidate lines are evaluated for relevance (recency / quality / interaction).
Line selection prefers clarity and avoids overpopulating the chart.
C) Multi-Timeframe Context (MTF)
The script can incorporate higher timeframe pivots/structure to contextualize local moves.
This is useful when lower timeframe price action is reacting to higher timeframe diagonals.
D) Break / Retest Interpretation Layer
A “break” is detected when price meaningfully violates a trendline under the chosen confirmation rule.
A “retest” is detected when price returns to the broken/active structure zone under a defined proximity logic.
Retest logic is optional and can be configured for conservative behavior.
SIGNALS & EVENTS (WHAT THE LABELS MEAN)
This tool is primarily visual, but it can optionally expose events as alerts depending on your configuration. Common event types:
Active Structure:
* A trendline currently considered valid/active according to the selection and stability rules.
Break:
* Price crosses the trendline in a direction that violates the prior structural role.
* Important: break significance depends on your confirmation setting (see below).
Retest (Optional):
* After a break, price revisits the trendline zone.
* Retest is often a “context event,” not a guaranteed entry. Many retests fail or overshoot.
CONFIRMATION MODES (WHY “CLOSE” VS. INTRABAR MATTERS)
A frequent source of confusion is whether a break should trigger on:
Intrabar touch/cross (more responsive, but noisier), or
Bar close confirmation (slower, but usually cleaner).
If you enable Close confirmation:
Break labels/events wait for the candle to close beyond the line (reduces whipsaws).
Retest logic typically becomes more meaningful because the break is “confirmed” by closing data.
If you use intrabar logic:
You will see earlier breaks, but expect more false positives in choppy regimes.
PROFILES (MICRO / MESO / MEGA)
Profiles are intended as “structural horizon presets.” Exact behavior depends on the internal pivot strengths and selection constraints, but conceptually:
Micro: short-horizon structure, more reactive, suitable for active monitoring.
Meso: balanced structure, typically a good default for swing structure.
Mega: longer-horizon structure, fewer but more dominant lines.
If you feel “too many lines,” reduce density or move up the horizon (Micro → Meso → Mega).
If you feel “not enough information,” increase density or move down the horizon (Mega → Meso → Micro).
DENSITY / CLEANLINESS CONTROLS
The indicator includes controls intended to keep the chart usable:
Density (Balanced / Cleaner / Fuller): adjusts how aggressively lines are filtered.
Replace vs. Keep behavior: controls whether new lines replace old ones as structure evolves.
Locked mode: prioritizes stability and reduces frequent redraw behavior.
A practical approach:
Start with Balanced density and Locked mode.
If you want more responsiveness, reduce locking or increase density gradually.
If you want a presentation-quality chart, prioritize locking and cleaner density.
HOW TO USE (WORKFLOWS)
Workflow 1 — “Structure First, Indicators Second”
Apply the script with defaults.
Identify dominant diagonals (especially higher timeframe context).
Add your favorite momentum/volume tool only after structure is clear.
Use breaks/retests as context to interpret indicator signals (not as stand-alone triggers).
Workflow 2 — “MTF Bias + Execution Timeframe”
Use a higher timeframe (e.g., 4H / 1D) context in the script.
Execute on a lower timeframe (e.g., 15m / 1H) while respecting higher timeframe diagonals.
A lower timeframe signal against a higher timeframe trendline is not “wrong,” but it is higher risk.
Workflow 3 — “Break-Then-Retest Observation”
Focus on clean breaks using Close confirmation.
Observe whether price returns to retest the level.
Track the retest outcome to understand regime shifts (trend continuation vs. transition).
IMPORTANT NOTES ABOUT INTERPRETATION
Trendlines are not magic levels. They are a structured representation of diagonal support/resistance.
In ranging markets, trendline breaks occur frequently and are less informative.
In trending markets, diagonal structure is often respected, but overshoots and volatility spikes happen.
Retests are context events. A retest can fail, succeed, or become a consolidation zone.
TRANSPARENCY & LIMITATIONS
1. Not a strategy / not a signal guarantee
This script does not promise profitability and should not be interpreted as a predictive system. It provides structure visualization and optional event labeling.
2. MTF limitations
MTF data is derived from higher timeframe aggregation. Depending on the symbol/session and chart conditions, the exact appearance can differ across timeframes. This is expected behavior in MTF analysis.
3. Pivot-based structure is inherently lagging
Pivots require a certain number of bars to confirm. This is the trade-off for structure quality. Faster pivots increase noise; slower pivots increase lag.
4. Structural redraw behavior
Even with stability controls, structure can evolve as new pivots form. “Locked” behavior helps, but no structure tool can freeze reality without losing relevance.
5. Alerts are context, not execution
If you enable alerts, treat them as notifications to review context, not as automatic trade triggers.
PERFORMANCE NOTES
This script is designed with multi-indicator chart usability in mind:
Visual output aims to be minimal and readable.
Defaults are chosen to avoid excessive object spam.
If you increase density and enable many features simultaneously, object counts and chart load can increase.
Recommended: tune step-by-step and keep only what you actively use.
FAQ
Q: Why do I sometimes see fewer lines than expected?
A: The selection filters prioritize “structure-worthy” lines. Increase density, reduce locking, or use a more reactive profile.
Q: Why did a line change?
A: A new pivot can shift the best-fit structural representation. Use Locked mode if you prefer stability.
Q: Which timeframe should I use?
A: Many users find 1H–4H best for structure clarity. If you scalp, use Micro profile with more conservative confirmation.
Q: Can this replace horizontal support/resistance?
A: No. Diagonal structure complements horizontal levels. Many meaningful areas are a confluence of both.
RISK DISCLOSURE
Trading involves risk. Past market behavior does not predict future results. Trendlines, breaks, and retests can fail, overshoot, or reverse abruptly—especially during high volatility, news events, low liquidity periods, and regime transitions. Always use risk management, position sizing discipline, and confirm structure with broader context.
NOT FINANCIAL ADVICE
This indicator is provided for educational and informational purposes only and does not constitute financial advice, investment advice, or a recommendation to buy or sell any instrument.
CHANGELOG (SUMMARY)
V7.x: Community Edition packaging, cleaner HUD, stability-focused defaults, and clearer break/retest presentation.
Focus: readability, rule clarity, and low-clutter output for real-world charts.
อินดิเคเตอร์ Pine Script®






















