OPEN-SOURCE SCRIPT
Atualizado MA200 + RSI Pullback + Hard Close

A long-only swing-trading indicator that signals entries when an
uptrending stock pulls back to oversold levels — but only during a
confirmed bullish market regime. Force-exits all signals when SPY
breaks its 200-day MA ("hard close").
═══ RULES ═══
• Entry: Close > MA200 AND RSI(14) < 40 AND SPY > SPY MA200 AND VIX < 30
• Exit : RSI > 70 OR Close < MA200 OR 2×ATR(14) trailing stop
• Hard close: exit ALL signals when SPY < SPY MA200 (regime kill switch)
═══ BACKTEST (499 S&P 500 stocks, 2008–2025, 0.1% commission) ═══
• Sharpe ratio: 1.25
• CAGR: 18.6%
• Max drawdown: -17.2%
• Trades: 1,719
• Win rate: 45.8%
• Avg hold: 18.7 days
═══ WALK-FORWARD VALIDATION ═══
• In-sample (2008–2018) Sharpe: 1.59
• Out-of-sample (2018–2025) Sharpe: 1.11
• IS → OOS degradation: ~30% (acceptable; classic edges often degrade 50%+)
• The hard-close filter cuts max drawdown ~9pp vs. the same strategy
without it — and makes IS/OOS more consistent (less regime-dependent).
═══ HOW TO USE ═══
• Daily timeframe, one ticker at a time (S&P 500 large-caps work best)
• Green triangle below bar = LONG signal
• Red triangle above bar = EXIT signal
• Red background = hard-close regime active (SPY in downtrend)
• Status table top-right = current state at a glance
• Five alert conditions provided (entry, all four exits)
═══ WHY IT WORKS ═══
The MA200 filter avoids catching falling knives. RSI < 40 in an uptrend
catches institutional panic that mean-reverts. The market filter and
hard close prevent participation in broad bear markets where mean-
reversion edges break down (2008, 2020, 2022).
═══ HONEST CAVEATS ═══
• Past performance ≠ future results.
• Backtested with ~10bps round-trip costs; higher costs degrade results.
• This is an INDICATOR, not an auto-executing strategy.
• Tested on US large-caps only. Behavior on small-caps, international,
ETFs, or crypto is untested or shown to underperform.
Not financial advice. Trade your own account. DYOR.
uptrending stock pulls back to oversold levels — but only during a
confirmed bullish market regime. Force-exits all signals when SPY
breaks its 200-day MA ("hard close").
═══ RULES ═══
• Entry: Close > MA200 AND RSI(14) < 40 AND SPY > SPY MA200 AND VIX < 30
• Exit : RSI > 70 OR Close < MA200 OR 2×ATR(14) trailing stop
• Hard close: exit ALL signals when SPY < SPY MA200 (regime kill switch)
═══ BACKTEST (499 S&P 500 stocks, 2008–2025, 0.1% commission) ═══
• Sharpe ratio: 1.25
• CAGR: 18.6%
• Max drawdown: -17.2%
• Trades: 1,719
• Win rate: 45.8%
• Avg hold: 18.7 days
═══ WALK-FORWARD VALIDATION ═══
• In-sample (2008–2018) Sharpe: 1.59
• Out-of-sample (2018–2025) Sharpe: 1.11
• IS → OOS degradation: ~30% (acceptable; classic edges often degrade 50%+)
• The hard-close filter cuts max drawdown ~9pp vs. the same strategy
without it — and makes IS/OOS more consistent (less regime-dependent).
═══ HOW TO USE ═══
• Daily timeframe, one ticker at a time (S&P 500 large-caps work best)
• Green triangle below bar = LONG signal
• Red triangle above bar = EXIT signal
• Red background = hard-close regime active (SPY in downtrend)
• Status table top-right = current state at a glance
• Five alert conditions provided (entry, all four exits)
═══ WHY IT WORKS ═══
The MA200 filter avoids catching falling knives. RSI < 40 in an uptrend
catches institutional panic that mean-reverts. The market filter and
hard close prevent participation in broad bear markets where mean-
reversion edges break down (2008, 2020, 2022).
═══ HONEST CAVEATS ═══
• Past performance ≠ future results.
• Backtested with ~10bps round-trip costs; higher costs degrade results.
• This is an INDICATOR, not an auto-executing strategy.
• Tested on US large-caps only. Behavior on small-caps, international,
ETFs, or crypto is untested or shown to underperform.
Not financial advice. Trade your own account. DYOR.
Notas de Lançamento
A long-only trend mean-reversion system for stocks. It buys qualitynames that are in an uptrend (price > 200-day MA) but temporarily
oversold (RSI < 40) — institutional panic that historically recovers.
Exits on RSI > 70, a close below the 200-MA, or a 2×ATR stop.
WHAT MAKES THIS DIFFERENT
This isn't a backtest fantasy. It was walk-forward validated:
parameters fit on 2008–2018, then tested untouched on 2018–2025.
The edge degraded ~30% out-of-sample — which is GOOD. A degradation
that small means the edge is real, not curve-fit. Most published
scripts hide their out-of-sample results. I lead with mine.
THE "HARD CLOSE" RULE
When SPY drops below its own 200-MA, the system closes everything
regardless of individual signals. This cut max drawdown from -25.9%
to -17.2% across 2008–2025 on the S&P 500 universe.
HONEST LIMITATIONS (rare on TV, I know)
• It's mean-reversion — it WILL catch some falling knives.
• Win rate is ~46%. The edge is in the asymmetry (avg win +8.2%
vs avg loss -3.9%), not in being right often.
• Tested on US large-caps. Don't assume it ports to crypto/forex.
• Backtest uses today's S&P 500 members (survivorship bias), so the
point-in-time numbers would be lower. The walk-forward DEGRADATION
is the honest signal here — not the absolute Sharpe.
HOW TO USE
Daily timeframe, one ticker at a time. The SPY-trend filter and the
VIX < 30 filter are toggles. The status table (top-right) shows
exactly which conditions are met right now.
Open-source under MPL 2.0 — read every line, change what you want.
If it earns a boost, it tells me the honest approach is worth
continuing. Comments welcome, especially critical ones.
Notas de Lançamento
A long-only trend mean-reversion system for stocks. It buys qualitynames that are in an uptrend (price > 200-day MA) but temporarily
oversold (RSI < 40) — institutional panic that historically recovers.
Exits on RSI > 70, a close below the 200-MA, or a 2×ATR stop.
WHAT MAKES THIS DIFFERENT
This isn't a backtest fantasy. It was walk-forward validated:
parameters fit on 2008–2018, then tested untouched on 2018–2025.
The edge degraded ~30% out-of-sample — which is GOOD. A degradation
that small means the edge is real, not curve-fit. Most published
scripts hide their out-of-sample results. I lead with mine.
THE "HARD CLOSE" RULE
When SPY drops below its own 200-MA, the system closes everything
regardless of individual signals. This cut max drawdown from -25.9%
to -17.2% across 2008–2025 on the S&P 500 universe.
HONEST LIMITATIONS (rare on TV, I know)
• It's mean-reversion — it WILL catch some falling knives.
• Win rate is ~46%. The edge is in the asymmetry (avg win +8.2%
vs avg loss -3.9%), not in being right often.
• Tested on US large-caps. Don't assume it ports to crypto/forex.
• Backtest uses today's S&P 500 members (survivorship bias), so the
point-in-time numbers would be lower. The walk-forward DEGRADATION
is the honest signal here — not the absolute Sharpe.
HOW TO USE
Daily timeframe, one ticker at a time. The SPY-trend filter and the
VIX < 30 filter are toggles. The status table (top-right) shows
exactly which conditions are met right now.
Script de código aberto
Em verdadeiro espírito do TradingView, o criador deste script o tornou de código aberto, para que os traders possam revisar e verificar sua funcionalidade. Parabéns ao autor! Embora você possa usá-lo gratuitamente, lembre-se de que a republicação do código está sujeita às nossas Regras da Casa.
Aviso legal
As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.
Script de código aberto
Em verdadeiro espírito do TradingView, o criador deste script o tornou de código aberto, para que os traders possam revisar e verificar sua funcionalidade. Parabéns ao autor! Embora você possa usá-lo gratuitamente, lembre-se de que a republicação do código está sujeita às nossas Regras da Casa.
Aviso legal
As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.