Market mode
Download scriptThe "Market Mode" indicator is designed to help traders identify the underlying structural state of a financial market by filtering out "noise" and highlighting significant price movements. It does this through a multi-step mathematical process that smooths out price action to reveal primary trends, peaks, and valleys.
Here is a breakdown of how the logic works:
1. Price Smoothing (Bandpass Filtering)
The script begins by taking raw market data (such as the Median Price) and applying a "Bandpass Filter." Think of this like a radio tuner: it filters out high-frequency "static" (minor, insignificant price flickers) and low-frequency "background hum" (very slow, long-term trends) to focus on the relevant intermediate market movements. This creates a smoother line that represents the "true" momentum of the asset.
2. Peak and Valley Detection
Once the price is smoothed, the logic scans the data to identify specific structural turning points:
- Peaks: The script identifies local highs where the smoothed price reaches a summit before turning downward.
- Valleys: Conversely, it identifies local lows where the price bottoms out before moving upward.
3. Accumulation and Summation
Instead of looking at single peaks or valleys in isolation, the script maintains a "rolling sum" of these points over a specific window of time:
- Sum of Peaks: It calculates the total weight of all recent highs.
- Sum of Valleys: It calculates the total weight of all recent lows.
- Bandpass Sum: It maintains a running total of the smoothed price movement over a set period.
4. Market Mode Calculation
The final logic uses these three components to determine the "Mode" of the market:
- Trend Strength: It compares the current smoothed momentum against the historical averages of its peaks and valleys.
- Dynamic Thresholds: The script calculates an upper and lower boundary (fractions) based on the average height of the peaks and the depth of the valleys.
5. Visual Output
The indicator translates these complex calculations into a visual "Mode" code:
- Bullish Signal: If the current market momentum exceeds the calculated "Peak" threshold, it indicates a strong upward state.
- Bearish Signal: If the current market momentum falls below the "Valley" threshold, it indicates a strong downward state.
- Neutral State: If the price is drifting between these two thresholds, it is treated as a consolidation or neutral zone.
In short, this script acts as a sophisticated "filter" that tells you whether the market is currently pushing strongly in one direction or if it is simply hovering in a neutral range, by mathematically balancing current momentum against previous structural highs and lows.
ÿþ/ / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# p r o p e r t y c o p y r i g h t "