PROTECTED SOURCE SCRIPT
Madstrat 2.0 Strategy

Madstrat 2.0 Strategy Overview
A multi-timeframe trading strategy implementing the Madstrat methodology with dual timeframe systems (15m/1hr and 30m/2hr), sophisticated day classification, and exhaustion-based exits.
---
Signal Types (Priority Order)
1. **Day 3 Signals** - GSD/RSD Day 3 with full confluence
2. **Day 2 Signals** - GSD/RSD Day 2 with full confluence
3. **M3 EQ Entry** - HTF 50 EMA rejection at equilibrium + LTF 50 SMA touch + 9/50 cross
4. **Pure Madstrat** - All confluence requirements except day count
---
Function Reference
Instrument & Tolerance
| Function | Purpose |
|----------|---------|
| `f_get_baseline_tolerance()` | Returns adaptive pip tolerance—wider for gold (~150 ticks), tighter for forex (~80 pips) |
| `f_get_breakout_points()` | Returns breakout threshold by instrument type |
Day Classification Engine (5m Authoritative)
| Function | Purpose |
|----------|---------|
| `f_day_state_5m()` | **Core engine**: handles rollover detection, daily/weekly OHLC, GSD/RSD counting, inside days, FBR, clean breakouts |
| `f_get_power_of_3_count()` | Maps DOW to Power of 3 (Mon=1, Tue=2, Wed=3, Thu=2, Fri=3) |
Touch & Alignment Detection
| Function | Purpose |
|----------|---------|
| `f_baseline_touch_buy/sell()` | Detects 50 EMA touch with directional close |
| `f_touch_buy/sell()` | Generic level touch detection |
| `f_update_touch_counter()` | Increments/resets touch bar counters |
| `f_stack_buy/sell()` | Full stack check: `close > 9 > 18 > 50 EMA > 50 SMA` |
| `f_ema_alignment_buy/sell()` | Basic 9/18 EMA alignment |
| `f_ema_slope_bullish/bearish()` | All EMAs sloping same direction |
| `f_candle_closed_above/below_emas()` | Candle position vs 9/18 EMAs |
Setup Grading & HTF Confirmation
| Function | Purpose |
|----------|---------|
| `f_grade_setup()` | Grades A/B setup based on multi-TF alignment + candle direction |
| `f_htf_rejection_bearish/bullish()` | Detects HTF 50 EMA rejection patterns |
Confluence Scoring
| Function | Purpose |
|----------|---------|
| `f_get_required_confluence()` | Dynamic score requirement by day count (Day 1→5, Day 2→4, Day 3+→3) |
| `f_confluence_score_day3()` | Scores Day 2/3 signals (max 10 factors) |
| `f_confluence_score_pure()` | Scores Pure signals (max 9 factors) |
Position & Risk Management
| Function | Purpose |
|----------|---------|
| `f_position_size()` | Calculates qty from entry, SL, and risk % |
| `f_calculate_rr()` | Computes risk-reward ratio |
| `f_find_swing_high/low()` | Locates historical swings for TP3 |
| `f_partial_close_longs/shorts()` | Closes % of all long/short entries |
| `f_close_all_longs/shorts()` | Full position close |
Exhaustion Areas (M1/M2)
| Function | Purpose |
|----------|---------|
| `f_is_bullish/bearish_candle()` | Candle direction check |
| `f_create_exhaustion_box()` | Draws exhaustion zone visualization |
Session & Utilities
| Function | Purpose |
|----------|---------|
| `f_session_string()` | Formats session time range |
| `f_get_label_size()` | Converts string to `size.*` constant |
| `f_chart_tf_minutes()` | Current chart TF in minutes |
UI Tables
| Function | Purpose |
|----------|---------|
| `f_auto_system()` / `f_selected_system()` | Auto-selects 15m or 30m system based on chart TF |
| `f_draw_confluence_table()` | Renders confluence scoring panel |
| `f_draw_status_table()` | Renders status/signal panel |
| `f_status_row/header()`, `f_touch_status_text()` | Table cell helpers |
---
Exit System
| Exit | Trigger | Action |
|------|---------|--------|
| **TP1** | Price hits PDH (longs) / PDL (shorts) | Close 50% |
| **TP2** | Price hits PWH / PWL | Close 30% (60% of remaining) |
| **TP3** | Price hits next swing level | Close remaining 20% |
| **M1-R1** | Test exhaustion zone + reject | Close 50% |
| **M1-R2** | Break exhaustion + return | Close 50% |
| **Stop Loss** | EMAs reverse + break entry candle | Full close |
---
Key Entry Requirements
- **All levels touched** (9/18/50 EMA + 50 SMA)
- **Full stack alignment**
- **5m EMA confirmation**
- **HTF baseline + EQ touch** (within lookback)
- **EQ rejection** (optional)
- **Minimum RR threshold**
- **Session filter** (optional)
- **No inside day**
A multi-timeframe trading strategy implementing the Madstrat methodology with dual timeframe systems (15m/1hr and 30m/2hr), sophisticated day classification, and exhaustion-based exits.
---
Signal Types (Priority Order)
1. **Day 3 Signals** - GSD/RSD Day 3 with full confluence
2. **Day 2 Signals** - GSD/RSD Day 2 with full confluence
3. **M3 EQ Entry** - HTF 50 EMA rejection at equilibrium + LTF 50 SMA touch + 9/50 cross
4. **Pure Madstrat** - All confluence requirements except day count
---
Function Reference
Instrument & Tolerance
| Function | Purpose |
|----------|---------|
| `f_get_baseline_tolerance()` | Returns adaptive pip tolerance—wider for gold (~150 ticks), tighter for forex (~80 pips) |
| `f_get_breakout_points()` | Returns breakout threshold by instrument type |
Day Classification Engine (5m Authoritative)
| Function | Purpose |
|----------|---------|
| `f_day_state_5m()` | **Core engine**: handles rollover detection, daily/weekly OHLC, GSD/RSD counting, inside days, FBR, clean breakouts |
| `f_get_power_of_3_count()` | Maps DOW to Power of 3 (Mon=1, Tue=2, Wed=3, Thu=2, Fri=3) |
Touch & Alignment Detection
| Function | Purpose |
|----------|---------|
| `f_baseline_touch_buy/sell()` | Detects 50 EMA touch with directional close |
| `f_touch_buy/sell()` | Generic level touch detection |
| `f_update_touch_counter()` | Increments/resets touch bar counters |
| `f_stack_buy/sell()` | Full stack check: `close > 9 > 18 > 50 EMA > 50 SMA` |
| `f_ema_alignment_buy/sell()` | Basic 9/18 EMA alignment |
| `f_ema_slope_bullish/bearish()` | All EMAs sloping same direction |
| `f_candle_closed_above/below_emas()` | Candle position vs 9/18 EMAs |
Setup Grading & HTF Confirmation
| Function | Purpose |
|----------|---------|
| `f_grade_setup()` | Grades A/B setup based on multi-TF alignment + candle direction |
| `f_htf_rejection_bearish/bullish()` | Detects HTF 50 EMA rejection patterns |
Confluence Scoring
| Function | Purpose |
|----------|---------|
| `f_get_required_confluence()` | Dynamic score requirement by day count (Day 1→5, Day 2→4, Day 3+→3) |
| `f_confluence_score_day3()` | Scores Day 2/3 signals (max 10 factors) |
| `f_confluence_score_pure()` | Scores Pure signals (max 9 factors) |
Position & Risk Management
| Function | Purpose |
|----------|---------|
| `f_position_size()` | Calculates qty from entry, SL, and risk % |
| `f_calculate_rr()` | Computes risk-reward ratio |
| `f_find_swing_high/low()` | Locates historical swings for TP3 |
| `f_partial_close_longs/shorts()` | Closes % of all long/short entries |
| `f_close_all_longs/shorts()` | Full position close |
Exhaustion Areas (M1/M2)
| Function | Purpose |
|----------|---------|
| `f_is_bullish/bearish_candle()` | Candle direction check |
| `f_create_exhaustion_box()` | Draws exhaustion zone visualization |
Session & Utilities
| Function | Purpose |
|----------|---------|
| `f_session_string()` | Formats session time range |
| `f_get_label_size()` | Converts string to `size.*` constant |
| `f_chart_tf_minutes()` | Current chart TF in minutes |
UI Tables
| Function | Purpose |
|----------|---------|
| `f_auto_system()` / `f_selected_system()` | Auto-selects 15m or 30m system based on chart TF |
| `f_draw_confluence_table()` | Renders confluence scoring panel |
| `f_draw_status_table()` | Renders status/signal panel |
| `f_status_row/header()`, `f_touch_status_text()` | Table cell helpers |
---
Exit System
| Exit | Trigger | Action |
|------|---------|--------|
| **TP1** | Price hits PDH (longs) / PDL (shorts) | Close 50% |
| **TP2** | Price hits PWH / PWL | Close 30% (60% of remaining) |
| **TP3** | Price hits next swing level | Close remaining 20% |
| **M1-R1** | Test exhaustion zone + reject | Close 50% |
| **M1-R2** | Break exhaustion + return | Close 50% |
| **Stop Loss** | EMAs reverse + break entry candle | Full close |
---
Key Entry Requirements
- **All levels touched** (9/18/50 EMA + 50 SMA)
- **Full stack alignment**
- **5m EMA confirmation**
- **HTF baseline + EQ touch** (within lookback)
- **EQ rejection** (optional)
- **Minimum RR threshold**
- **Session filter** (optional)
- **No inside day**
Skrip terproteksi
Skrip ini diterbitkan sebagai sumber tertutup. Namun, Anda dapat menggunakannya dengan bebas dan tanpa batasan apa pun – pelajari lebih lanjut di sini.
Pernyataan Penyangkalan
Informasi dan publikasi ini tidak dimaksudkan, dan bukan merupakan, saran atau rekomendasi keuangan, investasi, trading, atau jenis lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Ketentuan Penggunaan.
Skrip terproteksi
Skrip ini diterbitkan sebagai sumber tertutup. Namun, Anda dapat menggunakannya dengan bebas dan tanpa batasan apa pun – pelajari lebih lanjut di sini.
Pernyataan Penyangkalan
Informasi dan publikasi ini tidak dimaksudkan, dan bukan merupakan, saran atau rekomendasi keuangan, investasi, trading, atau jenis lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Ketentuan Penggunaan.