PROTECTED SOURCE SCRIPT
已更新

Vegas plus by stanley

162
This Pine Script implements a comprehensive trend-following strategy known popularly as the **Vegas Tunnel Method**. It combines multiple Exponential Moving Averages (EMAs) to define trends, pullbacks, and breakouts.

Here is a step-by-step walkthrough of how the code works, broken down by its components and logic.

---

### 1. The Anatomy (The Indicators)
The script uses three distinct groups of Moving Averages to define the market structure.

#### A. The Fast EMAs (The Trigger & Exit)
* **EMA 12 (Signal):** The fastest line. It is used to trigger entries (crossing the tunnel).
* **EMA 21 (Exit):** Used as a trailing stop. If the price crosses this line against your trade, the script signals an exit.
* **EMA 55 (Filter):** A medium-term filter, often used visually to gauge trend health.

#### B. The "Hero" Tunnel (The Action Zone)
* **EMAs 144 & 169 & 200:** These creates the main "Tunnel."
* **Function:** This acts as dynamic Support and Resistance.
* **Bullish:** If the 144 (Top) is above the 200 (Bottom), the tunnel is painted Blue.
* **Bearish:** If the 144 is below the 200, it is painted Red.

#### C. The "Anchor" Tunnel (The Deep Trend)
* **EMAs 576 & 676:** This creates a massive, slow-moving background tunnel.
* **Function:** It tells you the long-term trend. Generally, you only want to take Buy signals if price is above this Anchor, though the script logic focuses primarily on the Hero tunnel for triggers.

---

### 2. State Memory (`var` Variables)
This is a sophisticated part of the script. It uses `var` variables to "remember" where the price was in the past.
* `originPrice`: Remembers if the price was last seen **Above** (1) or **Below** (-1) the tunnel.
* `originEMA`: Remembers if the EMA 12 was last seen **Above** (1) or **Below** (-1) the tunnel.

**Why is this needed?**
To distinguish between a **Breakout** (crossing from Bear to Bull) and a **Pullback** (already Bull, dipped into tunnel, and coming back out).

---

### 3. The Four Entry Triggers
The script looks for four specific scenarios to generate a Buy or Sell signal. You can turn these on/off in the settings.

#### Trigger 1: Price U-Turn (Trend Continuation)
* **Logic:** The Price was *already* above the tunnel (`originPrice == 1`), dipped down, and is now crossing back up (`crossover`).
* **Meaning:** This is a classic "Buy the Dip" signal within an existing trend.

#### Trigger 2: EMA U-Turn (Lagging Confirmation)
* **Logic:** Similar to Trigger 1, but uses the **EMA 12** line instead of the Price candle.
* **Meaning:** This is safer but slower. It waits for the average price to curl back out of the tunnel.

#### Trigger 3: Breakthrough (Momentum Shift)
* **Logic:** The EMA 12 was previously *below* the tunnel (`originEMA == -1`) and has just crossed *above* it (`crossover`).
* **Meaning:** This is a Trend Reversal signal. The market has shifted from Bearish to Bullish.

#### Trigger 4: Wick Rejection (Touch & Go)
* **Logic:**
1. Price is generally above the tunnel.
2. The `Low` of the current candle touches the tunnel.
3. The `Low` of the *previous* candle did NOT touch the tunnel.
4. The candle closes *outside* (above) the tunnel.
* **Meaning:** The price tested the support zone and was immediately rejected (bounced off), leaving a wick.

---

### 4. Trade Management (State Machine)
The script uses a variable called `tradeState` to manage signals so they don't spam your chart.

* `tradeState = 0`: Flat (No position).
* `tradeState = 1`: Long.
* `tradeState = -1`: Short.

**The Rules:**
1. **Entry:** If `validLong` is triggered AND `tradeState` is not already 1 -> Change state to 1 (Long) and plot a **BUY** label.
2. **Holding:** If you are already in State 1, the script ignores new Buy signals.
3. **Exit:** If `tradeState` is 1 AND price closes below EMA 21 -> Change state to 0 (Flat) and plot an **Exit L** label.

---

### 5. Visual Summary
* **Green Label:** Buy Signal (Long Entry).
* **Red Label:** Sell Signal (Short Entry).
* **Grey X:** Exit Signal (Close the position).
* **Blue/Red Tunnel:** The "Hero" tunnel (144/169/200).
* **Grey Background Tunnel:** The "Anchor" tunnel (576/676).

### How to read the signals:
You are looking for the price to interact with the **Hero Tunnel** (the thinner, brighter one).
1. **Trend:** Look at the slope of the Anchor (thick grey) tunnel.
2. **Setup:** Wait for price to come back to the Hero Tunnel.
3. **Trigger:** Wait for a **Green Label**. This means the price dipped into the tunnel and is now blasting out (U-Turn), or has rejected the tunnel (Wick), or has broken through a new trend (Breakthrough).
4. **Exit:** Close the trade when the **Grey X** appears (Price crosses the EMA 21).
發行說明
final version of the script
發行說明
Alright, let me walk you through this step by step. This indicator might look intimidating with all that code, but the concept is actually pretty intuitive once you see what it's doing.

---

## What This Indicator Actually Does

At its core, this is a **trend-following system** built around something called "tunnels" — which are just zones created by pairs of moving averages. The idea is simple: when price is above the tunnel, you're in bullish territory. When it's below, you're in bearish territory. When price is *inside* the tunnel, that's the messy in-between zone where you generally wait.

The indicator does three main things for you:

**It shows you the trend structure** through colored tunnel zones on your chart. Think of these like lanes on a highway — they tell you which direction traffic is flowing.

**It generates entry signals** (BUY/SELL labels) when specific conditions are met.

**It manages exits** automatically, including a "catastrophe stop" for when trades go wrong immediately.

---

## The Visual Elements (What You'll Actually See)

When you load this on a chart, you'll see several colored lines and shaded zones. Here's what each one means:

**The Fast EMAs (the quick-moving lines)**

The orange line (EMA 12) is your "signal" line — it's the fastest and most responsive. This is what triggers most of your entries.

The gray line (EMA 21) is your "trend confirmation" and also your exit trigger once a trade is working.

The lighter gray line (EMA 55) is your macro filter — it shows you the bigger picture trend.

**The Hero Tunnel (the main zone, 144-200 EMAs)**

This is the most important visual. It's the shaded zone in the middle of everything. When the tunnel is cyan/teal colored, the structure is bullish. When it's red, it's bearish. There's also a dotted blue line in the middle (169 EMA) that acts as a divider.

This tunnel is your "home base" for decision-making. Price bouncing off this tunnel or breaking through it is what generates most signals.

**The Mid Tunnel (288-338 EMAs)**

This is a secondary support/resistance zone further out. It's like a backup level — if price blows through the Hero Tunnel, this is the next area where it might find structure.

**The Anchor Tunnel (576-676 EMAs)**

This is the deep background level. It moves very slowly and represents major structural support/resistance. Think of it as the "last line of defense" for major trends.

---

## How to Read the Trend

Here's the simple version:

**Bullish setup:** Price is above the Hero Tunnel, and ideally the tunnel itself is cyan (meaning the 144 EMA is above the 200 EMA). Everything is stacked up — fast EMAs above slow EMAs, price above everything.

**Bearish setup:** The opposite. Price is below the Hero Tunnel, tunnel is red, fast EMAs are below slow EMAs.

**Choppy/Uncertain:** Price is bouncing around inside the tunnel, or the fast EMAs are crossing back and forth. This is when the indicator is basically saying "wait."

---

## The Four Entry Triggers

The indicator uses four different ways to generate entry signals. You can turn each one on or off in the settings, but here's what they're looking for:

**Trigger 1 — Price U-Turn**

This fires when price was above the tunnel, dipped *into* the tunnel (body inside), and then closes back above it. It's catching a pullback that failed to break down. Same logic inverted for shorts.

**Trigger 2 — EMA U-Turn**

Similar concept, but it's watching the 12 EMA instead of price. If the 12 EMA dips into the tunnel and then crosses back out in the original direction, that's a lagging confirmation that the pullback is over.

**Trigger 3 — Breakthrough**

This is for momentum shifts. If the 12 EMA was *below* the tunnel and then crosses *above* it, that's a potential trend change. This catches breakouts rather than pullbacks.

**Trigger 4 — Wick Rejection**

This is the "touch and go" signal. Price wicks into the tunnel (the low touches it) but the candle closes back outside. It's catching those quick tests of support that get immediately bought up.

When any of these conditions are met, you'll see a green "BUY" label below the candle or a red "SELL" label above it.

---

## How Exits Work

This is where it gets clever. The indicator has two types of exits:

**Standard Exit**

Once you're in a trade and price closes on the right side of the 21 EMA, your stop becomes "armed." After that, if price closes back on the wrong side of the 21 EMA, you exit. You'll see a gray X mark on the chart.

The key detail: the stop only arms *after the trade proves itself*. So if you go long and price immediately drops without ever closing above the 21 EMA, the standard exit doesn't fire yet.

**Catastrophe Exit**

This is the safety net. If you enter a trade and it immediately goes wrong — like you buy and price just tanks through the bottom of the tunnel without ever giving you a chance to profit — the catastrophe exit kicks in. You'll see an orange X with "FAIL" label.

The smart thing here is it uses a *snapshot* of where the tunnel was when you entered, not where it is now. So the floor doesn't chase price down.

---

## Practical Tips for Using This

**Start by just watching it.** Don't trade off it immediately. Load it up and watch how signals play out over a few weeks. You'll start to see which setups work in your market and which ones get chopped up.

**Timeframe matters.** This is built around the Vegas system which traditionally runs on higher timeframes (4H, Daily). The EMAs are pretty long (144, 200, 288, etc.), so on lower timeframes they're going to be very slow-moving. Not saying you can't use it on shorter timeframes, but know that the character will change.

**The tunnels are dynamic support/resistance.** Even if you don't trade the signals, the tunnel zones themselves are useful as reference levels. Price tends to react around these areas.

**Pay attention to tunnel color.** If you get a buy signal but the Hero Tunnel is red (bearish structure), you're essentially trying to catch a bottom in a downtrend. Higher risk. The cleanest trades happen when your signal direction matches the tunnel color.
發行說明
Enhanced rejection logic
發行說明
updated color

免責聲明

這些資訊和出版物並非旨在提供,也不構成TradingView提供或認可的任何形式的財務、投資、交易或其他類型的建議或推薦。請閱讀使用條款以了解更多資訊。