OPEN-SOURCE SCRIPT
Ratchet Exit Trend Strategy with VIX Filter

This strategy is a trend-following system designed specifically for volatile markets. Instead of focusing solely on the "perfect entry," this script emphasizes intelligent trade management using a custom **"Ratchet Exit System."**
Additionally, it integrates a volatility filter based on the CBOE Volatility Index (VIX) to minimize risk during extreme market phases.
### 🎯 The Concept: Ratchet Exit
The "Ratchet" system operates like a mechanical ratchet tool: the Stop Loss can only move in one direction (up, for long trades) and "locks" into specific stages. The goal is to give the trade "room to breathe" initially to avoid being stopped out by noise, then aggressively reduce risk as the trade moves into profit.
The exit logic moves through 3 distinct phases:
1. **Phase 0 (Initial Risk):** At the start of the trade, a wide Stop Loss is set (Default: 10%) to tolerate normal market volatility.
2. **Phase 1 (Risk Reduction):** Once the trade reaches a specific floating profit (Default: +10%), the Stop Loss is raised and "pinned" to a fixed value (Default: -8% from entry). This drastically reduces risk while keeping the trade alive.
3. **Phase 2 (Trailing Mode):** If the trend extends to a higher profit zone (Default: +15%), the Stop switches to a dynamic Trailing Mode. It follows the **Highest High** at a fixed percentage distance (Default: 8%).
### 🛡️ VIX Filter & Panic Exit
High volatility is often the enemy of trend-following strategies.
* **Entry Filter:** The system will not enter new positions if the VIX is above a user-defined threshold (Default: 32). This helps avoid entering "falling knife" markets.
* **Panic Exit:** If the VIX spikes above the threshold (32) while a trade is open, the position is closed immediately to protect capital (Emergency Exit).
### 📈 Entry Signals
The strategy trades **LONG only** and uses Simple Moving Averages (SMAs) to identify trends:
* **Golden Cross:** SMA 25 crosses over SMA 50.
* **3-Bar Breakouts:** A confirmation logic where the price must close above the SMA 50, 100, or 200 for 3 consecutive bars.
### ⚙️ Settings (Inputs)
All parameters are fully customizable via the settings menu:
* **SMAs:** Lengths for the trend indicators (Default: 25, 50, 100, 200).
* **VIX Filter:** Toggle the filter on/off and adjust the panic threshold.
* **Ratchet Settings:** Percentages for Initial Stop, Trigger Levels for Stages 1 & 2, and the Trailing Distance.
### ⚠️ Technical Note & Risk Warning
This script uses `request.security` to fetch VIX data. Please ensure you understand the risks associated with trading leveraged or volatile assets. Past performance is not indicative of future results.
Additionally, it integrates a volatility filter based on the CBOE Volatility Index (VIX) to minimize risk during extreme market phases.
### 🎯 The Concept: Ratchet Exit
The "Ratchet" system operates like a mechanical ratchet tool: the Stop Loss can only move in one direction (up, for long trades) and "locks" into specific stages. The goal is to give the trade "room to breathe" initially to avoid being stopped out by noise, then aggressively reduce risk as the trade moves into profit.
The exit logic moves through 3 distinct phases:
1. **Phase 0 (Initial Risk):** At the start of the trade, a wide Stop Loss is set (Default: 10%) to tolerate normal market volatility.
2. **Phase 1 (Risk Reduction):** Once the trade reaches a specific floating profit (Default: +10%), the Stop Loss is raised and "pinned" to a fixed value (Default: -8% from entry). This drastically reduces risk while keeping the trade alive.
3. **Phase 2 (Trailing Mode):** If the trend extends to a higher profit zone (Default: +15%), the Stop switches to a dynamic Trailing Mode. It follows the **Highest High** at a fixed percentage distance (Default: 8%).
### 🛡️ VIX Filter & Panic Exit
High volatility is often the enemy of trend-following strategies.
* **Entry Filter:** The system will not enter new positions if the VIX is above a user-defined threshold (Default: 32). This helps avoid entering "falling knife" markets.
* **Panic Exit:** If the VIX spikes above the threshold (32) while a trade is open, the position is closed immediately to protect capital (Emergency Exit).
### 📈 Entry Signals
The strategy trades **LONG only** and uses Simple Moving Averages (SMAs) to identify trends:
* **Golden Cross:** SMA 25 crosses over SMA 50.
* **3-Bar Breakouts:** A confirmation logic where the price must close above the SMA 50, 100, or 200 for 3 consecutive bars.
### ⚙️ Settings (Inputs)
All parameters are fully customizable via the settings menu:
* **SMAs:** Lengths for the trend indicators (Default: 25, 50, 100, 200).
* **VIX Filter:** Toggle the filter on/off and adjust the panic threshold.
* **Ratchet Settings:** Percentages for Initial Stop, Trigger Levels for Stages 1 & 2, and the Trailing Distance.
### ⚠️ Technical Note & Risk Warning
This script uses `request.security` to fetch VIX data. Please ensure you understand the risks associated with trading leveraged or volatile assets. Past performance is not indicative of future results.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.