OPEN-SOURCE SCRIPT
NA GPT - TTM Squeeze Strategy

**NA GPT - TTM Squeeze Strategy**” transforms the well-known TTM Squeeze indicator into a back-testable, long-only strategy.
It combines **volatility compression** (Bollinger Bands inside Keltner Channels) with **momentum confirmation** to catch powerful bullish breakouts and then trails positions with a simple 21-period moving-average stop.
---
## 1. Core Concepts & Calculations
| Component | What it measures | How it works |
| ---------------------- | ------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Squeeze State** | Volatility contraction vs. expansion | • Calculate a 20-period Bollinger Band (BB). <br>• Calculate a 20-period Keltner Channel (KC). <br>• **Squeeze ON** when the entire BB is *inside* the KC (narrow volatility). |
| **Momentum Histogram** | Direction & strength of pressure building inside the squeeze | • Compute the midpoint of the recent high/low range and the 20-period SMA of close. <br>• Take the price’s deviation from that blended average. <br>• Fit a **20-period linear regression** to that deviation to produce the histogram. <br>• Color logic: ↗ increasing green/lime for strengthening bulls, ↘ red/maroon for bears. |
| **Blue-Dot Theme** | Visual cue of squeeze state | • **Navy-blue dot** = Squeeze ON (ready to pop). <br>• **Steel-blue dot** = Squeeze just released. <br>• **Sky-blue dot** = Neutral (no squeeze). |
---
## 2. Trade Logic
| Step | Condition | Rationale |
| ---------------- | ------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
| **Entry (Long)** | Three consecutive navy-blue dots (i.e., **3 bars with Squeeze ON in a row**) *inside the user-defined date window*. | Requires sustained volatility compression before committing capital, filtering out one-bar “fake” squeezes. |
| **Exit (Flat)** | Close price **crosses below** the 21-period Simple Moving Average. | A classic trailing stop that lets profits run while cutting momentum failures. |
| **Positioning** | Long-only, one trade at a time. No short sales. | Focuses on bullish breakouts, keeps strategy simple and margin-friendly. |
---
## 3. Inputs & Customisation
| Input | Default | Purpose |
| -------------------------- | ------------------------ | ---------------------------------------------- |
| **BB Length / Multiplier** | 20 / 2.0 | Adjust sensitivity of Bollinger Bands. |
| **KC Length / Multiplier** | 20 / 1.5 | Adjust Keltner Channel width. |
| **Use True Range (KC)** | ✔ | Pick *True Range* vs. *High-Low* for KC width. |
| **Trade Window** | 1 Jan 2022 → 31 Dec 2069 | Back-test only the period you care about. |
| **Commission** | 0.01 % | Embedded in `strategy()` header. |
| **Slippage (Ticks)** | 3 | Models real-world order fill uncertainty. |
---
## 4. Visual Outputs
* **Momentum Histogram** (green / lime / red / maroon).
* **Zero Line** colored by squeeze state (blue / dark navy / grey).
* **Blue-Dot Row** at the chart bottom showing squeeze timing.
The visuals are **identical** to the original indicator, letting you correlate back-test trades with familiar chart cues.
---
## 5. How to Use
1. **Add to chart**, choose your symbol & timeframe (works on anything from 1-minute to weekly).
2. **Tune the BB/KC/ATR settings** to match instrument volatility.
3. **Adjust the date window** for focused walk-forward testing.
4. Run the “**Strategy Tester**” to inspect historical performance, P\&L curves, drawdowns, and trade list.
5. Use the plotted dots & histogram to visually validate why each trade fired.
6. Combine with your own risk-management (position sizing, portfolio filters, etc.) before going live.
---
## 6. Practical Notes
* Designed for educational/back-testing purposes—**not financial advice**.
* Long-only by design; add your own short logic if desired.
* Because exits rely on the 21-SMA, extremely low-volume instruments or illiquid intraday timeframes may experience wider drawdowns.
* Commission/slippage values are easily editable in the first line of the script.
It combines **volatility compression** (Bollinger Bands inside Keltner Channels) with **momentum confirmation** to catch powerful bullish breakouts and then trails positions with a simple 21-period moving-average stop.
---
## 1. Core Concepts & Calculations
| Component | What it measures | How it works |
| ---------------------- | ------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Squeeze State** | Volatility contraction vs. expansion | • Calculate a 20-period Bollinger Band (BB). <br>• Calculate a 20-period Keltner Channel (KC). <br>• **Squeeze ON** when the entire BB is *inside* the KC (narrow volatility). |
| **Momentum Histogram** | Direction & strength of pressure building inside the squeeze | • Compute the midpoint of the recent high/low range and the 20-period SMA of close. <br>• Take the price’s deviation from that blended average. <br>• Fit a **20-period linear regression** to that deviation to produce the histogram. <br>• Color logic: ↗ increasing green/lime for strengthening bulls, ↘ red/maroon for bears. |
| **Blue-Dot Theme** | Visual cue of squeeze state | • **Navy-blue dot** = Squeeze ON (ready to pop). <br>• **Steel-blue dot** = Squeeze just released. <br>• **Sky-blue dot** = Neutral (no squeeze). |
---
## 2. Trade Logic
| Step | Condition | Rationale |
| ---------------- | ------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
| **Entry (Long)** | Three consecutive navy-blue dots (i.e., **3 bars with Squeeze ON in a row**) *inside the user-defined date window*. | Requires sustained volatility compression before committing capital, filtering out one-bar “fake” squeezes. |
| **Exit (Flat)** | Close price **crosses below** the 21-period Simple Moving Average. | A classic trailing stop that lets profits run while cutting momentum failures. |
| **Positioning** | Long-only, one trade at a time. No short sales. | Focuses on bullish breakouts, keeps strategy simple and margin-friendly. |
---
## 3. Inputs & Customisation
| Input | Default | Purpose |
| -------------------------- | ------------------------ | ---------------------------------------------- |
| **BB Length / Multiplier** | 20 / 2.0 | Adjust sensitivity of Bollinger Bands. |
| **KC Length / Multiplier** | 20 / 1.5 | Adjust Keltner Channel width. |
| **Use True Range (KC)** | ✔ | Pick *True Range* vs. *High-Low* for KC width. |
| **Trade Window** | 1 Jan 2022 → 31 Dec 2069 | Back-test only the period you care about. |
| **Commission** | 0.01 % | Embedded in `strategy()` header. |
| **Slippage (Ticks)** | 3 | Models real-world order fill uncertainty. |
---
## 4. Visual Outputs
* **Momentum Histogram** (green / lime / red / maroon).
* **Zero Line** colored by squeeze state (blue / dark navy / grey).
* **Blue-Dot Row** at the chart bottom showing squeeze timing.
The visuals are **identical** to the original indicator, letting you correlate back-test trades with familiar chart cues.
---
## 5. How to Use
1. **Add to chart**, choose your symbol & timeframe (works on anything from 1-minute to weekly).
2. **Tune the BB/KC/ATR settings** to match instrument volatility.
3. **Adjust the date window** for focused walk-forward testing.
4. Run the “**Strategy Tester**” to inspect historical performance, P\&L curves, drawdowns, and trade list.
5. Use the plotted dots & histogram to visually validate why each trade fired.
6. Combine with your own risk-management (position sizing, portfolio filters, etc.) before going live.
---
## 6. Practical Notes
* Designed for educational/back-testing purposes—**not financial advice**.
* Long-only by design; add your own short logic if desired.
* Because exits rely on the 21-SMA, extremely low-volume instruments or illiquid intraday timeframes may experience wider drawdowns.
* Commission/slippage values are easily editable in the first line of the script.
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Declinazione di responsabilità
Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Declinazione di responsabilità
Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.