Adaptive thresholds
Entry, exit and size factors that shift with volatility and trend; flat on SPY when the regimes stay neutral.
AdaptiveThresholds takes two regime codes from upstream indicators: volatility (0 low, 1 normal, 2 high) and trend (-1 down, 0 flat, 1 up). It outputs three numbers: an entry threshold, an exit threshold and a position size factor. The base values are fixed at 0.015 for entry and 0.012 for exit, then multiplied by hard-coded factors for the regime, such as 1.5 for entry in high volatility. The thresholds are small fractions near 0.01, not price levels, so the consuming rule decides what they are compared against.
How to read it
- The three lines sit in their own pane below the price, not on the candles.
- entry_threshold and exit_threshold are near 0.01 and size_factor is near 1, so the first two look flat next to the third.
- The lines only move when a regime input changes. Between changes they stay at the current levels.
- A size factor of 0.7 with entry at 0.0225 means the volatility input has flagged high volatility.
What it outputs
- Entry threshold
- Base entry threshold 0.015, scaled by volatility: x1.5 in high, x0.8 in low, x1.0 in normal. Flat at 0.015 on the sample.
- Exit threshold
- Base exit threshold 0.012, scaled by volatility (x1.3 high, x0.9 low) and trend (x1.2 up, x0.8 down). Flat at 0.012 on the sample.
- Position size factor
- Size multiplier: 0.7 in high volatility, otherwise 1.0. Trend does not change it. Flat at 1.0 on the sample.
Pitfalls
- On the sample month all three outputs were constant at 0.015, 0.012 and 1.0. Both regime inputs stayed neutral, so the indicator added no variation. Check the regime inputs before relying on it.
- The docstring promises trailing stops and quick profits when ranging. The code does neither: a flat trend leaves the exit unchanged, and the same constants apply to every symbol.
- The multipliers are hard-coded, not exposed as parameters. Changing them means editing the Python source and the matching Cython body together.