Skip to content

Jakers471/Trade-Journal-V1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fractal Trading Analysis System

Overview

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.

System Architecture

Core Concept: Fractal Pattern Recognition

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.

Hierarchical Structure

📊 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

A-Pattern Definitions

Atomic Pattern Types

Based on the analysis system, each A-pattern represents a specific market behavior:

  1. A1 - Stage 1: Consolidation/Accumulation Phase
  2. A2 - Stage 2: Markup/Distribution Phase
  3. A3 - Demand: Buying Pressure Zone
  4. A4 - Supply: Selling Pressure Zone
  5. A5 - Support: Price Floor Level
  6. A6 - Resistance: Price Ceiling Level
  7. A12 - Bull S1 INV: Bullish Stage 1 Inventory/Invalidation
  8. A13 - Bull S1 VAL: Bullish Stage 1 Value Area
  9. A14 - Bull S2 INV: Bullish Stage 2 Inventory/Invalidation
  10. A15 - Bull S2 VAL: Bullish Stage 2 Value Area
  11. A16 - Bear S1 INV: Bearish Stage 1 Inventory/Invalidation
  12. A17 - Bear S1 VAL: Bearish Stage 1 Value Area
  13. A18 - Bear S2 INV: Bearish Stage 2 Inventory/Invalidation
  14. A19 - Bear S2 VAL: Bearish Stage 2 Value Area

VAL/INV Grid System

  • 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

Multi-Timeframe Analysis

Timeframe Hierarchy

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)

Fractal Consistency

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.

Spatial-Temporal Analysis

Trade Positioning Metrics

For each trade, the system calculates:

Spatial Analysis

  • 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)

Temporal Analysis

  • 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 Metrics

  • 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)

Anchor Point System

Rectangle Patterns (9 anchor points)

  • Top Row: top_left, top_center, top_right
  • Middle Row: middle_left, middle_center, middle_right
  • Bottom Row: bottom_left, bottom_center, bottom_right

Line Patterns (3 anchor points)

  • start: Beginning of line
  • middle: Center point of line
  • end: End of line

Data Flow

1. Input Data

  • Trade CSV: Entry/exit times, prices, PnL, contract information
  • Analysis JSON: A-patterns, S-groups, VAL/INV grids across timeframes

2. Processing Pipeline

  1. Data Loading: Import trade and analysis data
  2. Pattern Extraction: Parse A-patterns from analysis JSON
  3. S-Group Organization: Group A-patterns by Singular ID
  4. Trade Mapping: Map trades to relevant S-groups and timeframes
  5. Spatial-Temporal Analysis: Calculate positioning metrics for all trade-A-pattern combinations
  6. Feature Engineering: Create normalized metrics, scores, and categorical features

3. Output Dataset

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)

Neural Network Training Objectives

Learning Goals

The neural network will learn to identify:

  1. Most Profitable Setups: Which A-pattern combinations lead to profitable trades
  2. Optimal Positioning: Where within VAL/INV grids to place trades
  3. Perfect Timing: When Stage 1→Stage 2 transitions occur
  4. Pattern Reliability: Z-scores and historical consistency for predictability
  5. Multi-Timeframe Context: How HTF/MTF/LTF alignment affects profitability

Predictive Elements

  • 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

Expected ML Outputs

  • 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

Key Insights for ML Training

Pattern Evolution

  • 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

Spatial-Temporal Relationships

  • 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

Multi-Timeframe Context

  • 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

File Structure

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

Usage

  1. Upload Data: Import trade CSV and analysis JSON files
  2. Run Analysis: Execute the dashboard to process all data
  3. Review Results: Examine spatial-temporal analysis and pattern metrics
  4. Export ML Dataset: Download comprehensive dataset for neural network training
  5. Train Models: Use the exported data to train profitability prediction models

Technical Notes

Score Calculations

  • 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

Data Requirements

  • 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

Limitations

  • 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)

Future Enhancements

  1. Multi-Timeframe Integration: Enhanced analysis across all timeframes simultaneously
  2. Pattern Type Detection: Automatic detection of line vs rectangle patterns
  3. Historical Context: Integration with external market data for broader context
  4. Real-Time Analysis: Live pattern recognition and trade positioning
  5. Advanced ML Models: Deep learning models for pattern prediction

Conclusion

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors