smithery/smith6jt-cop

trading-gates-pattern-filter

Pattern filter normalization and multi-gate order entry system

Installation

$ npx skills add smithery/smith6jt-cop --skill trading-gates-pattern-filter

Similar popular skills

Related neighbors and high-traction skills in the same topics — useful to compare before installing.

Also in this package

Other skills from smithery/smith6jt-cop · top by installs.

npx skills add smithery/smith6jt-cop

Browse all from smithery/smith6jt-cop

More details

Agent compatibility

Declared targets from SKILL.md / docs. Unmarked agents are not listed — the skill may still install via the CLI.

Claude Code Declared
Cursor Not declared
Codex Not declared
GitHub Copilot Not declared
Windsurf Not declared
Gemini CLI Not declared
Cline Not declared
OpenCode Not declared

Skill metadata

Parsed from SKILL.md frontmatter.

Declared agents claude-code

Package contents

Files included with this skill beyond the listing page.

  • skill md SKILL.md 5,331 B
  • docs SUMMARY.md 98 B

History

  1. First recorded snapshot · 0 installs

SKILL.md

Trading Gates & Pattern Filter - Research Notes

Experiment Overview

Item Details
Date 2025-12-18
Goal Fix pattern filter blocking all trades; add dashboard gate visibility
Environment Python 3.10, Alpaca API, Live Trading
Status Success

Problem Statement

The live trader was showing "Pattern filter rejected - no high-win-rate pattern match" for all symbols, even when the dashboard showed valid BUY/SELL signals. Investigation revealed two issues:

  1. Missing predator/prey values: getpredprey_validation() wasn't returning predator/prey values
  2. Misaligned thresholds: Pattern filter used absolute thresholds but Lotka-Volterra dynamics decay values to near-zero

Failed Attempts

Attempt Why It Failed
Lowering absolute thresholds (e.g., 0.01 instead of 0.4) Thresholds become meaningless when values vary by orders of magnitude
Using raw predator/prey values directly Values decay to 0.01-0.02, making both patterns fail
Bypassing pattern filter Defeats purpose of high-win-rate filtering

Solution: Normalized Dominance Ratios

The key insight is that while raw predator/prey values can be any magnitude, their ratio indicates regime dominance:

# In filter_by_patterns() - alpaca_trading/signals/pattern_filter.py

# Extract raw values
raw_prey = regime_context.get('prey_strength', 0.5)
raw_predator = regime_context.get('predator_strength', 0.5)

# Normalize to dominance ratios (0-1 range)
total_strength = raw_predator + raw_prey + 1e-9  # Avoid division by zero
prey_strength = raw_prey / total_strength  # Higher = more mean-reverting
predator_strength = raw_predator / total_strength  # Higher = more trending

Example

  • Raw values: predator=0.015, prey=0.17
  • Normalized: predatordominance=8%, preydominance=92%
  • Interpretation: Strong mean-reverting regime (VWAP reversion pattern applies)

Trading Gates Architecture

Orders must pass ALL gates before execution:

Gate Threshold Implementation
Confidence Adaptive (0.50-0.65) getadaptiveentry_threshold() based on GARCH regime
Pattern Filter 65% min win rate VWAP reversion (68%) OR momentum continuation (71%)
Crypto Short Block shorts detectassettype() == CRYPTO and signal < 0
Portfolio Limit <80% exposure portfoliometrics.totalexposure
Capital Manager 30% safety buffer capitalmgr.checktrade_allowed()
Portfolio Risk VaR <2% portfolioriskmgr.check_risk()

Pattern Filter Requirements

VWAP Reversion (68% win rate):

  • prey_dominance >= 0.4 (mean-reverting regime)
  • Price 2+ standard deviations from VWAP
  • Signal direction matches expected reversion

Momentum Continuation (71% win rate):

  • predator_dominance >= 0.6 (trending regime)
  • trendprobup > 0.7 OR trendprobdown > 0.7
  • Pullback in trend direction
  • Signal aligns with trend

Dashboard Gate Display

Added gate status indicators to plotsymbolsignals():

# In dashboard.py - alpaca_trading/visualization/dashboard.py

gate_statuses = symbol_signals.get('gate_statuses', [])
for i, sym in enumerate(symbols):
    gate = gate_statuses[i]
    status = gate.get('final_status', 'UNKNOWN')

    if status == 'READY':
        status_color = 'green'
        status_text = 'READY'
    elif status == 'BLOCKED':
        status_color = 'red'
        status_text = gate.get('block_reason', 'blocked')[:12]
    elif status == 'HOLD':
        status_color = 'gray'
        status_text = 'HOLD'

Key Files Modified

File Change
alpacatrading/prediction/multitf_predictor.py Added predator/prey to getpredprey_validation() return
alpacatrading/signals/patternfilter.py Normalized predator/prey to dominance ratios
alpaca_trading/executor.py Changed qty: int to qty: float for fractional shares
scripts/live_trader.py Added crypto short block, --dashboard flag
scripts/monitor_dashboard.py Added checktradinggates() function
alpaca_trading/visualization/dashboard.py Added gate status display

Verification

After fix:

  • AAPL: PASS (vwapreversion) - preydominance=92%
  • AMD: PASS (vwapreversion) - preydominance=91.9%
  • AVGO: FAIL (no_match) - SELL signal in prey-dominant regime (expects BUY)
  • BTCUSD: FAIL (cryptonoshort) - Alpaca doesn't support crypto shorts

Key Learnings

  1. Lotka-Volterra dynamics decay: Both predator and prey values decay to near-zero over time; use ratios, not absolutes
  2. Crypto limitations: Alpaca doesn't support short selling for crypto; must block SELL signals for crypto entries
  3. Fractional shares: Executor must use float qty, not int, for proper fractional share support
  4. Dashboard visibility: Showing gate status helps debug why signals don't result in orders

Related Skills

  • position-reconciliation: Broker state sync
  • markov-regime-features: Debugging constant Markov features
  • drawdown-guardrails-pattern: Drawdown control across systems