Alpha Research
MA21 Mean Reversion Strategy
Complete Trading System Documentation
MCX Crude Oil - Intraday Trading System
PART 1: CORE CONCEPT
The Big Idea
Trade pullbacks to the 21-period Moving Average (MA21) during established trends.
When the market is trending, price naturally pulls back to the 21 MA before continuing. We enter at these pullback zones, trading WITH the trend direction.
"The MA is a ZONE, not a thin line" - Entry allowed within ±25 points of MA21
PART 2: MULTI-TIMEFRAME (MTF) ANALYSIS
Timeframe Hierarchy
We analyze 5 timeframes from highest to lowest:
| Timeframe | Purpose | What We Look For |
|---|---|---|
| Daily (1D) | Context/Bias | Overall trend direction, key levels |
| 4-Hour (4H) | Primary Trend | Main trend confirmation |
| 1-Hour (1H) | Confirmation | Trend alignment validation |
| 15-Min (15M) | Entry Timing | Final confirmation before entry |
| 5-Min (5M) | Execution | Precise entry and exit |
MTF Alignment Logic
For each timeframe, we check:
- MA21 Slope - Is it rising or declining?
- Price Position - Is price above/below MA21?
- MA21 vs MA200 - Short-term vs long-term trend alignment
Weighted Scoring
Each timeframe contributes to an alignment score:
- Higher timeframes have more weight (Daily > 4H > 1H > 15M > 5M)
- Score ranges from 0.0 to 1.0
- Higher score = stronger alignment
Direction Determination
IF all timeframes agree → Strong signal IF most timeframes agree → Medium signal IF timeframes conflict → No trade (wait for clarity)
Per-Timeframe Trend Analysis
For each timeframe, the Trend Analysis Core calculates:
1. Trend Direction
Based on MA21 slope:
| MA21 Slope | Direction | Threshold |
|---|---|---|
| Positive > 0.01% | UP | Bullish slope threshold |
| Negative < -0.01% | DOWN | Bearish slope threshold |
| Between ±0.01% | SIDEWAYS | No clear trend |
2. MA Trending Status
Is the MA21 moving with significant momentum?
| MA Slope | Status | Threshold |
|---|---|---|
| > 0.05% | TRENDING | MA is clearly moving |
| < 0.05% | FLAT | MA is consolidating |
3. Price-MA Struggle Detection
Is price stuck near the MA without breaking away?
| Condition | Detection |
|---|---|
| Price within 0.5% of MA21 for multiple bars | STRUGGLING |
| Price clearly moving away from MA21 | CLEAR TREND |
Trading Impact: Price-MA struggle = -30 penalty in grading
4. Trend Confidence Calculation
Weighted score from three factors:
Confidence = (MA_Slope × 40%) + (Price_Position × 30%) + (MA_Alignment × 30%)
| Factor | Weight | What It Measures |
|---|---|---|
| MA Slope | 40% | Steepness of MA21 angle |
| Price Position | 30% | Is price above/below MA21? |
| MA Alignment | 30% | Does MA21 align with MA200? |
PART 3: SIGNAL GENERATION FLOW
Complete Flow Diagram
┌─────────────────────────────────────────────────────────────────────────────┐ │ SIGNAL GENERATION PIPELINE │ ├─────────────────────────────────────────────────────────────────────────────┤ │ │ │ STEP 1: DATA COLLECTION │ │ ┌─────────────────────────────────────────────────────────────────────┐ │ │ │ Load OHLCV data for all 5 timeframes │ │ │ │ Calculate MA21 and MA200 for each timeframe │ │ │ └─────────────────────────────────────────────────────────────────────┘ │ │ ↓ │ │ STEP 2: MULTI-TIMEFRAME ANALYSIS │ │ ┌─────────────────────────────────────────────────────────────────────┐ │ │ │ Analyze trend direction in each timeframe │ │ │ │ Calculate weighted alignment score │ │ │ │ Determine primary direction (LONG/SHORT/NONE) │ │ │ └─────────────────────────────────────────────────────────────────────┘ │ │ ↓ │ │ STEP 3: MARKET STATE ANALYSIS │ │ ┌─────────────────────────────────────────────────────────────────────┐ │ │ │ Detect: Railroad Trend, Creeper Move, Two-Day Trend │ │ │ │ Classify: Trend Phase (EARLY/MIDDLE/LATE) │ │ │ │ Check: Institutional activity, BOS (Break of Structure) │ │ │ └─────────────────────────────────────────────────────────────────────┘ │ │ ↓ │ │ STEP 4: SETUP QUALITY GRADING │ │ ┌─────────────────────────────────────────────────────────────────────┐ │ │ │ Calculate 5-factor weighted score │ │ │ │ Apply penalties (creeper -50, MA struggle -30, etc.) │ │ │ │ Apply bonuses (railroad +15, key level +10) │ │ │ │ Assign grade: A+, A, B, C, D, F │ │ │ └─────────────────────────────────────────────────────────────────────┘ │ │ ↓ │ │ STEP 5: ENTRY FILTERS │ │ ┌─────────────────────────────────────────────────────────────────────┐ │ │ │ □ Is price within ±25 pts of MA21? │ │ │ │ □ Does direction align with MA21 slope? │ │ │ │ □ Is setup grade A+, A, or B? │ │ │ │ □ Is current hour allowed? (not 9, 22, 23) │ │ │ │ □ Does probability zone allow this trade? │ │ │ │ ALL YES → Generate Signal | ANY NO → No Signal │ │ │ └─────────────────────────────────────────────────────────────────────┘ │ │ ↓ │ │ STEP 6: SIGNAL OUTPUT │ │ ┌─────────────────────────────────────────────────────────────────────┐ │ │ │ Direction: LONG or SHORT │ │ │ │ Entry Price: Current close price │ │ │ │ Stop Loss: 40 points (structure-based or default) │ │ │ │ Take Profit: 60 points (1.5:1 R:R) │ │ │ │ Position Size: 1 lot │ │ │ └─────────────────────────────────────────────────────────────────────┘ │ │ │ └─────────────────────────────────────────────────────────────────────────────┘
PART 4: MARKET STATE DETECTION
7 Detection Algorithms
1. Railroad Trend Detection
What it is: Strong, consistent trend with minimal pullbacks.
| Characteristic | Description |
|---|---|
| Bar Analysis | 5 most recent bars analyzed |
| Strong Bars | 80%+ must close in same direction |
| Consistency | Bars must be "strong" (body > 0.3% of price) |
Trading Impact: +15 bonus to setup score (high quality trend)
2. Creeper Move Detection
What it is: Slow, grinding price action with small bars.
| Characteristic | Description |
|---|---|
| Bar Range | Average range < 0.5% of price |
| Analysis Period | Last 7 bars |
| Pattern | Price moving slowly without clear impulse |
Trading Impact: -50 penalty to setup score (avoid these setups)
3. Two-Day Trend Analysis
What it is: Trend must be visible on Daily timeframe for 2+ days.
| Requirement | Description |
|---|---|
| Daily Bars | At least 2 consecutive bars in same direction |
| Purpose | Filters out noise, ensures real trend |
Trading Impact: Missing two-day trend = -30 penalty
4. Trend Phase Classification
| Phase | Bars into Trend | Trading Approach |
|---|---|---|
| EARLY | 0-15 bars | Avoid (uncertain direction) |
| MIDDLE | 15-40 bars | TARGET (best trades) |
| LATE | 40+ bars | Avoid (exhaustion risk) |
Trading Impact: Not being in MIDDLE phase = -25 penalty
5. Institutional Fight Detection
What it is: When big players are battling each other (choppy action).
| Indicator | Sign |
|---|---|
| Volume | 1.5x+ average volume |
| Price Action | Narrow range with high volume |
| Wicks | Long wicks on candles (rejection) |
Trading Impact: 0.7x multiplier on final score (30% reduction)
6. Break of Structure (BOS)
What it is: Price breaking a significant swing high/low.
| BOS Type | Description |
|---|---|
| SWING_HIGH_BREAK | Price breaks above prior swing high |
| SWING_LOW_BREAK | Price breaks below prior swing low |
| PDH_BREAK | Previous Day High break |
| PDL_BREAK | Previous Day Low break |
7. Volatility Classification
| Volatility | ATR % of Price | Trading Adjustment |
|---|---|---|
| HIGH | > 1.0% | Wider stops needed |
| MEDIUM | 0.3% - 1.0% | Normal stops |
| LOW | < 0.3% | Tighter stops possible |
PART 5: SETUP QUALITY GRADING SYSTEM
5-Factor Weighted Scoring
Every potential trade is scored on 5 factors:
| Factor | Weight | What It Measures |
|---|---|---|
| Timeframe Alignment | 30% | How well all timeframes agree |
| Trend Strength | 20% | Quality of the trend (railroad vs creeper) |
| Key Level Proximity | 20% | Is entry near a significant level? |
| Entry Quality | 15% | Clean entry technique, near MA |
| Risk/Reward | 15% | How favorable is the R:R ratio |
Score Calculation
Base Score = (TF_score × 0.30) + (Trend_score × 0.20) + (KeyLevel_score × 0.20)
+ (Entry_score × 0.15) + (RR_score × 0.15)
Final Score = Base Score + Bonuses - Penalties
Penalties (Negative Adjustments)
| Condition | Penalty | Reason |
|---|---|---|
| Creeper Move | -50 | Poor quality price action |
| MA Struggle | -30 | Price fighting the MA |
| No Two-Day Trend | -30 | Trend not established |
| Wrong Trend Phase | -25 | Not in MIDDLE phase |
| Far from Key Level | -50 | No confluence |
| Far from MA | -40 | Not a pullback entry |
Bonuses (Positive Adjustments)
| Condition | Bonus | Reason |
|---|---|---|
| Railroad Trend | +15 | High quality trend |
| At Key Level | +10 | Confluence present |
| Clean Entry | +10 | Clear technical setup |
Grade Thresholds
| Grade | Min Score | Action |
|---|---|---|
| A+ | 90+ | Trade with full conviction |
| A | 80-89 | Trade with confidence |
| B | 70-79 | Trade normally |
| C | 60-69 | NO TRADE |
| D | 50-59 | NO TRADE |
| F | <50 | NO TRADE |
A+ Special Requirements
To get an A+ grade, ALL of these must be true:
- Score ≥ 90
- All timeframes aligned
- Entry near MA21 (within ±25 pts)
- Two-day trend present
PART 6: ENTRY TECHNIQUES
Available Entry Techniques
Universal (Both Directions)
| Technique | Description |
|---|---|
| NEAR_MA | Entry when price is near MA21 zone (±25 pts) |
Long-Specific (Bullish)
| Technique | Description |
|---|---|
| GREEN_BAR_AFTER_PULLBACK | Green candle after price pulled back |
| MA_BOUNCE_LONG | Bounce off MA21 in uptrend |
| BOS_ENTRY_LONG | Entry after break of structure (upside) |
| BREAKOUT_PULLBACK_LONG | Pullback after breakout, then continue |
| DISCOUNT_ZONE_LONG | Buy in lower zone of range |
Short-Specific (Bearish)
| Technique | Description |
|---|---|
| RED_BAR_AFTER_RALLY | Red candle after price rallied |
| MA_BOUNCE_SHORT | Rejection from MA21 in downtrend |
| BOS_ENTRY_SHORT | Entry after break of structure (downside) |
| BREAKOUT_PULLBACK_SHORT | Pullback after breakdown, then continue |
| PREMIUM_ZONE_SHORT | Sell in upper zone of range |
How Entry Technique is Selected
IF price near MA21 zone:
technique = NEAR_MA
ELIF break of structure detected:
IF direction == LONG: technique = BOS_ENTRY_LONG
IF direction == SHORT: technique = BOS_ENTRY_SHORT
ELIF pullback pattern detected:
IF direction == LONG: technique = GREEN_BAR_AFTER_PULLBACK
IF direction == SHORT: technique = RED_BAR_AFTER_RALLY
ELSE:
technique = MA_BOUNCE_LONG or MA_BOUNCE_SHORT
PART 7: PROBABILITY ZONES
Halves & Thirds Analysis
Based on price position within recent swing range:
| Zone | Position in Range | Continuation Probability |
|---|---|---|
| Top Third | 67-100% | 80% (likely to make new high) |
| Top Half | 50-67% | 65% |
| Bottom Half | 33-50% | 35% |
| Bottom Third | 0-33% | 15% (85% likely to go lower) |
Zone-Based Trading Rules
In Trending Market
| Zone | LONG | SHORT |
|---|---|---|
| Top Third | Allowed (after pullback) | Blocked (with trend) |
| Bottom Third | Blocked (against trend) | Allowed (after rally) |
In Sideways Market (Mean Reversion)
| Zone | LONG | SHORT |
|---|---|---|
| Top Third | Blocked (overextended) | Allowed |
| Bottom Third | Allowed | Blocked |
Three-Finger Spread
What it is: Large separation between Price, MA21, and MA200.
Three-Finger Spread = When: - Distance(Price to MA21) > 2% of price - AND Distance(MA21 to MA200) > 2% of price
Trading Impact: When detected, expect profit-taking soon (bearish for longs, bullish for shorts)
Crash Bar Detection
What it is: Abnormally large bar indicating structural break.
| Characteristic | Threshold |
|---|---|
| Bar Size | 2x average bar size |
| Close Position | Within 30% of extreme |
Trading Impact: Crash bar in sideways + top zone → Override to SHORT (Crash SHORT detection)
PART 8: EXIT RULES
Initial Stop Loss: 40 Points
| Method | Description |
|---|---|
| Default | 40 points from entry |
| Structure-Based | Below recent swing low (LONG) / Above recent swing high (SHORT) |
| MA-Based | MA21 value ± 25 points buffer |
| Minimum Enforced | Always at least 40 points |
Stop Loss by Entry Technique
| Technique | Stop Placement |
|---|---|
| NEAR_MA | 40 pts default |
| BOS_ENTRY | Below/above structure (10-bar lookback + 5pt buffer) |
| MA_BOUNCE | Below/above MA21 zone |
| BREAKOUT_PULLBACK | Below/above pullback low/high (3-bar lookback) |
DYNAMIC STOP MANAGEMENT (Two-Phase System)
Phase 1: Breakeven Stop (ENABLED)
When trade reaches 25 points profit, stop moves to entry price + 2 pts.
| Parameter | Value |
|---|---|
| Activation | 25 points in profit |
| New Stop | Entry price + 2 pts buffer |
| Purpose | Lock in small profit, eliminate loss |
Example (LONG at 5500):
Entry: 5500 Original Stop: 5460 (40 pts risk) Price reaches 5525 (25 pts profit) → Stop moves to 5502 (entry + 2 buffer) → Worst case now = +2 pts profit (not -40 loss!)
Phase 2: Trailing Stop - ATR Based (ENABLED)
After 20 points profit, stop trails behind price using ATR (Average True Range).
| Parameter | Value |
|---|---|
| Method | ATR_MULTIPLE (adapts to volatility) |
| ATR Period | 14 bars |
| ATR Multiplier | 2.0 |
| Trailing Distance | ATR × 2 (dynamic) |
| Minimum Distance | 15 points |
| Activation | 20 points in profit |
How ATR Trailing Works:
IF current ATR = 12 points: Trailing Distance = 12 × 2 = 24 pts IF price moves to 5540 (LONG from 5500): New Stop = 5540 - 24 = 5516 (Stop can only move UP, never back down) IF volatility increases, ATR = 20: Trailing Distance = 20 × 2 = 40 pts (wider stop) This prevents getting stopped out in volatile moves
Stop Movement Flow (LONG Example)
Entry: 5500, Original Stop: 5460
Price hits 5520 (+20 pts):
├── Trailing activates
├── ATR = 15 pts → Trail distance = 30 pts
└── New stop = 5520 - 30 = 5490
Price hits 5525 (+25 pts):
├── Breakeven activates
└── Stop moves to max(5490, 5502) = 5502
Price hits 5560 (+60 pts):
├── Trail: 5560 - 30 = 5530
└── Stop is now 5530 (locked +30 pts profit!)
Price reverses to 5530:
└── EXIT via STOP at 5530 = +30 pts profit
(Shows as "stop" exit but is profitable!)
Take Profit: 60 Points (1.5:1 R:R)
| Calculation | Logic |
|---|---|
| Primary | 50% of distance to MA21 |
| Minimum | Risk × 1.5 = 40 × 1.5 = 60 pts |
| Final Target | MAX(50% to MA, 60 pts) = Usually 60 pts |
Why 60 pts: Since we enter NEAR the MA (within 25 pts), 50% of that distance is small. The minimum of 60 pts ensures favorable R:R.
Timeout: 8 Hours Maximum
- If trade doesn't hit stop or target within 8 hours
- Exit at current market price
- Prevents overnight holding
Slippage Modeling
Realistic execution costs are modeled:
| Exit Type | Slippage Added |
|---|---|
| Entry (base) | 1.0 points |
| Stop Loss exit | +2.0 points (worse fill in fast move) |
| Take Profit exit | +0.5 points (better fill, limit order) |
| Market Impact | Up to 2.0 points (capped) |
Example:
- Entry at 5500 → Actual fill: 5501 (+1 pt slippage)
- Stop at 5460 → Actual fill: 5458 (-2 pts slippage for LONG)
- Target at 5560 → Actual fill: 5559.5 (-0.5 pts slippage)
PART 9: HOUR FILTER
Blocked Trading Hours
| Hour | IST Time | Reason |
|---|---|---|
| 9 | 9:00-10:00 AM | Market open volatility |
| 22 | 10:00-11:00 PM | Late session |
| 23 | 11:00-11:30 PM | Market close |
Allowed Trading Hours
Trading allowed: 10 AM to 9 PM IST (Hours 10-21)
PART 10: DIRECTION DETERMINATION
MA21 Slope Alignment (Hard Filter)
The primary direction filter:
| MA21 Slope | Allowed Direction | Logic |
|---|---|---|
| Rising (↗) | LONG only | Trade with uptrend |
| Declining (↘) | SHORT only | Trade with downtrend |
| Flat (→) | Use MTF direction | Let higher timeframes decide |
Direction Determination Algorithm
<source lang="python"> def determine_direction(ma21_slope, mtf_direction):
if ma21_slope == "rising":
return LONG # Only longs in uptrend
elif ma21_slope == "declining":
return SHORT # Only shorts in downtrend
else: # Flat
return mtf_direction # Use multi-timeframe consensus
</source>
PART 11: RISK MANAGEMENT
Position Sizing
| Parameter | Value |
|---|---|
| Position Size | 1 lot (100 barrels) |
| Risk per Trade | 40 pts × 100 = Rs 4,000 |
| Reward per Trade | 60 pts × 100 = Rs 6,000 |
| Max Concurrent Trades | 1 |
Cost Structure
| Cost Type | Value |
|---|---|
| Brokerage | Rs 20 per lot per leg (Dhan) |
| CTT | 0.01% on sell side |
| Total Round-trip | ~Rs 95 per trade |
PART 12: EQUITY CURVE
PART 13: BACKTEST RESULTS (19 Months)
Summary Statistics
| Metric | Value |
|---|---|
| Initial Capital | Rs 1.00 Lakhs |
| Final Value | Rs 26.48 Lakhs |
| Total Profit | Rs 25.48 Lakhs |
| Total Return | 2,548% |
| Peak Value | Rs 28.35 Lakhs |
| Max Drawdown | -78.6% |
Trade Statistics
| Metric | Value |
|---|---|
| Total Trades | 7,534 |
| Win Rate | 57.6% |
| Profit Factor | 1.20 |
| Average Win | Rs 3,464 |
| Average Loss | Rs 3,904 |
| Largest Win | Rs 26,799 |
| Largest Loss | Rs 13,217 |
| Avg Holding Time | 2.4 hours |
Exit Reason Breakdown
| Exit Type | Count | % | Note |
|---|---|---|---|
| Stop | 5,444 | 72.3% | Includes trailing stop profits |
| Target | 1,716 | 22.8% | 100% winners |
| Timeout | 374 | 5.0% | 8-hour limit |
Direction Distribution
| Direction | Count | % |
|---|---|---|
| SHORT | 6,024 | 80% |
| LONG | 1,510 | 20% |
Setup Quality Distribution
| Grade | Count | % |
|---|---|---|
| A+ | 3,457 | 45.9% |
| A | 551 | 7.3% |
| C | 3,526 | 46.8% |
Note: C-grade trades were analyzed but NOT executed per strategy rules
PART 14: HARD vs SOFT FILTERS
Understanding which rules reject trades outright vs which just affect scoring:
HARD FILTERS (Trade Rejected if Failed)
These filters block trades entirely - no exceptions:
| Filter | Rule | Effect |
|---|---|---|
| MA21 Slope Alignment | Direction must match MA21 slope | Rising MA = LONG only, Declining MA = SHORT only |
| Setup Grade | Must be A+, A, or B | C/D/F grades = NO TRADE |
| Hour Filter | Hours 9, 22, 23 blocked | Market open/close = NO TRADE |
| Price in MA Zone | Must be within ±25 pts of MA21 | Too far from MA = NO TRADE |
SOFT FILTERS (Affect Score, Don't Block)
These filters affect the quality score but don't block trades:
| Filter | Effect on Score | Can Still Pass? |
|---|---|---|
| MTF Alignment | 30% weight in grading | Yes, if other factors strong |
| Creeper Move | -50 penalty | Yes, if base score high enough |
| Railroad Trend | +15 bonus | N/A (bonus not required) |
| Price-MA Struggle | -30 penalty | Yes, if other factors compensate |
| Wrong Trend Phase | -25 penalty | Yes, if other factors compensate |
| Key Level Proximity | 20% weight in grading | Yes, affects grade not rejection |
| Institutional Fight | 0.7x multiplier | Yes, reduces but doesn't block |
Filter Flow
ENTRY CANDIDATE
│
▼
┌─────────────────────────────────────────┐
│ HARD FILTERS (any fail = NO TRADE) │
│ • MA21 slope alignment │
│ • Hour filter │
│ • Price in MA zone │
└─────────────────────────────────────────┘
│ ALL PASS
▼
┌─────────────────────────────────────────┐
│ SOFT FILTERS (calculate score) │
│ • MTF alignment (30% weight) │
│ • Trend strength (20% weight) │
│ • Key level proximity (20% weight) │
│ • Entry quality (15% weight) │
│ • Risk/Reward (15% weight) │
│ ± Penalties and Bonuses │
└─────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────┐
│ FINAL GRADE CHECK (HARD FILTER) │
│ Score ≥ 70 = B or better = TRADE │
│ Score < 70 = C or worse = NO TRADE │
└─────────────────────────────────────────┘
PART 15: KEY STRATEGY PRINCIPLES
- Trade WITH the trend - MA21 slope determines direction, never fight it
- Enter at value - Only when price is near MA21 zone (±25 pts)
- Quality over quantity - Only A+, A, B grade setups are traded
- Avoid creeper moves - -50 penalty ensures we skip poor quality price action
- Trade the MIDDLE - Focus on middle phase of trends, avoid early/late
- Dynamic stop management - Breakeven at 25 pts, trailing with ATR
- Time discipline - Maximum 8 hour holding period
- No overnight risk - All positions closed intraday
- Probability zones - Trade high probability zones only
- MTF as soft filter - Contributes to score, doesn't block alone
APPENDIX: SOURCE CODE REFERENCE
| File | Purpose |
|---|---|
trend_analysis_core.py |
MA slope, trend direction, price-MA struggle |
multi_timeframe_analysis.py |
MTF alignment scoring (5 timeframes) |
market_state_analysis.py |
Market state detection (7 algorithms) |
setup_quality_detection.py |
5-factor grading system |
probability_zone_analysis.py |
Zone-based filtering, Three-Finger Spread |
signal_generation_trade_management.py |
Entry/Exit logic, stop/target calculation |
trade_execution_engine.py |
Breakeven, Trailing stop, Slippage, Timeout |
Document generated from code analysis - January 2026
All rules extracted directly from source code implementation