OPEN-SOURCE SCRIPT
Trend Breakout & Ratchet Stop System [Market Filter]

Description:
This strategy implements a robust trend-following system designed to capture momentum moves while strictly managing downside risk through a multi-stage "Ratchet" exit mechanism and broad market filters.
It is designed for swing traders who want to align individual stock entries with the overall market direction.
How it works:
1. Market Regime Filters (The "Safety Check") Before taking any position, the strategy checks the health of the broader market to avoid "catching falling knives."
Broad Market Filter: By default, it checks NASDAQ:QQQ (adjustable). If the benchmark is trading below its SMA 200, the strategy assumes a Bear Market and suppresses all new long entries.
Volatility Filter (VIX): Uses CBOE:VIX to gauge fear. If the VIX is above a specific threshold (Default: 32), entries are paused, and existing positions can optionally be closed to preserve capital.
2. Entry Logic Entries are based on Momentum and Trend confirmation. A position is opened if filters are clear AND one of the following occurs:
Golden Cross: SMA 25 crosses over SMA 50.
SMA Breakouts: A "Three-Bar-Break" logic confirms a breakout above the SMA 50, 100, or 200 (price must establish itself above the moving average).
3. The "Ratchet" Exit System The exit logic evolves as the trade progresses, tightening risk like a ratchet:
Stage 0 (Initial Risk): Starts with a standard percentage Stop Loss from the entry price.
Stage 1 (Breakeven/Lock): Once the price rises by Profit Step 1 (e.g., +10%), the Stop Loss jumps to a tighter level and locks there. This secures the initial move.
Stage 2 (Trailing Mode): If the price continues to rise to Profit Step 2 (e.g., +15%), the Stop Loss converts into a dynamic Trailing Stop relative to the Highest High. This allows the trade to run as long as the trend persists.
Additional Exits:
Dead Cross: Closes position if SMA 25 crosses under SMA 50.
VIX Panic: Emergency exit if volatility spikes above the threshold.
Settings & Customization:
SMAs: Adjustable lengths for all Moving Averages.
Filters: Toggle Market/VIX filters on/off and choose your benchmark ticker (e.g., SPY or QQQ).
Risk Management: Fully customizable percentages for the Ratchet steps (Initial SL, Stage 1 Trigger, Trailing distance).
This strategy implements a robust trend-following system designed to capture momentum moves while strictly managing downside risk through a multi-stage "Ratchet" exit mechanism and broad market filters.
It is designed for swing traders who want to align individual stock entries with the overall market direction.
How it works:
1. Market Regime Filters (The "Safety Check") Before taking any position, the strategy checks the health of the broader market to avoid "catching falling knives."
Broad Market Filter: By default, it checks NASDAQ:QQQ (adjustable). If the benchmark is trading below its SMA 200, the strategy assumes a Bear Market and suppresses all new long entries.
Volatility Filter (VIX): Uses CBOE:VIX to gauge fear. If the VIX is above a specific threshold (Default: 32), entries are paused, and existing positions can optionally be closed to preserve capital.
2. Entry Logic Entries are based on Momentum and Trend confirmation. A position is opened if filters are clear AND one of the following occurs:
Golden Cross: SMA 25 crosses over SMA 50.
SMA Breakouts: A "Three-Bar-Break" logic confirms a breakout above the SMA 50, 100, or 200 (price must establish itself above the moving average).
3. The "Ratchet" Exit System The exit logic evolves as the trade progresses, tightening risk like a ratchet:
Stage 0 (Initial Risk): Starts with a standard percentage Stop Loss from the entry price.
Stage 1 (Breakeven/Lock): Once the price rises by Profit Step 1 (e.g., +10%), the Stop Loss jumps to a tighter level and locks there. This secures the initial move.
Stage 2 (Trailing Mode): If the price continues to rise to Profit Step 2 (e.g., +15%), the Stop Loss converts into a dynamic Trailing Stop relative to the Highest High. This allows the trade to run as long as the trend persists.
Additional Exits:
Dead Cross: Closes position if SMA 25 crosses under SMA 50.
VIX Panic: Emergency exit if volatility spikes above the threshold.
Settings & Customization:
SMAs: Adjustable lengths for all Moving Averages.
Filters: Toggle Market/VIX filters on/off and choose your benchmark ticker (e.g., SPY or QQQ).
Risk Management: Fully customizable percentages for the Ratchet steps (Initial SL, Stage 1 Trigger, Trailing distance).
Скрипт с открытым кодом
В истинном духе TradingView, создатель этого скрипта сделал его открытым исходным кодом, чтобы трейдеры могли проверить и убедиться в его функциональности. Браво автору! Вы можете использовать его бесплатно, но помните, что перепубликация кода подчиняется нашим Правилам поведения.
Отказ от ответственности
Информация и публикации не предназначены для предоставления и не являются финансовыми, инвестиционными, торговыми или другими видами советов или рекомендаций, предоставленных или одобренных TradingView. Подробнее читайте в Условиях использования.
Скрипт с открытым кодом
В истинном духе TradingView, создатель этого скрипта сделал его открытым исходным кодом, чтобы трейдеры могли проверить и убедиться в его функциональности. Браво автору! Вы можете использовать его бесплатно, но помните, что перепубликация кода подчиняется нашим Правилам поведения.
Отказ от ответственности
Информация и публикации не предназначены для предоставления и не являются финансовыми, инвестиционными, торговыми или другими видами советов или рекомендаций, предоставленных или одобренных TradingView. Подробнее читайте в Условиях использования.