maXXit LevelTRG [V6 2.0]# maXXit Level Trigger — Overview
**Platform:** TradingView Pine Script v6 · Overlay indicator
---
## What does the Level Trigger do?
The Level Trigger automates trade entries and exits based on a freely configurable price level. False breakouts are filtered by an **N-closes confirmation** — only after N consecutive candles close through the level is an action triggered. The trigger fires JSON alerts to an external webhook server connected to a broker API (IBKR, OANDA, IG Markets).
If the signal generation is based on futures contracts (highly recommended), the mirror instruments are mapped through configurable parameters inside the script to the pre-configured broker API. The trigger does not fire position entries or exits inside TradingView directly. A plain-text message can be sent as an alternative.
All state machine logic runs **live only** — no historical replay arming.
---
## Flow (State Machine)
```
1. ARMED — Price touches the trigger level from the opposite side (intrabar, live bar only)
2. ENTRY — N consecutive closes back through the level → BUY / SELL alert
3. POSITION — Stop and TP monitor the open position
4. EXIT — SL or TP fires → closing order alert
```
---
## Features
| Feature | Description |
|---|---|
| **Long & Short** | Both directions configurable |
| **N-Closes (1–3)** | Consecutive closes required for arming confirmation, entry and SL/TP (Close mode) |
| **Live arming only** | Trigger arms only on real-time bars — no historical replay |
| **Trigger-level stop** | N closes back through the trigger level = automatic stop exit. Active only when no Absolute SL is set |
| **Absolute Stop Loss** | A separate SL level — fires immediately on intrabar touch, no close confirmation. When set, the trigger-level stop is deactivated |
| **Take Profit — Close mode** | TP arms on intrabar touch (high/low crosses TP level), exits on N consecutive closes back through TP |
| **Take Profit — Touch mode** | Exit fires immediately on intrabar TP touch |
| **Trailing stop** | Auto-stop locks at the TP level when TP is first reached — acts as a floor stop while price runs |
| **JSON alerts** | Direct broker integration (IBKR, OANDA, IG Markets) via webhook |
| **Symbol mapping** | Pre-defined instrument parameters for 15+ futures/CFDs |
| **Lock to Symbol** | Trigger stays bound to the selected instrument ticker prefix across chart changes |
| **Position Lock** | Preserves position state (LONG/SHORT) when inputs are changed mid-trade |
| **Fractal Grid** | Optional overlay of highest-high / lowest-low grids (5 levels, 10–50 bars) |
---
## Stop Loss Logic — Three-tier hierarchy
Only one tier is active at a time:
| Priority | Condition | Stop mechanism | Trigger |
|---|---|---|---|
| **1 — Absolute SL** | SL Level > 0 | Fixed price level | Intrabar touch — immediate |
| **2 — Auto-SL (TP lock)** | TP reached → auto_sl set | Old TP level becomes new stop | N consecutive closes through the level |
| **3 — Trigger-level stop** | No SL, no auto_sl | Trigger level acts as stop | N consecutive closes |
### How tiers interact
- When **Absolute SL is set**: tiers 2 and 3 are deactivated. Only the intrabar stop fires.
- When **TP is reached** (intrabar touch in Close mode): the TP level locks as a trailing stop (`auto_sl`). The Absolute SL can now be removed — `auto_sl` takes over with N-close confirmation.
- When **neither SL nor auto_sl is active**: the trigger level itself acts as the stop (N closes back through it).
### After a stop fires
The trigger does not re-arm automatically. To re-activate, change the Trigger Level input — this resets all state.
---
## Worked Example — LONG, N = 2 closes
**Setup:** Direction = LONG · Trigger = 5000 · TP = 5100 · Closes required = 2
### Phase 1 — Entry
| Event | What happens |
|---|---|
| Price dips below 5000 (intrabar, live) | Trigger **arms** — indicator starts watching |
| Price rises, 2 consecutive closes above 5000 | **Entry alert fired** → BUY order sent · stop activates at 5000 |
| Price dips back, 2 closes below 5000 (before TP) | **Stop exit** → SELL alert · trigger deactivates |
### Phase 2a — TP exit (Close mode, price reverses after TP)
| Event | What happens |
|---|---|
| Price rises through 5100 (intrabar) | TP **arms** — stop locks at 5100, indicator waits for reversal |
| Price falls back, 2 consecutive closes below 5100 | **TP exit alert** → SELL order sent · position closed |
### Phase 2b — Trailing stop (price keeps running above TP)
| Event | What happens |
|---|---|
| Price rises through 5100 | TP arms — stop **locks at 5100** (yellow line) |
| Price continues above 5100 | Position stays open · stop remains at 5100 |
| User raises TP to 5200 | `tp_armed` resets · stop stays locked at old 5100 level (use Active Position to preserve state) |
| Price reaches 5200 | Stop locks at 5200 |
| Price falls, 2 closes below 5200 | **Stop exit alert** → SELL order sent |
> The locked stop (old TP level) works exactly like the trigger-level stop: N consecutive closes through the level fire the exit.
### Workflow — raising TP while stop is locked
Pine Script resets all computed state (`tp_armed`, `auto_sl`) on every input change. To preserve the locked stop when raising TP:
| Step | Action |
|---|---|
| 1 | Note the current locked stop level (yellow line, e.g. 5100) |
| 2 | Set **Active Position** = `LONG` (or `SHORT`) |
| 3 | Set **Trigger Level** = locked stop value (e.g. 5100) |
| 4 | Set **TP Level** = new target (e.g. 5200) |
| 5 | After recalc: position restored · Trigger Level acts as stop · new TP active |
> **Why Trigger Level:** it is a persistent input that survives recalculation. When in position with no Absolute SL and no `auto_sl`, the trigger level acts as the N-closes stop.
---
## Visual Display
### Trigger label (at trigger level)
| State | Label | Color |
|---|---|---|
| Armed, LONG direction | TOUCHED ↑ | Green |
| Armed, SHORT direction | TOUCHED ↓ | Red |
| Active LONG position | LONG ↑ | Green |
| Active SHORT position | SHORT ↓ | Red |
| SL/Trigger crossed while in position | CAUTION | Orange |
| TP armed (acting as SL) | IDLE | Gray |
| No trigger configured | IDLE | Gray |
### SL label (at SL level)
| State | Label | Color |
|---|---|---|
| In LONG position | ARMED ▼ | Dark orange |
| In SHORT position | ARMED ▲ | Dark orange |
| Armed, LONG direction | ARMED ▼ | Dark orange |
| Armed, SHORT direction | ARMED ▲ | Dark orange |
| Hidden when TP is armed (TP line acts as SL) | — | — |
### TP label (at TP level)
| State | Label | Color |
|---|---|---|
| Position open, TP not yet reached | TP ACTIVE | Green |
| TP reached, acting as trailing stop (LONG) | SL ACTIVE ↑ | Green |
| TP reached, acting as trailing stop (SHORT) | SL ACTIVE ↓ | Red |
| TP exit just fired | TP CLOSED | Gray |
| No position | IDLE | Gray |
### Lines
- **Trigger line** — dashed · color matches trigger label state
- **SL line** — solid · dark orange when armed or in position · hidden when TP is acting as SL
- **TP line** — dashed · green (active) · color matches TP label state
- **Auto-SL line** — solid yellow · shows locked stop level when TP has armed
---
## Design Decisions & Rationale
### Why live-only arming (`barstate.isrealtime`)
All state machine logic runs only on real-time bars. Trigger levels are set manually based on the current Elliott Wave analysis. A historical simulation of manually-set levels would be meaningless — the level is valid only in the context of the current wave structure. Live-only arming ensures clean state on each session start and prevents false fills from historical data replay.
### Why the trigger does not re-arm automatically after exit
After a trade closes, re-entry at the same level requires re-analysis and a conscious decision. Re-arming is triggered by changing the Trigger Level input, which reloads all state. This is intentional: the wave structure has either confirmed or invalidated at that level.
### Why position sizing is manual
Risk per trade depends on the SL distance, which varies with each wave setup. The analyst calculates `quantity = max_risk_USD / (entry_price - SL_level)` before setting inputs. Automating this inside the script would require the entry price to be known in advance, which conflicts with the trigger-based entry mechanism.
### Why TradingView webhooks (no direct broker connection)
TradingView provides the charting and signal generation layer. The broker API integration lives in a separate webhook server. This separation keeps the Pine Script simple and broker-agnostic — switching brokers requires only a server-side change, not a script rewrite.
### Why N-closes confirmation instead of intrabar triggers
Intrabar wicks frequently penetrate Elliott levels without confirming. N confirmed closes through a level provide meaningful structure confirmation — a wick is noise, a close is a statement. The cost is a few points of slippage on the entry; the benefit is fewer false signals.
### Why TP Close mode arms on intrabar touch (not N closes)
TP is a profit target, not a structural level. Waiting for N closes above the TP level before arming would delay the trailing stop activation unnecessarily — the first intrabar touch is sufficient evidence that the target was reached. The exit itself still requires N closes back through the TP level, preserving the confirmation logic on the way out.
---
## Settings Reference
| Input | Group | Description |
|---|---|---|
| Send JSON Alert | Account & Broker | ON = JSON webhook · OFF = plain-text alert |
| Webhook Secret | Account & Broker | Token included in JSON payload for server authentication |
| Account ID | Account & Broker | Broker account identifier (IBKR, OANDA, IG Markets, etc.) |
| Use predefined mapping | Instrument | Uses built-in symbol → broker mapping table |
| Mirror Trade | Instrument | NO = trade the chart future · YES = trade mirror instrument (STK/CFD) |
| Mirror Instrument | Instrument | STK (IBKR ETF) or CFD (OANDA / IG Markets) |
| Quantity | Instrument | Size of the order |
| Direction | Level Trigger | LONG or SHORT |
| Trigger Level | Level Trigger | Price level. 0 = disarmed |
| Stop Loss Level | Level Trigger | Absolute SL. 0 = use trigger-level stop instead |
| TP Level | Level Trigger | Take profit level. 0 = disabled |
| TP Arm Mode | Level Trigger | Touch = immediate intrabar exit · Close = N-close reversal confirmation |
| Closes required | Level Trigger | 1–3 consecutive closes needed for arming, entry and SL/TP |
| Lock to Symbol | Level Trigger | Ticker prefix to lock trigger to one instrument (e.g. MNQ, FXXP) |
| Active Position | Level Trigger | Auto / LONG / SHORT — preserves position state across input changes |
| Fractal Grid | Position Management | Shows highest-high / lowest-low grid overlay |
---
## Supported Instruments
| Prefix | Instrument | Exchange | Mirror (STK) | Mirror (CFD OANDA) | Mirror (CFD IG) |
|---|---|---|---|---|---|
| MNQ | Micro Nasdaq-100 | CME | QQQ | NAS100_USD | NASDAQ |
| MES | Micro S&P 500 | CME | SPY | SPX500_USD | SPTRD |
| MYM | Micro Dow Jones | CBOT | DIA | US30_USD | DOW |
| FXXP / FSXE | Euro Stoxx 50 | EUREX | IMEU | EU50_EUR | STXE |
| MGC | Micro Gold | COMEX | GLD | XAU_USD | SPOTGOLD |
| MCL | Micro Crude Oil | NYMEX | USO | WTICO_USD | USOIL |
| MNG | Micro Nat Gas | NYMEX | — | NATGAS_USD | NATURALGAS |
| MHG | Micro Copper | COMEX | — | XCU_USD | COPPER |
| ZW | Wheat | CBOT | — | WHEAT_USD | — |
| ZN | 10Y T-Note | CBOT | — | USB10Y_USD | — |
| CN1 | FTSE China A50 | SGX | — | CN50_USD | — |
| EURUSD | EUR/USD Spot | IDEALPRO | — | EUR_USD | — |
| BTCUSD | Bitcoin | — | — | BTC_USD | BITCOIN |
| ETHUSD | Ethereum | — | — | ETH_USD | ETHUSD |
---
## Later Enhancements Planned
| # | Enhancement | Rationale |
|---|---|---|
| **1** | **Multi-level trigger** — two simultaneous trigger levels with independent directions | Allows monitoring Wave 3 and Wave 5 levels simultaneously without two separate chart instances |
| **2** | **Partial exits / scale-out** — e.g. 50% at TP1, remainder with trailing stop | Elliott Wave extensions are common; closing the full position at the first TP level often leaves significant profit on the table |
| **3** | **Volatility-adaptive N-closes** — automatically tighten/loosen confirmation count based on ATR or session volatility | A single N-close setting behaves differently in a quiet overnight session vs. a high-impact news event |
Chỉ báo






















