caishen

CDS - Chaos Data Services

RISE Framework Specification

Spec ID: 04
Version: 1.0
Document ID: caishen-rise-cds-v1.0
Last Updated: 2025-01-31

Creative Intent

What CDS Enables Users to Create:

Desired Outcomes:

  1. Users receive fully calculated chaos indicator data
  2. Fractals are automatically detected and classified
  3. Divergence patterns are identified
  4. Multi-timeframe perspectives are unified

Core Concepts

Bill Williams Chaos Theory Indicators

The platform implements Bill Williams’ trading methodology:


Core Components

ChaosDataBuilder

The central data structure containing all chaos analysis for a POV.

Behavior:

Layout: Contains List<BarChaosItem>, InstrumentPerspective, MarketOverViewerNode

BarChaosItem

Extended price bar with all chaos indicator values.

Behavior:

FractalSignalAnalyzer

Analyzes fractal patterns for trading signals.

Behavior:


ChaosDataBuilder Structure

Core Properties

ChaosDataBuilder:
  # Identification
  - Instrument: string              # "EUR/USD"
  - Timeframe: string               # "H4"
  - PovTlid: string                 # Unique POV+Time ID
  - CorrelationId: Guid             # Related data group
  
  # Price Data
  - ChartBars: List<BarChaosItem>   # All bar data
  - PipSize: double                 # Instrument pip size
  - PriceHighestValue: double       # Max price in range
  - PriceLowestValue: double        # Min price in range
  
  # Indicator Extremes
  - AOHighestValue: double          # Max AO value
  - AOLowestValue: double           # Min AO value
  - ACHighestValue: double          # Max AC value
  - ACLowestValue: double           # Min AC value
  
  # Trend Analysis
  - TrendLastWave: string           # "UP" or "DOWN"
  - TrendLastBar: string            # Last bar trend
  
  # Gator Mouth Analysis
  - NbBarMouthIsOpen: int           # Bars since mouth opened
  - GatorMouthMaxOpenessMaxDistGLRL: double  # Max Lips-Teeth distance
  - GatorMouthMaxOpenessMaxDistRLBL: double  # Max Teeth-Jaw distance
  - GatorMouthMaxOpenessMaxDistGLBL: double  # Max Lips-Jaw distance
  
  # Angle Analysis (Gator slope)
  - AngleGatorDatadistGLRL: double
  - AngleGatorDatadistRLBL: double
  - AngleGatorDatadistGLBL: double
  - AngleGatorDatadistGLPrice: double
  - AngleGatorDatadistRLPrice: double
  - AngleGatorDatadistBLPrice: double
  
  # Market Overview
  - MarketOverViewerNodeCurrentIsDiverging: bool
  - MarketOverViewerNodeCurrentBdb: int
  - MarketOverViewerNodeCurrentDivA: double
  - MarketOverViewerNodeCurrentDivAPeakDt: DateTime
  - MarketOverViewerNodeCurrentDivB: double
  - MarketOverViewerNodeCurrentDivBPeakDt: DateTime
  - MarketOverViewerNodeCurrentDivergenceIndicator: int
  - MarketOverViewerNodeCurrentStrengthOrder: int
  
  # Instrument Properties
  - InstrumentProperty: InstrumentPropertyDTO

BarChaosItem Properties

BarChaosItem extends BarChartItem:
  # Identification
  - Id: Guid
  - Tlid: string                    # Time-based ID (yyMMddHHmm)
  - CorrelationId: Guid
  
  # Price (OHLC)
  - Dt: DateTime                    # Bar timestamp
  - Ask: QuoteSide                  # Ask OHLC
  - Bid: QuoteSide                  # Bid OHLC
  - V: int                          # Volume
  
  # Alligator
  - Lips: double                    # Green line (5-period)
  - Teeth: double                   # Red line (8-period)
  - Jaw: double                     # Blue line (13-period)
  
  # Oscillators
  - AO: double                      # Awesome Oscillator
  - SAO: double                     # Smoothed AO
  - AC: double                      # Accelerator
  - ACD: double                     # AC direction
  - AOF: double                     # AO fast
  
  # Fractals
  - Fractal: double                 # Fractal value
  - FractalBuy: double             # Buy fractal (low)
  - FractalSell: double            # Sell fractal (high)
  - FractalDimension: double       # Fractal dimension
  
  # Fibonacci Levels
  - F2, F3, F5, F8, F13, F21, F34, F55, F89: double
  
  # Other Indicators
  - Zone: int                       # Trading zone (0=gray, 1=green, 2=red)
  - ZLC: bool                       # Zero line cross
  - MFI: int                        # Market Facilitation Index
  - Squat: bool                     # Squat bar indicator
  - BDB: int                        # Bar divergence pattern (-1, 0, 1)
  - FDB: int                        # Full divergence bar
  
  # Gator
  - GatorUpper: double              # Upper gator value
  - GatorLower: double              # Lower gator value
  - GatorSupreme: double            # Gator supreme indicator
  
  # State
  - IsAOPeak: int                   # Is this bar an AO peak
  - IsIncompleted: bool             # Bar still forming
  - BarType: int                    # Bar classification

Fractal Detection

Williams Fractal Pattern

A fractal is identified when a bar has:

Algorithm GetFractal(quotes, windowSpan=2):
  For each bar:
    isHigh = true
    isLow = true
    
    For each bar in [-windowSpan, +windowSpan]:
      if evalHigh <= wingHigh: isHigh = false
      if evalLow >= wingLow: isLow = false
    
    if isHigh: FractalBear = bar.High  # Sell signal
    if isLow: FractalBull = bar.Low    # Buy signal

FractalResult

FractalResult:
  - Date: DateTime
  - FractalBear: decimal?    # Sell fractal (high point)
  - FractalBull: decimal?    # Buy fractal (low point)

Creative Advancement Scenarios

Scenario 1: Build Complete CDB

Creative Advancement Scenario: Create Chaos Data Builder

Desired Outcome: Complete CDB for EUR/USD H4 analysis

Current Reality: Raw price bars available from PDS

Natural Progression Steps:
  1. Receive PriceHistoryBase from PDS
  2. Calculate Alligator (Lips, Teeth, Jaw) for each bar
  3. Calculate AO and AC
  4. Detect Fractals
  5. Calculate Zones (green/red)
  6. Compute Gator mouth analysis
  7. Identify divergence patterns
  8. Assemble ChaosDataBuilder with all data

Achieved Outcome: User has complete chaos analysis

Supporting Features: Indicator calculation pipeline

Scenario 2: Detect Trading Signal

Creative Advancement Scenario: Identify Fractal Breakout

Desired Outcome: Trading signal with direction and price

Current Reality: CDB contains recent price action

Natural Progression Steps:
  1. Scan recent bars for fractal patterns
  2. Identify most recent fractal high/low
  3. Check if price has broken through fractal level
  4. Validate with AO/AC confirmation
  5. Return signal with breakout price

Achieved Outcome: Actionable trading signal

Supporting Features: FractalSignalAnalyzer

Divergence Detection

Divergence Types

DivergenceTypeEnum:
  - None = 0
  - BullishRegular = 1      # Price lower low, AO higher low
  - BearishRegular = 2      # Price higher high, AO lower high
  - BullishHidden = 3       # Price higher low, AO lower low
  - BearishHidden = 4       # Price lower high, AO higher high

DivergenceLevel

DivergenceLevel:
  - Type: DivergenceTypeEnum
  - PricePointA: double
  - PricePointB: double
  - AOPointA: double
  - AOPointB: double
  - DateA: DateTime
  - DateB: DateTime
  - Strength: int           # Signal strength (1-3)

Market Overview

InstrumentPerspective

Multi-timeframe view of single instrument.

InstrumentPerspective:
  - Instrument: string
  - Perspectives: Dictionary<string, ChaosDataBuilder>  # TF -> CDB
  - CurrentState: InstrumentPerspectiveStateEnum

MarketOverViewerNode

Current market state summary.

MarketOverViewerNode:
  - IsDiverging: bool
  - BDB: int                    # Bar divergence code
  - DivA: double               # First divergence point
  - DivAPeakDt: DateTime
  - DivB: double               # Second divergence point
  - DivBPeakDt: DateTime
  - TrendLastWave: string      # "UP" or "DOWN"
  - DivergenceIndicator: int   # Divergence type code
  - StrengthOrder: int         # Signal strength ranking

Implementation Notes for Python/TypeScript

Python Implementation

from dataclasses import dataclass, field
from datetime import datetime
from typing import List, Optional, Dict
from decimal import Decimal

@dataclass
class FractalResult:
    date: datetime
    fractal_bear: Optional[Decimal] = None
    fractal_bull: Optional[Decimal] = None

@dataclass
class BarChaosItem:
    dt: datetime
    open: Decimal
    high: Decimal
    low: Decimal
    close: Decimal
    volume: int = 0
    
    # Alligator
    lips: float = 0.0
    teeth: float = 0.0
    jaw: float = 0.0
    
    # Oscillators
    ao: float = 0.0
    ac: float = 0.0
    
    # Fractals
    fractal_buy: Optional[float] = None
    fractal_sell: Optional[float] = None
    fractal_dimension: float = 0.0
    
    # Zone
    zone: int = 0  # 0=gray, 1=green, 2=red
    
    # Other
    bdb: int = 0
    squat: bool = False
    mfi: int = 0

@dataclass
class ChaosDataBuilder:
    instrument: str
    timeframe: str
    chart_bars: List[BarChaosItem] = field(default_factory=list)
    
    # Summary
    price_highest: float = 0.0
    price_lowest: float = 0.0
    ao_highest: float = 0.0
    ao_lowest: float = 0.0
    trend_last_wave: str = ""
    nb_bar_mouth_is_open: int = 0

class CDSService:
    def calculate_fractals(
        self, 
        bars: List[BarChaosItem],
        window_span: int = 2
    ) -> List[FractalResult]:
        """Detect Williams fractals in price series"""
        pass
    
    def build_cdb(
        self,
        price_history: PriceHistoryBase
    ) -> ChaosDataBuilder:
        """Build complete ChaosDataBuilder from price history"""
        pass

TypeScript Implementation

interface BarChaosItem {
  dt: Date;
  open: number;
  high: number;
  low: number;
  close: number;
  volume: number;
  
  // Alligator
  lips: number;
  teeth: number;
  jaw: number;
  
  // Oscillators
  ao: number;
  ac: number;
  
  // Fractals
  fractalBuy?: number;
  fractalSell?: number;
  fractalDimension: number;
  
  // Zone
  zone: number;  // 0=gray, 1=green, 2=red
  
  // Other
  bdb: number;
  squat: boolean;
  mfi: number;
}

interface ChaosDataBuilder {
  instrument: string;
  timeframe: string;
  chartBars: BarChaosItem[];
  priceHighest: number;
  priceLowest: number;
  aoHighest: number;
  aoLowest: number;
  trendLastWave: 'UP' | 'DOWN' | '';
  nbBarMouthIsOpen: number;
}

interface ICDSService {
  calculateFractals(
    bars: BarChaosItem[],
    windowSpan?: number
  ): FractalResult[];
  
  buildCDB(
    priceHistory: PriceHistoryBase
  ): Promise<ChaosDataBuilder>;
}