OPEN-SOURCE SCRIPT

Dynamic Gravity Attractor (DGA) [MarkitTick]

1 438
💡 An advanced technical indicator designed to identify, weight, and visualize significant price zones using a physics-inspired gravitational model. By treating historical price pivots as physical masses that exert gravitational pull on the current price, this tool dynamically highlights levels of high structural importance. This offers traders a unique, quantitative perspective on support, resistance, and the overarching market equilibrium based on continuous volume and touch data.

✨ Originality and Utility

Unlike standard static support and resistance indicators that simply draw horizontal lines at arbitrary swing highs and lows, this system introduces a dynamic, weighted engine based on volume execution and touch frequency.

Traditional indicators often clutter the chart with dozens of obsolete lines. This tool resolves the issue by clustering proximate price levels using an Average True Range based spatial resolution. This synthesizes fragmented levels into cohesive, highly actionable Gravity Zones.

The core utility lies in its ability to quantify the relative strength of these zones using a gravitational constant. Instead of merely sorting by recency, it sorts by actual structural pull. This allows traders to cleanly distinguish between minor intraday speed bumps and major macroeconomic price attractors that have a high probability of influencing future price routing.

🔬 Methodology and Concepts
istantanea
The script operates on a robust foundation of interconnected logical pillars, ensuring a precise reading of historical market structure:

  • • Pivot Detection and Clustering: The indicator identifies standard non-repainting pivot highs and lows using a defined lookback window. Instead of plotting each pivot individually and causing chart noise, it evaluates if a new pivot falls within an existing cluster radius. This radius is dynamically determined by a user-defined percentage of the 14-period Average True Range. If a match is found, the cluster aggregate price, volume, and touch count are updated using a volume-weighted average formula.
  • • Mass Calculation: Each clustered zone is assigned a quantitative mass. This mass is a blended metric derived from the total trading volume transacted at that specific level and the frequency of price touches it has endured. Users can dynamically adjust the weighting of these two components to favor volume-heavy execution levels or frequently tested psychological levels.
  • • Gravitational Pull: Applying a concept directly akin to classical physics, the indicator calculates the gravitational force of each active zone relative to the current closing price. The formula incorporates the zone calculated mass, a user-defined Gravitational Constant, and the inverse square of the absolute distance between the zone and the current price.
  • • Net Force and Equilibrium: By aggregating the gravitational pull of all active zones above the current price and subtracting the zones below, the script calculates a continuous Live Net Force. This net force dictates the overall directional bias of the underlying market structure.


🎨 Visual Guide
istantanea
The tool provides a rich, multi-layered visual experience, utilizing dark-mode optimized palettes to allow traders to interpret complex market structures at a rapid glance:

  • • Gravity Zone Lines: Horizontal lines representing the clustered price levels. The strongest mathematical attractor is plotted with a solid line, while weaker zones use dashed line styles to indicate secondary importance. The thickness of the line directly correlates with its top-ranking status.
  • • Zone Colors: Levels situated above the current price are colored in a visual gradient from vibrant purple to deep violet, representing resistance or overhead gravity. Levels situated below are colored in a gradient from yellow to dark orange, representing support or underlying gravity. The color intensity and opacity scale dynamically with the calculated mass of each zone.
  • • Gravity Fields (Halos): Semi-transparent background boxes surrounding the strongest top-ranked gravity zones. The vertical height of the box represents the zone mathematical sphere of influence, calculated using the true range and the zone specific mass.
  • • Gravity Center: A distinct dotted cyan line plotting the weighted center-of-mass between the strongest overhead attractor and the strongest underlying attractor. This acts as the market current fulcrum.
  • • Dynamic Labels: Textual tags attached to the right of the gravity lines. These indicate the exact price level, an arrow denoting if the force is pushing up or down, and a percentage representing its gravitational strength relative to the maximum active zone.
  • • Heatmap Candles: The main chart candles are recolored based on the Live Net Force. A bullish bias paints the candles in a specific underlying color, while a bearish bias paints them in an overhead color. Border and wick colors adapt similarly to show micro-shifts in pressure.
  • • Gravity Dashboard: A comprehensive on-chart data table displaying the active number of tracked levels, the exact prices of the top upper and lower attractors, the Net Force bias, the current cluster size, and a visual block-bar representation of the highest active mass percentage.


📖 How to Use
istantanea
  • • Trend Identification: Observe the Heatmap Candles and the Net Force metric on the Gravity Dashboard. A sustained bullish color bias suggests the price is being pulled upward by a stronger overhead attractor or violently pushed from a massive underlying support base. Traders should look to align their directional trades with this dominant net force.
  • • Targeting and Exits: Use the strongest Gravity Zone Lines as primary profit targets or areas to scale out of positions. Because these zones possess high mass, price tends to inevitably gravitate toward them over time.
  • • Entry Confirmation: Wait for the price to enter a Gravity Field. If price action demonstrates rejection patterns, long wicks, or volume anomalies within these specific halo zones, it provides a high-probability entry for mean-reversion trades.
  • • Equilibrium Trading: The Gravity Center line represents a literal point of balance between the primary opposing structural forces. Observing the price crossing, retesting, and holding this level can indicate a fundamental shift in structural control from sellers to buyers, or vice versa.
  • • Automated Alerts: The script includes built-in alert conditions for when the price comes within a tight proximity to the strongest above or below zones. It also fires alerts when the overall Net Force shifts direction. All alerts and webhooks are constructed as strictly formatted JSON strings designed for flawless third-party execution, dynamically calculating and including the Entry Price, the precise Take Profit target, and the exact Stop Loss invalidation price.


⚙️ Inputs and Settings
istantanea
  • • History Depth (bars): Determines how far back in time the script looks to evaluate active pivots. A higher number tracks long-term macro zones, while a lower number focuses on immediate intraday structure.
  • • Number of Gravity Zones: Limits the maximum number of attractor lines drawn on the chart to prevent visual clutter.
  • • Level Cluster Resolution (ATR%): Controls how closely pivots must be to merge into a single, heavier zone. A higher value aggregates more historical levels together, creating fewer but stronger zones.
  • • Gravitational Constant G: A mathematical multiplier that scales the overall gravity calculations. Adjusting this tweaks the sensitivity of the Net Force output.
  • • Mass Components (Volume & Touch Weight): Fractional sliders allowing the user to adjust whether a zone mass is more heavily derived from transacted volume or the sheer number of times the price has historically tested the level.
  • • Minimum Touch Count: The baseline number of times a price level must be tested before it is officially registered as having enough mass to generate gravity.
  • • Visual Settings: Comprehensive toggles to independently turn lines, text labels, halo fields, the dashboard table, and center-of-gravity boxes on or off according to individual visual preference and chart cleanliness. All colors are fully user-configurable without hardcoding.


🔍 Deconstruction of the Underlying Scientific and Academic Framework

The tool borrows directly from classical mechanics, specifically the law of universal gravitation, to mathematically model financial market microstructure. In standard physics, the attractive force of gravity between two independent objects is directly proportional to the product of their masses and inversely proportional to the square of the distance between their centers.

In the context of this script, the current market closing price acts as a dynamic point mass navigating a static field of larger, stationary masses, representing the historical support and resistance clusters. The script operationalizes this concept by calculating Mass as a composite statistical index of cumulative trading volume and historical test frequency. Volume acts as the density of the price level, representing committed capital and trapped liquidity, while touch frequency represents the psychological reinforcement and memory of the level among market participants.

By rigidly utilizing the inverse square law of distance, the indicator mathematically guarantees that nearby price levels exert exponentially more influence on current price action than distant levels. This accurately reflects the highly localized nature of market liquidity, order book depth, and slippage. Furthermore, the clustering algorithm employs a dynamic threshold based on Average True Range, introducing a volatility-normalized spatial resolution. This specific mechanism ensures that the radius of a mass point expands in highly volatile environments and contracts in tight consolidations, strictly adhering to established principles of adaptive signal processing, robust statistical smoothing, and dynamic time warping.

⚠️ Disclaimer
All provided scripts and indicators are strictly for educational exploration and must not be interpreted as financial advice or a recommendation to execute trades. We expressly disclaim all liability for any financial losses or damages that may result, directly or indirectly, from the reliance on or application of these tools. Market participation carries inherent risk where past performance never guarantees future returns, leaving all investment decisions and due diligence solely at your own discretion.

Declinazione di responsabilità

Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.