Zach's Quantum Harmonic Oscillator — Strategy by Capitalist_Zach

By Capitalist_Zach

Performance Metrics

Description

The Quantum Harmonic Oscillator script models market momentum by applying the mechanical principles of a physical spring to asset data.Financial assets frequently exhibit mean-reverting behavior, acting as if they are tethered to an average price line. Standard indicators track this distance linearly, which fails to capture the accelerating risk of a snapback as prices stretch further away from the mean.This engine implements Hooke's Law to model market tension accurately:A. The Spring Constant: Simulates market inertia and asset-specific liquidity constraints.B. Exponential Tension: Squaring the normalized displacement ensures that minor price fluctuations generate negligible energy scores, while rapid, extended vertical moves generate exponentially higher potential energy numbers.C. The Snapback Effect: By tracking the accumulation of this energy, the tool identifies the precise structural limits where market momentum exhausts itself, providing a mathematical framework to predict a rapid return to the baseline equilibrium.The engine replaces arbitrary guessing with structured, institutional-grade logic. By applying a nonlinear potential energy model U = 0.5 * k * x**2, it isolates deep structural exhaustion from normal market noise. Built-in volatility scaling, strict US session time-locking, and lookahead-free multi-timeframe filtering ensure that the data remains highly reliable and entirely optimized for real-time execution.Strategy ArchitectureThis strategy is highly functional and mathematically sound due to four distinct engineering choices in the Pine Script code:1. True Mathematical Mean Reversion (The Taylor Series Principle)In physical sciences, almost any system near a stable equilibrium naturally behaves like a harmonic oscillator because its potential energy can be approximated as a parabola. In trading, standard mean-reversion tools (like Bollinger Bands) only track linear distance from an average.- By squaring the price displacement (Δx)², the script mimics true physical tension. Small deviations generate negligible energy, while large deviations generate exponentially higher energy. This accurately isolates true structural exhaustion from routine market fluctuations.2. Strict Volatility NormalizationRaw price distance is a misleading metric because a $5 move on a quiet day means something completely different than a $5 move during a major news event.- The script divides the price displacement by standard deviation. This normalizes the system, ensuring that your extreme thresholds scale dynamically across different asset classes, market cycles, and high- or low-volatility regimes without requiring manual recalibration.3. Zero-Lookahead Multi-Timeframe Data- The code strictly specifies barmerge.lookahead_off. This ensures historical simulation data perfectly matches real-time execution, preventing the script from "looking into the future" and rendering back test results completely reliable.4. The Liquidity Control FilterExecuting mean-reversion strategies during illiquid market phases (such as pre-market, after-hours, or major holidays) often leads to massive slippage and false breakouts.- The in_session filter restricts trade entries exclusively to regular US equity trading hours (09:30 AM to 04:00 PM EST). This aligns the strategy with peak daily volume and options market liquidity, filtering out erratic overnight price action.Strategy Report & Results AnalysisThe "Unit-Based" Testing FrameworkWhen reviewing the Strategy Tester report, note that this system evaluates mathematical edge rather than an arbitrary starting balance. The back test is configured to trade exactly 1 fixed unit per signal (default_qty_value=1).- Why standard account balance metrics don't apply: Evaluating a compounding cash balance creates distortion based on when you started the back test. By focusing purely on raw unit extraction, we can analyze the pure statistical edge of the harmonic oscillator without masking performance behind capital allocation size.- How to interpret the data: Look directly at the Win Rate, Profit Factor, and Average Trade Net Profit in points or ticks. These core metrics demonstrate the system's structural advantage across changing market conditions.Performance Summary- High Win-to-Loss Efficiency: By ignoring minor market noise and only firing entries when potential energy reaches absolute mathematical limits, the strategy reduces overtrading and maximizes high-probability entries.- Controlled Drawdown Profile: Because the oscillator standardizes raw price displacement against real-time volatility, it prevents catastrophic entries during extreme, un-normalized parabolic runs.- Overnight Risk Management: While positions are permitted to hold overnight, restricting entry and exit operations strictly to liquid market windows prevents the strategy from suffering heavy slippage or execution gaps during low-volume extended hours.

Browse all 5,900+ TradingView Pine Script strategies

View on TradingView