1. The Market Philosophy¶
This script operates on a Momentum Prediction philosophy, leveraging the principle of historical analogy. Its core thesis is that identifiable, multi-dimensional market patterns precede short-term directional price movements. Rather than following an existing trend, it seeks to forecast its inception. The strategy is built on the assumption that market behavior, while complex, is not entirely random. Specific “fingerprints”—defined by a confluence of oscillatory and mean-reversion metrics—repeat over time. By identifying a current market state that is statistically analogous to past states that led to momentum bursts, the model aims to capture alpha by anticipating the next directional impulse before it becomes obvious to the broader market.
2. The Trade Narrative¶
The ideal setup for this strategy is not a simple visual pattern but a specific quantitative signature. The script is waiting for the market to exhibit a unique “character” across multiple timeframes. This narrative unfolds as the relationship between various short, medium, and long-term RSI values, combined with price deviations from their respective moving averages, aligns into a formation that the model recognizes. The script is essentially looking for a moment where the market’s internal dynamics—its speed, acceleration, and reversionary tension—match a historical precedent that has a high probability of resolving into a bullish or bearish move within the next few bars. It’s a data-driven form of tape reading, searching for the quiet prelude to a price cascade.
3. Trigger Logic & Mechanics¶
The strategy’s engine is a K-Nearest Neighbors (KNN) model that translates a complex market state into a simple probability.
Why these indicators? The script constructs a rich “feature vector” using multiple RSI and MA-deviation periods to capture a holistic view of market momentum and reversionary pressure. This multi-faceted approach provides a more robust snapshot than any single indicator. The optional PCA (Principal Component Analysis) further refines this by compressing the features, aiming to enhance the signal-to-noise ratio by isolating the most impactful market dynamics.
How do filters serve? The primary filter is the
prob_threshold. By requiring a high confidence score (e.g., 90%) from the weighted KNN vote, the model aggressively filters out ambiguous or low-conviction setups. This is designed to improve precision at the cost of frequency. The external EMA acts as a secondary, discretionary filter, allowing the trader to contextualize the signal as either pro-trend (higher probability) or counter-trend (higher risk).The Catalyst: The trigger is a purely quantitative event. The script flips from “observing” to “executing” the moment the model’s calculated probability for a directional move—based on a weighted consensus of historically similar patterns—crosses the predefined confidence threshold. This crossover signifies that the current market state has achieved statistical significance as a precursor to momentum.