0000 Kalman Trend Levels W D STRAT v9 — Strategy by shitholed
By shitholed
Performance Metrics
- Author: shitholed
- Symbol: NASDAQ:IXIC
- Timeframe: 1 day
- Net P&L: +564,924,166.78 USD (+56,492.42%)
- Win Rate: 36.8%
- Profit Factor: 2.697
- Max Drawdown: 73,511,893.00 USD (19.09%)
- Total Trades: 223
Description
Strategy Overview: Kalman Trend Levels (v9)This Pine Script (v6) strategy is a trend-following system that utilizes dual Kalman filters to determine market direction. It features dynamic position sizing, built-in risk management, and a highly advanced performance dashboard capable of calculating annualized metrics (CAGR, Sharpe, Sortino) accurately across any timeframe, including intraday charts.1. Trend Detection (Kalman Filters)The core of the strategy relies on a custom implementation of a Kalman Filter, which smooths price data by mathematically estimating the underlying trend and filtering out random market noise.Short & Long Filters: The system calculates a fast (short_len) and a slow (long_len) Kalman line using adjustable process and measurement noise variables (kalman_q and kalman_r).Trend Direction: A bullish trend is identified when the short Kalman line crosses above the long Kalman line. Conversely, a bearish trend occurs when the short line drops below the long line.Visuals: The chart dynamically colors the candles and plots upper/lower structural boundary boxes based on trend shifts. It also includes an optional retest logic to highlight when the price pulls back to test these established boxes.2. Position Sizing & Cash ManagementThe strategy actively manages risk through its quantity calculation. It dynamically sizes positions to utilize exactly 50% of the current equity (strategy.equity * 0.50). This intentional sizing ensures that the remaining 50% of the portfolio is kept securely in cash, leaving it completely untouched and protected from market exposure.The system supports both long-only and bi-directional (long and short) trading modes.3. Risk Management & ExecutionSeveral optional safety mechanisms are built into the execution logic:Stop Loss & Take Profit: Percentage-based exit targets can be toggled on or off to protect capital and secure gains automatically.Cooldown Filter: To prevent overtrading or immediate re-entries during choppy, sideways price action, a cooldown timer (cd_bars) blocks new entry signals for a specified number of bars immediately after a trade is closed.4. Advanced Intraday Performance DashboardThe script features a comprehensive, on-chart table comparing the strategy's real-time performance against a standard Buy & Hold approach.Timestamp-Based Annualization: Instead of relying on a static assumption of trading days per year, the script calculates the exact time elapsed using Unix timestamps in milliseconds. This guarantees that time-dependent metrics like the Compound Annual Growth Rate (CAGR) remain mathematically flawless, even when the script is applied to 1-minute or 5-minute intraday charts.Tax Adjustments: The dashboard calculates realistic net returns by automatically deducting a configurable tax rate (defaulting to 18.5%) from the gross performance.Risk-Adjusted Metrics: The script iteratively tracks the variance of returns at every bar close. This enables the calculation of professional risk-adjusted performance ratios on the fly:Sharpe Ratio: Measures the annualized return relative to the total volatility of the strategy.Sortino Ratio: Isolates and penalizes only the downside volatility, providing a clearer picture of the actual risk of loss.Calmar Ratio: Compares the annualized performance directly against the maximum historical drawdown.