This project implements a sophisticated fractal trading analysis system that maps trade positions relative to atomic patterns (A-patterns) across multiple timeframes. The system creates comprehensive spatial-temporal datasets for neural network training to identify the most profitable trading setups.
The system is based on the principle that market structure follows fractal patterns - the same atomic building blocks (A-patterns) exist across all timeframes, but their positioning and relationships create unique market structures.
📊 TRADING ANALYSIS SYSTEM
├── 🎯 STRUCTURAL LAYERS
│ ├── 📈 Symbol + Timeframe (e.g., NQU5, 5MIN)
│ │ └── 🆔 Singular ID (S1, S2, S3...)
│ │ └── 🧩 A-Patterns (A1, A2, A3, A4, A5, A6, A12-A19)
│ │ ├── 📊 Stage 1: A1 (Consolidation/Accumulation)
│ │ ├── 📈 Stage 2: A2 (Expansion/Markup)
│ │ ├── 🛡️ Support/Resistance: A5/A6
│ │ ├── 💰 Demand/Supply: A3/A4
│ │ └── 📐 VAL/INV Grid: A14/A15 (Fibonacci)
│ └── 📚 Historical Context
│ └── 🔄 Previous Singular IDs → Current Context
│
├── 🎯 TRADE POSITIONING ANALYSIS
│ ├── 📍 Spatial Mapping
│ │ ├── 🎯 Trade Inside A-Pattern (INSIDE vs RELATIVE_TO)
│ │ ├── 📏 Distance to All A-Patterns in S-Group
│ │ ├── 🎨 Anchor Points (9 for rectangles, 3 for lines)
│ │ └── 📐 VAL/INV Grid Positioning
│ ├── ⏰ Temporal Mapping
│ │ ├── 🕐 Timing Within A-Pattern Duration
│ │ ├── 📊 Pattern Sequence Timing
│ │ └── 🔄 Historical Pattern Evolution
│ └── 📊 Performance Correlation
│ └── 💰 PnL vs Positioning Analysis
Based on the analysis system, each A-pattern represents a specific market behavior:
- A1 - Stage 1: Consolidation/Accumulation Phase
- A2 - Stage 2: Markup/Distribution Phase
- A3 - Demand: Buying Pressure Zone
- A4 - Supply: Selling Pressure Zone
- A5 - Support: Price Floor Level
- A6 - Resistance: Price Ceiling Level
- A12 - Bull S1 INV: Bullish Stage 1 Inventory/Invalidation
- A13 - Bull S1 VAL: Bullish Stage 1 Value Area
- A14 - Bull S2 INV: Bullish Stage 2 Inventory/Invalidation
- A15 - Bull S2 VAL: Bullish Stage 2 Value Area
- A16 - Bear S1 INV: Bearish Stage 1 Inventory/Invalidation
- A17 - Bear S1 VAL: Bearish Stage 1 Value Area
- A18 - Bear S2 INV: Bearish Stage 2 Inventory/Invalidation
- A19 - Bear S2 VAL: Bearish Stage 2 Value Area
- A14/A15: Create the Fibonacci grid boundaries for Stage 2 analysis
- A12/A13: Create simplified grid boundaries for Stage 1 analysis
- Purpose: Define validation and invalidation levels for trade positioning
The system analyzes patterns across multiple timeframes simultaneously:
- Higher Timeframes (HTF): Daily, 4H, 1H (market structure)
- Medium Timeframes (MTF): 30M, 15M (intermediate patterns)
- Lower Timeframes (LTF): 5M, 1M (entry/exit precision)
Daily (HTF): S1 → A1 → A2 → A3 → A14/A15 (VAL/INV)
4H (HTF): S1 → A1 → A2 → A3 → A14/A15 (VAL/INV)
1H (MTF): S1 → A1 → A2 → A3 → A14/A15 (VAL/INV)
30M (MTF): S1 → A1 → A2 → A3 → A14/A15 (VAL/INV)
5M (LTF): S1 → A1 → A2 → A3 → A14/A15 (VAL/INV)
1M (LTF): S1 → A1 → A2 → A3 → A14/A15 (VAL/INV)
Key Principle: Same A-patterns exist across all timeframes, but their positioning and relationships create unique market structures.
For each trade, the system calculates:
- Entry/Exit Retracement: Position within A-pattern price range (0.0-1.0)
- Distance from Validation: How far from upper boundary (A14/A15)
- Distance from Invalidation: How far from lower boundary (A14/A15)
- Closest Anchor Point: Which of 9 anchor points (rectangles) or 3 anchor points (lines) the trade is nearest to
- Spatial Score: Normalized positioning quality (0-1)
- Entry/Exit Time Percent: Position within A-pattern duration (0.0-1.0)
- Time Distance from Anchor: Minutes from closest anchor point
- Pattern Sequence Timing: When trade occurs relative to A1→A2→A3 sequence
- Temporal Score: Timing quality relative to pattern middle (0-1)
- Combined Score: Average of spatial and temporal scores
- Relationship Type: INSIDE (trade inside A-pattern) vs RELATIVE_TO (trade outside but analyzed against A-pattern)
- Top Row: top_left, top_center, top_right
- Middle Row: middle_left, middle_center, middle_right
- Bottom Row: bottom_left, bottom_center, bottom_right
- start: Beginning of line
- middle: Center point of line
- end: End of line
- Trade CSV: Entry/exit times, prices, PnL, contract information
- Analysis JSON: A-patterns, S-groups, VAL/INV grids across timeframes
- Data Loading: Import trade and analysis data
- Pattern Extraction: Parse A-patterns from analysis JSON
- S-Group Organization: Group A-patterns by Singular ID
- Trade Mapping: Map trades to relevant S-groups and timeframes
- Spatial-Temporal Analysis: Calculate positioning metrics for all trade-A-pattern combinations
- Feature Engineering: Create normalized metrics, scores, and categorical features
Comprehensive ML-ready dataset with:
- Core Metrics: Normalized_Change, Normalized_Bars, Pattern_Strength, Volatility_Score, Pattern_Confidence, Z_Score
- Succession Features: Has_Next_Pattern, Next_Pattern, Time_To_Next_Minutes
- S-Group Features: S_Group_Size, S_Group_Avg_Strength, S_Group_Consistency
- Fibonacci Features: Fib_Type, Fib_Level, Zone (for A1 patterns)
- Spatial-Temporal Features: Trade positioning relative to S-pattern boundaries
- Categorical Features: Symbol, Timeframe, Pattern types (one-hot encoded)
The neural network will learn to identify:
- Most Profitable Setups: Which A-pattern combinations lead to profitable trades
- Optimal Positioning: Where within VAL/INV grids to place trades
- Perfect Timing: When Stage 1→Stage 2 transitions occur
- Pattern Reliability: Z-scores and historical consistency for predictability
- Multi-Timeframe Context: How HTF/MTF/LTF alignment affects profitability
- A1/A2 Averages & Z-Scores: Current vs historical performance comparison
- Pattern Reliability: Z-score proximity indicates predictable patterns
- Breakout Timing: When Stage 1 consolidation leads to Stage 2 expansion
- Contextual Analysis: How previous S-patterns influence current setups
- Entry/Exit Recommendations: Optimal trade positioning
- Probability Scores: Win/loss likelihood
- Timing Windows: Best entry/exit times
- Pattern Recognition: Identify profitable setups
- Risk Assessment: Position sizing and management
- Stage 1 (A1): Consolidation/accumulation phase
- Stage 2 (A2): Expansion/markup phase
- Transition Timing: When A1 approaches average bar count, A2 breakout is likely
- Pattern Reliability: Z-scores close to 0 indicate predictable patterns
- Perfect positioning doesn't guarantee profits: 0.950 combined score can still result in losses
- Pattern relationships matter: Trade inside A1 but poorly timed relative to A2
- Temporal context is crucial: Trade timing relative to pattern sequences
- Multiple pattern analysis provides richer context: Single pattern analysis is insufficient
- Timeframe independence: Same A-patterns exist across all timeframes
- Timeframe relationships: Higher timeframe context influences lower timeframe decisions
- Pattern alignment: Successful trades often align across multiple timeframes
- Hierarchical importance: HTF > MTF > LTF for decision making
Trade journal/
├── analysis_dashboard.py # Main analysis application
├── data/
│ ├── trades_export (2).csv # Trade data
│ ├── trades_export (3).csv # Additional trade data
│ └── indexeddb_complete_export (1).json # Analysis patterns
├── models/ # Neural network models (future)
├── notebooks/ # Jupyter notebooks for analysis
├── trade_analysis_output/ # Generated analysis outputs
├── visualizations/ # Charts and graphs
└── README.md # This documentation
- Upload Data: Import trade CSV and analysis JSON files
- Run Analysis: Execute the dashboard to process all data
- Review Results: Examine spatial-temporal analysis and pattern metrics
- Export ML Dataset: Download comprehensive dataset for neural network training
- Train Models: Use the exported data to train profitability prediction models
- Spatial Score:
1 - (closest_anchor_price_distance / a_price_range) - Temporal Score:
1 - abs(entry_time_percent - 0.5) - Combined Score:
(spatial_score + temporal_score) / 2
- Trade Data: Must include Id, ContractName, EnteredAt, ExitedAt, EntryPrice, ExitPrice, PnL, Type
- Analysis Data: Must include A-pattern labels, chartValues, metrics, and timeframe information
- Symbol Matching: Trade ContractName must match analysis symbol for proper mapping
- Pattern Type Assumption: Currently assumes all patterns are rectangles (can be enhanced for lines)
- Timeframe Matching: Requires exact symbol/timeframe matches between trade and analysis data
- Historical Context: Limited to available analysis data (no external market context)
- Multi-Timeframe Integration: Enhanced analysis across all timeframes simultaneously
- Pattern Type Detection: Automatic detection of line vs rectangle patterns
- Historical Context: Integration with external market data for broader context
- Real-Time Analysis: Live pattern recognition and trade positioning
- Advanced ML Models: Deep learning models for pattern prediction
This fractal trading analysis system provides a comprehensive framework for understanding market structure through atomic patterns. By mapping trade positions relative to A-patterns across multiple timeframes, the system creates rich datasets for neural network training to identify the most profitable trading setups.
The key insight is that market structure follows fractal patterns - the same atomic building blocks create infinite variations through different arrangements. The neural network learns to recognize which combinations and positioning strategies lead to profitable trades within this fractal framework.