# LLM Market Detector - AI-Powered Market State Analysis

**Last Updated**: 2026-03-17
**Version**: 1.0.0

## How It Works

### Open LLM Market Detector

Navigate to the LLM Market Detector page from the strategy builder menu. This module uses large language models to classify current market conditions as trending, ranging, or volatile based on multi-timeframe price action analysis.

### Select a Configuration Preset

Choose from three built-in presets: Conservative (higher confidence thresholds, fewer but more reliable signals), Balanced (moderate sensitivity for general use), or Aggressive (lower thresholds for maximum signal frequency). Each preset adjusts batch size, warmup period, and lookback bars automatically.

### Fine-Tune Advanced Parameters

Expand the Advanced Configuration panel to manually adjust prediction batch size (how many bars the LLM processes per cycle), warmup period (minimum bars before first prediction), lookback bars (historical context window), and analysis interval (frequency of re-evaluation).

### Customize the Analysis Prompt

Edit the Analysis Prompt section to refine how the LLM interprets market conditions. You can instruct the model to weight specific indicators, prioritize certain timeframes, or focus on particular market microstructure signals for more targeted detection.

### Set the Default Fallback State

Configure the fallback market state (TREND, RANGE, or UNDEFINED) that the system uses when the LLM analysis is unavailable or returns inconclusive results. This ensures your downstream strategy always receives a valid market state signal.

### Generate Market Detection Strategy

Click the Generate Strategy button to compile your configuration into executable market detection code. The system sends your parameters and prompt to the LLM provider, which returns a structured detection algorithm tailored to your specifications.

### Review and Integrate the Output

Examine the generated detection code in the output panel. Verify the logic matches your expectations, then integrate it into your trading workflow. The market state output (TREND/RANGE) feeds directly into the Entry Signal Builder and Exit Strategy Builder for regime-adaptive strategies.

> The LLM Market Detector uses artificial intelligence to classify market conditions in real time. Detection accuracy depends on the quality of your prompt configuration and the underlying LLM model selected in your account settings.

## Tips & Best Practices

- Start with the Balanced preset and run several backtests before switching to Aggressive. Lower confidence thresholds generate more signals but also more false positives, which can erode returns through excessive trading.

- Set the lookback bars to at least 2x your typical holding period. If your strategy holds positions for 20 bars on average, a lookback of 40-60 bars gives the LLM sufficient context to detect regime shifts before they impact your open positions.

- Include specific indicator references in your analysis prompt (e.g., 'weight ADX above 25 as strong trend confirmation') to guide the LLM toward more actionable and consistent market state classifications.

- Use the UNDEFINED fallback state during initial testing rather than defaulting to TREND or RANGE. This makes it easy to identify in backtest results exactly when the LLM failed to classify, helping you refine your prompt iteratively.

## Frequently Asked Questions

### What market states does the LLM Market Detector classify?

The detector classifies markets into three states: TREND (sustained directional movement with momentum), RANGE (sideways consolidation between support and resistance), and UNDEFINED (transitional or ambiguous conditions). Each state can trigger different entry and exit logic in your downstream strategy modules.

### How do the three presets differ in practical terms?

Conservative uses a large lookback window (80+ bars) and high confidence threshold, producing fewer regime change signals but with higher accuracy. Balanced uses moderate settings (40-60 bars lookback) suitable for most strategies. Aggressive uses a short lookback (20-30 bars) and low threshold, detecting regime changes quickly but with more false signals. Choose based on your strategy's sensitivity to regime misclassification.

### What happens when the LLM API call fails or times out?

When the LLM analysis fails, the system automatically applies your configured fallback state (TREND, RANGE, or UNDEFINED). The failure is logged, and your strategy continues operating without interruption. The detector retries on the next analysis interval cycle. Persistent failures may indicate LLM provider issues or API credit exhaustion.

### Which LLM provider and model does the detector use?

The detector uses whichever LLM provider and model you have configured in your account settings. The request includes your analysis prompt and the market data context window. Different models may produce varying classification quality, so test your prompt with your specific provider before integrating into your backtested strategies.

## Important Notes

> LLM-based market detection is probabilistic and not guaranteed to be accurate. AI predictions depend on model quality, prompt design, and market data availability. Each LLM API call consumes credits from your account. Always validate detection results through comprehensive backtesting before relying on them in any strategy.

---

Source: https://stratcraft.ai/help/llm-market-detector/