Ultimate Lorentzian Classification — Strategy by greymyst

By greymyst

Performance Metrics

Description

1. The Machine Learning Engine (K-Nearest Neighbors)Instead of relying on fixed crossovers (like a standard MACD), the core of this strategy uses a machine learning algorithm called K-Nearest Neighbors (k-NN) combined with a mathematical formula called the Lorentzian Distance Metric.Feature Engineering: Every time a new bar prints, the algorithm takes a "snapshot" of the market using 5 distinct features: RSI (momentum), WaveTrend (oscillation), CCI (cyclical trend), ADX (trend strength), and MFI (volume-weighted flow).Finding the Neighbors: It takes this snapshot and compares it against a rolling historical dataset of the last 200 bars. Using the Lorentzian formula, it calculates the "distance" (or similarity) between the current market condition and every single past condition.The Vote (Prediction): It isolates the 8 most similar historical moments (the 8 Nearest Neighbors). It then looks at what actually happened after those historical moments—did the price go up or down? The neighbors cast a "vote." If the majority of similar past setups resulted in a pump, the model turns Bullish. If they dumped, it turns Bearish.2. The Confluence FiltersJust because the ML model predicts a move doesn't mean it's a safe trade. To prevent getting chopped up, the raw prediction must pass a strict gauntlet of filters:Trend Filter (EMA Baseline): The strategy will only accept a ML "Buy" vote if the current price is above the 200-period EMA (an established uptrend). Conversely, it will only short if the price is below the EMA.Volatility Filter (ATR Expansion): The strategy checks the Average True Range (ATR). It will only execute a trade if the current ATR is surging higher than its recent average (specifically, 1.5x higher). This ensures the strategy only buys into violent, expanding moves (like a volatility squeeze firing off) and ignores boring, sideways chop.3. Trade Execution & Risk ManagementWhen the ML Prediction, the Trend Filter, and the Volatility Filter all perfectly align, a signal is generated.Entry: The script triggers strategy.entry() to automatically buy or short the asset using your predefined capital sizing.Dynamic Targets: The exact moment the trade opens, it calculates a Stop Loss (SL) and Take Profit (TP) dynamically based on the current ATR (volatility).Example: If the market is moving wildly, your SL and TP will be placed wider to let the trade breathe. If the market is moving slowly, the SL and TP will be placed tighter.Exit: It submits a strategy.exit() bracket order. The position will ride out automatically until price either hits your Take Profit target for a win, or your Stop Loss target for a loss.

Browse all 5,900+ TradingView Pine Script strategies

View on TradingView