Jump to content

Component:Signal Generation: Difference between revisions

From PlusEV Wiki Page
No edit summary
No edit summary
 
Line 97: Line 97:
</pre>
</pre>


    === Gate 3: Direction Determination ===
=== Gate 3: Direction Determination ===


  Direction is determined by MA21 slope with 1H → 15m fallback:
Direction is determined by MA21 slope with 1H → 15m fallback:


  <pre>
<pre>
  trend_direction = market_state.trend_direction
trend_direction = market_state.trend_direction


  IF trend_direction == "up":
IF trend_direction == "up":
      direction = LONG    // MA21 rising → trade long
    direction = LONG    // MA21 rising → trade long


  ELIF trend_direction == "down":
ELIF trend_direction == "down":
      direction = SHORT  // MA21 declining → trade short
    direction = SHORT  // MA21 declining → trade short


  ELSE:
ELSE:
      // MA21 flat/unclear → use MTF fallback
    // MA21 flat/unclear → use MTF fallback
      IF mtf_direction == "up":
    IF mtf_direction == "up":
          direction = LONG
        direction = LONG
      ELIF mtf_direction == "down":
    ELIF mtf_direction == "down":
          direction = SHORT
        direction = SHORT
      ELSE:
    ELSE:
          // TICKET-22: 1H → 15m fallback (matches TimeframeSettings)
        // TICKET-22: 1H → 15m fallback (matches TimeframeSettings)
          // Config: primary=1H, confirmation=15m, wait_for_15min_alignment=True
        // Config: primary=1H, confirmation=15m, wait_for_15min_alignment=True


          one_hour_dir = timeframe_results['1h'].direction
        one_hour_dir = timeframe_results['1h'].direction
          fifteen_min_dir = timeframe_results['15m'].direction
        fifteen_min_dir = timeframe_results['15m'].direction


          // Priority 1: 1H + 15m agreement (strongest)
        // Priority 1: 1H + 15m agreement (strongest)
          IF one_hour_dir == fifteen_min_dir AND one_hour_dir IN ['up', 'down']:
        IF one_hour_dir == fifteen_min_dir AND one_hour_dir IN ['up', 'down']:
              direction = LONG if one_hour_dir == 'up' else SHORT
            direction = LONG if one_hour_dir == 'up' else SHORT


          // Priority 2: 1H only (primary_timeframe)
        // Priority 2: 1H only (primary_timeframe)
          ELIF one_hour_dir IN ['up', 'down']:
        ELIF one_hour_dir IN ['up', 'down']:
              direction = LONG if one_hour_dir == 'up' else SHORT
            direction = LONG if one_hour_dir == 'up' else SHORT


          // Priority 3: 15m only (confirmation_timeframe)
        // Priority 3: 15m only (confirmation_timeframe)
          ELIF fifteen_min_dir IN ['up', 'down']:
        ELIF fifteen_min_dir IN ['up', 'down']:
              direction = LONG if fifteen_min_dir == 'up' else SHORT
            direction = LONG if fifteen_min_dir == 'up' else SHORT


          ELSE:
        ELSE:
              RETURN None  // ALL timeframes sideways → true consolidation
            RETURN None  // ALL timeframes sideways → true consolidation
  </pre>
</pre>


  '''Direction Hierarchy:'''
'''Direction Hierarchy:'''
  # MA21 slope (5min) - primary
# MA21 slope (5min) primary
  # MTF primary_direction - first fallback
# MTF primary_direction first fallback
  # 1H + 15m agreement - strongest MTF signal
# 1H + 15m agreement strongest MTF signal
  # 1H only - primary_timeframe fallback
# 1H only primary_timeframe fallback
  # 15m only - confirmation_timeframe fallback
# 15m only confirmation_timeframe fallback
  # None - only if all sideways (true consolidation)
# None only if all sideways (true consolidation)


=== Gate 4: Probability Zone Filter ===
=== Gate 4: Probability Zone Filter ===

Latest revision as of 22:24, 10 January 2026

Signal Generation & Trade Management

[edit]

Purpose

[edit]

"Should we trade? Which direction? Where's entry/stop/target?"

This component is the decision maker. It receives graded setups from Layer 3 and decides:

  1. Should we take this trade? (passes all gate filters)
  2. Which direction? (LONG or SHORT)
  3. Where to enter, stop, and exit? (entry techniques)

Trading Market Principle

[edit]

"Trade with the trend, not against it"

  • MA21 rising = LONG only → don't fight a rising market
  • MA21 declining = SHORT only → don't catch falling knives
  • MA21 flat = use MTF direction as tiebreaker
  • Gate filters protect capital → blocked hours, wrong zone, weak confirmation = skip
  • Only high-quality setups traded → A+, A, B grades only

Decision Flow

[edit]
           ┌─────────────────────────────────┐
           │  Setup Quality Result (Layer 3) │
           │  Grade: A+/A/B/C/D/F            │
           └─────────────────────────────────┘
                         │
                         ▼
           ┌─────────────────────────────────┐
           │  GATE 1: Grade Filter           │
           │  Only A+, A, B pass             │
           │  C, D, F → REJECTED             │
           └─────────────────────────────────┘
                         │
                         ▼
           ┌─────────────────────────────────┐
           │  GATE 2: Hour Filter            │
           │  Blocked: 9 AM, 10 PM, 11 PM    │
           │  (Loss-making hours)            │
           └─────────────────────────────────┘
                         │
                         ▼
           ┌─────────────────────────────────┐
           │  GATE 3: Direction Determination│
           │  MA21 rising → LONG             │
           │  MA21 declining → SHORT         │
           │  Flat/unclear → NO TRADE        │
           └─────────────────────────────────┘
                         │
                         ▼
           ┌─────────────────────────────────┐
           │  GATE 4: Probability Zone Filter│
           │  Top third + LONG = OK          │
           │  Bottom third + LONG = BLOCKED  │
           │  (Trades with probability)      │
           └─────────────────────────────────┘
                         │
                         ▼
           ┌─────────────────────────────────┐
           │  Calculate Entry/Stop/Target    │
           │  Generate Signal                │
           └─────────────────────────────────┘

Gate Filters

[edit]

Gate 1: Grade Filter

[edit]

Only high-quality setups are traded:

Grade Action
A+, A, B PASS → Generate signal
C, D, F BLOCKED → No signal generated

Gate 2: Hour Filter

[edit]

Block historically loss-making hours:

Blocked Hours: [9, 22, 23]  // 9 AM, 10 PM, 11 PM IST

IF current_hour IN blocked_hours:
    RETURN None  // No signal

Gate 3: Direction Determination

[edit]

Direction is determined by MA21 slope with 1H → 15m fallback:

trend_direction = market_state.trend_direction

IF trend_direction == "up":
    direction = LONG    // MA21 rising → trade long

ELIF trend_direction == "down":
    direction = SHORT   // MA21 declining → trade short

ELSE:
    // MA21 flat/unclear → use MTF fallback
    IF mtf_direction == "up":
        direction = LONG
    ELIF mtf_direction == "down":
        direction = SHORT
    ELSE:
        // TICKET-22: 1H → 15m fallback (matches TimeframeSettings)
        // Config: primary=1H, confirmation=15m, wait_for_15min_alignment=True

        one_hour_dir = timeframe_results['1h'].direction
        fifteen_min_dir = timeframe_results['15m'].direction

        // Priority 1: 1H + 15m agreement (strongest)
        IF one_hour_dir == fifteen_min_dir AND one_hour_dir IN ['up', 'down']:
            direction = LONG if one_hour_dir == 'up' else SHORT

        // Priority 2: 1H only (primary_timeframe)
        ELIF one_hour_dir IN ['up', 'down']:
            direction = LONG if one_hour_dir == 'up' else SHORT

        // Priority 3: 15m only (confirmation_timeframe)
        ELIF fifteen_min_dir IN ['up', 'down']:
            direction = LONG if fifteen_min_dir == 'up' else SHORT

        ELSE:
            RETURN None  // ALL timeframes sideways → true consolidation

Direction Hierarchy:

  1. MA21 slope (5min) – primary
  2. MTF primary_direction – first fallback
  3. 1H + 15m agreement – strongest MTF signal
  4. 1H only – primary_timeframe fallback
  5. 15m only – confirmation_timeframe fallback
  6. None – only if all sideways (true consolidation)

Gate 4: Probability Zone Filter

[edit]

Filters trades based on price position within range:

Zone LONG SHORT Logic
Top Third Blocked Allowed 80% continuation down, 15% up
Middle Half Allowed Allowed Neutral zone
Bottom Third Allowed Blocked 80% continuation up, 15% down

Sideways Market Exception: In creeper/consolidation, uses mean reversion (opposite logic).


Stop Loss Calculation

[edit]

Stop placement based on entry technique:

Entry Technique LONG Stop SHORT Stop
GREEN_BAR_PULLBACK Below pullback low Above rally high
BREAKOUT_PULLBACK min(last 3 lows) max(last 3 highs)
MA_BOUNCE MA21 - 5 points MA21 + 5 points
BOS_ENTRY min(last 10 lows) + buffer max(last 10 highs) - buffer
DISCOUNT_ZONE entry × 0.99 entry × 1.01
DEFAULT entry - 40 points entry + 40 points

Minimum Stop Distance: 40 points (prevents tight stops hitting on noise)


Take Profit Calculation

[edit]

Implements "cut the move in half" principle:

distance_to_ma = |entry_price - MA21|
target_distance = distance_to_ma × 0.5

IF LONG:
    take_profit = entry_price + target_distance
ELSE:
    take_profit = entry_price - target_distance

Minimum R:R: 1.5 (target must be at least 1.5× risk)


Cost Calculations

[edit]

Commission (Dhan Broker)

[edit]
commission = position_size × Rs 20 per lot

CTT (Commodity Transaction Tax)

[edit]
contract_value = entry_price × lot_size × position_size
tax = contract_value × 0.0001  // 0.01% total (0.005% per leg)

Configuration

[edit]
Parameter Value Description
commission_per_lot 20.00 Rs per lot (Dhan)
transaction_tax_rate 0.00005 0.005% per leg × 2 = 0.01% CTT
lot_size_multiplier 100 MCX lot size
min_stop_distance 40 Minimum stop in points
default_risk_reward 1.5 Minimum R:R ratio
enable_hour_filter True Block loss-making hours
blocked_hours [9, 22, 23] Hours to skip
enable_ma_direction_filter True MA21 alignment required
enable_probability_zone_filter True Zone probability check
enable_color_change_filter False Disabled (too restrictive)

Output

[edit]

Signal Object:

Field Type Description
direction Enum LONG or SHORT
entry_price float Current close price
stop_loss_price float Calculated stop level
take_profit_price float Calculated target level
position_size int From setup quality (1 or 2 lots)
setup_quality Enum A+, A, or B
entry_technique Enum How stop was determined

Dependencies

[edit]

Upstream:

Internal:

Downstream: