Systematic Deviation Harvester — Strategy by Capitalist_Zach

By Capitalist_Zach

Performance Metrics

Description

The Systematic Deviation Harvester is a structural asset accumulation engine designed to exploit extreme peak-to-trough price dislocations. Instead of relying on mathematical oscillators or moving averages, this strategy isolates pure structural alpha by measuring real-time percentage contractions from a rolling annual high-water mark.Operating strictly on a daily resolution, the system treats deep market corrections as mathematical discounts, mechanically scaling into assets during cascading sell-offs and liquidating the aggregate basket via a unified trailing profit target.🏛️ Core Algorithmic Pillars1. Trailing High-Water Mark EngineThe system maintains a rolling, state-retaining benchmark of the asset's structural peak.- Annual Anchor: At the open of the first trading bar of each calendar year, the benchmark resets to prevent structural anchoring bias.- Peak Registration: If the market prints a higher high during the year, the benchmark dynamically adjusts to the new ceiling, resetting the downside calculation logic.2. Asymmetric Scale-In MatrixWhen market panic drives price away from the annual ceiling, the engine deploys capital across two independent structural tiers. While the strategy permits position stacking over time, an internal state machine prevents over-exposure or execution spam:- Alpha 1 Allocation (Minor Drop): Triggers an initial capital deployment (e.g., 5% of account equity) when price crosses the secondary correction threshold.- Alpha 2 Allocation (Major Drop): Triggers a heavier, secondary capital deployment (e.g., 10% of account equity) only if a systemic liquidation cascades into deep discount territory.3. State Interlocks & Re-Armament HandlersTo prevent the engine from repeatedly buying into a declining market on consecutive bars, the strategy utilizes strict execution flags (minor_triggered and major_triggered). Once a tier is filled, it is locked. The engine governs its multi-cycle stacking through two user-selectable reset rules:- Clean Slate Mode (Standard): Entry flags remain completely locked until a trailing exit is achieved and total position exposure reads exactly zero. Once flat, the entry flags clear for a fresh cycle.- Rally Reset Mode (Optional): Clears the entry locks mid-cycle if the market stages a significant recovery rally from its local bottom (e.g., drawdown shrinks back to 1%). This allows the engine to unlock the entry tiers and stack new positions if the market rolls over again before hitting a full profit take.4. The Omega Master ExitPosition liquidation is never managed on an individual trade level. Instead, the strategy treats the compounded portfolio as a unified basket:- Composite Average Price Tracker: The engine continuously tracks the volume-weighted average cost base across all active scale-in tiers.- Tick-Precision Trailing Stop: Once the market rallies past a specified percentage above the composite average cost, the engine activates a trailing stop. It converts percentage parameters into discrete price ticks (syminfo.mintick) to trail the macro-recovery, capturing maximum extension while protecting capital against sudden re-tests of the lows.⚙️ Interface Parameters & Customization- Drawdown Thresholds: User-definable percentage boundaries for minor/major entry triggers and recovery reset thresholds.- True Compounding Sizing: Dynamic capital sizing that computes exact share counts based on real-time equity fluctuations rather than static cash values.- Unified Compounding Exit: Custom configurations for trailing activation thresholds and peak-to-exit retraction steps.🚀 Setup & Deployment Guide1. Timeframe Selection: Open a clean chart and explicitly set the resolution to Daily (1D).2. Apply Engine: Add the script to your chart. The baseline metrics are pre-configured for broad market index equity tracking.3. Calibrate Thresholds: Open the inputs settings panel. For high-volatility large-caps, expand the Minor Drop and Major Drop fields proportionally to accommodate wider structural swings.4. Select Risk Profile: Choose your exposure rule. Toggle Enable Rally Reset Rule ON for aggressive, high-frequency compounding, or leave it OFF for conservative, single-cycle wave trading.📊 Methodological Constraints (Read Before Backtesting)- Timeframe Enforced: Designed and structurally locked to the Daily (1D) interval. Intraday testing will render calculation flags inactive.- Backtest Fidelity: Built using process_orders_on_close = true. This prevents the "look-ahead" backtesting bias common in default script architectures by ensuring orders are strictly filled at the confirmed closing print of a daily candle.🏁The Systematic Deviation Harvester is engineered strictly for high-conviction, structural bull-market assets that exhibit long-term macro growth profiles. Because the architecture relies entirely on scaling into deep price contractions relative to annual benchmarks, its structural alpha depends heavily on the underlying asset eventually recovering and charting new highs. It should be deployed exclusively on resilient, secularly expanding markets, such as major index ETFs or high-conviction large-cap equities, where deep corrections represent clear mathematical discounts rather than terminal structural decay.Release NotesThis update corrects the strategy logic to make the script execute exactly as it was originally intended to work.- Fixed Rally Reset Function: Corrected the rule so it no longer wipes old entry flags too early. It now properly monitors the specific recovery percentage set in the configuration panel before unlocking the final deep buy tier (α3).- Automated Sizing Math: Completely automated the α3 entry target and capital allocation based on primary inputs (α1 + α2), removing unnecessary settings.Dynamic Profit Targets: Enhanced the exit engine so the profit target automatically expands when deeper buy tiers are triggered, keeping the risk-to-reward ratio balanced.- Updated Visuals: Added an orange line to track the deep drawdown threshold and background colors to show when Phase 2 is active.

Browse all 5,900+ TradingView Pine Script strategies

View on TradingView