Jump to content

Alpha Research5

From PlusEV Wiki Page
Revision as of 18:29, 7 January 2026 by Plusev.blr (talk | contribs)

Component Architecture

Branch: rikk_mtf_backtest001 | Companion to: Alpha_Research

Component-level implementation of the MTFDR backtesting system. Each component translates trading philosophy into executable Python.


PART 1: Pipeline Architecture

The system processes each 5-minute bar through 5 sequential layers:

     Raw OHLC Data (1D, 4H, 1H, 15M, 5M)
              │
              ▼
┌─────────────────────────────────────────────────────────────────────┐
│  LAYER 1: multi_timeframe_analysis.py                               │
│  "Are all timeframes pointing the same direction?"                  │
│                                                                     │
│  • Analyzes [1D, 4H, 1H, 15M, 5M] via TrendAnalysisCore            │
│  • Calculates weighted alignment score (hierarchical weights)       │
│  • 15-minute confirmation requirement                               │
│  • Output: TimeframeAnalysisResult (aligned, direction, score)      │
└─────────────────────────────────────────────────────────────────────┘
              │
              ▼
┌─────────────────────────────────────────────────────────────────────┐
│  LAYER 2: market_state_analysis.py                                  │
│  "What kind of market are we in?"                                   │
│                                                                     │
│  7 Detection Algorithms:                                            │
│  1. Railroad Trend - Strong one-sided move (consistency > 80%)      │
│  2. Creeper Move - Slow grinding action (avg range < 0.5%)          │
│  3. Volatility Classification - High/Normal/Low                     │
│  4. Market State - Trending/Range/Creeper/Momentum                  │
│  5. Two-Day Trend - Both days close same direction                  │
│  6. Trend Phase - EARLY/MIDDLE/LATE                                 │
│  7. Institutional Behavior - Fight, Accumulation, BOS               │
│  Output: MarketStateResult                                          │
└─────────────────────────────────────────────────────────────────────┘
              │
              ▼
┌─────────────────────────────────────────────────────────────────────┐
│  LAYER 3: setup_quality_detection.py                                │
│  "How good is this setup? Grade it A+ to F."                        │
│                                                                     │
│  5-Factor Weighted Scoring:                                         │
│  • Timeframe Alignment (30%)                                        │
│  • Trend Strength (20%)                                             │
│  • Entry Quality (15%)                                              │
│  • Key Level Proximity (20%)                                        │
│  • Risk/Reward (15%)                                                │
│                                                                     │
│  Output: SetupQualityResult (grade, score, position_size)           │
└─────────────────────────────────────────────────────────────────────┘
              │
              ▼
┌─────────────────────────────────────────────────────────────────────┐
│  LAYER 4: signal_generation_trade_management.py                     │
│  "Should we trade? What direction? Where's entry/stop/target?"      │
│                                                                     │
│  Direction Logic:                                                   │
│  • MA21 rising → LONG                                               │
│  • MA21 declining → SHORT                                           │
│  • Flat → MTF fallback                                              │
│                                                                     │
│  Gate Filters: Hour, MA Direction, Probability Zone                 │
│  Output: Signal (direction, entry, stop, target, grade)             │
└─────────────────────────────────────────────────────────────────────┘
              │
              ▼
┌─────────────────────────────────────────────────────────────────────┐
│  LAYER 5: trade_execution_engine.py                                 │
│  "Execute the trade, manage the position, calculate P&L"            │
│                                                                     │
│  Execution: Slippage modeling, Commission (Rs 20/lot), CTT (0.01%)  │
│  Position Management: Trailing stop, Breakeven stop, Time exit      │
│  Output: Trade objects with complete P&L                            │
└─────────────────────────────────────────────────────────────────────┘

PART 2: Component Index

# Component Purpose Code Link
1 multi_timeframe_analysis.py MTF alignment across 5 timeframes View
2 trend_analysis_core.py Per-timeframe trend direction, MA slopes View
3 market_state_analysis.py Railroad, creeper, volatility, trend phase View
4 setup_quality_detection.py 5-factor scoring, A+ to F grades View
5 signal_generation_trade_management.py Direction, filters, entry/stop/target View
6 trade_execution_engine.py Execution, position management, P&L View
7 probability_zone_analysis.py Probability zones (80%/65%/35%/15%), crash bar View
8 data_manager.py Data loading, timeframe aggregation View
9 backtesting_analytics.py Performance metrics, reporting View

PART 3: Trading Concept → Code Mapping

Trading Concept Status Component Implementation
Halves/Thirds probability_zone_analysis.py Top third = 80%, Bottom third = 15% continuation
Crash Bar probability_zone_analysis.py Bar 2x average = structural break
Three-Finger Spread probability_zone_analysis.py Price/21MA/200MA separation detection
45-degree Angle trend_analysis_core.py MA slope analysis, flattish detection
Railroad Trend market_state_analysis.py Consistency > 80%, 3+ strong bars
Creeper Move market_state_analysis.py Avg range < 0.5% over 7 bars
Two-Day Trend market_state_analysis.py Both daily bars close same direction
Color Change probability_zone_analysis.py Liquidity sweep pattern detection
Fab Four - Not implemented (Three-Finger Spread is closest)
Traffic Jam - Not implemented

PART 4: Key Configuration Parameters

Setup Quality Weights

timeframe_alignment_weight = 0.30   # 30%
trend_strength_weight      = 0.20   # 20%
entry_technique_weight     = 0.15   # 15%
key_level_proximity_weight = 0.20   # 20%
risk_reward_weight         = 0.15   # 15%
                           -------
                             1.00

Penalty & Bonus Constants

creeper_move_penalty       = -50
ma_struggle_penalty        = -30
two_day_trend_penalty      = -30
phase_mismatch_penalty     = -25
railroad_trend_bonus       = +15
key_level_bonus            = +10
clean_entry_bonus          = +10

Grade Thresholds & Position Sizing

A+ = score >= 90    →  2 lots
A  = score >= 80    →  1 lot
B  = score >= 70    →  1 lot
C  = score >= 60    →  1 lot
D  = score >= 50    →  1 lot
F  = score < 50     →  1 lot

Trading Constants

commission_per_lot     = 20.00      # Rs per lot (Dhan)
transaction_tax_rate   = 0.0001     # 0.01% CTT
lot_size_multiplier    = 100        # MCX lot size
min_stop_distance      = 40         # Points
default_risk_reward    = 1.5        # R:R ratio