OPEN-SOURCE SCRIPT
oppliger trendfollow

📈 Strategy Overview: SMA25 vs SMA200 – Gap Momentum Trend Strategy
This strategy is a trend-following system designed to capture strong, accelerating uptrends while exiting early when momentum begins to fade.
It uses the relationship between two moving averages — the 25-period SMA and the 200-period SMA — and monitors the gap (distance) between them as a measure of trend strength.
🟢 Entry Conditions (Go Long)
A long position is opened only when all of the following conditions are true:
Uptrend confirmation:
The 25-period SMA is above the 200-period SMA
→ confirms a clear upward trend.
Price momentum:
The closing price is above the SMA25 line,
→ showing that the market currently trades with bullish momentum.
Trend acceleration:
The gap between SMA25 and SMA200 has been increasing for the last 5 consecutive bars.
→ mathematically:
gap_t > gap_(t-1) > gap_(t-2) > gap_(t-3) > gap_(t-4)
→ indicates that the short-term trend is pulling away from the long-term trend and accelerating upward.
✅ When all three conditions are met, the strategy enters a long trade at the close of the current candle.
🔴 Exit Conditions (Close Long)
The position is closed when the uptrend starts to lose strength:
Trend deceleration:
The gap between SMA25 and SMA200 has been shrinking for 3 consecutive bars.
→ mathematically:
gap_t < gap_(t-1) < gap_(t-2)
→ signals that the short-term moving average is converging toward the long-term average, showing weakening momentum.
🚪 When this condition is met, the strategy closes the position at market price.
⚙️ Summary of Logic
Phase Condition Meaning
Entry SMA25 > SMA200 Long-term trend is up
Entry Close > SMA25 Short-term momentum is bullish
Entry Gap rising 5 bars Trend is accelerating
Exit Gap falling 3 bars Trend is weakening
💡 Interpretation
This strategy aims to:
Enter only when a strong, accelerating uptrend is confirmed.
Stay in the trade as long as momentum remains intact.
Exit early when the market starts losing strength, before the trend fully reverses.
It works best in trending markets and helps avoid false entries during sideways or weak phases.
This strategy is a trend-following system designed to capture strong, accelerating uptrends while exiting early when momentum begins to fade.
It uses the relationship between two moving averages — the 25-period SMA and the 200-period SMA — and monitors the gap (distance) between them as a measure of trend strength.
🟢 Entry Conditions (Go Long)
A long position is opened only when all of the following conditions are true:
Uptrend confirmation:
The 25-period SMA is above the 200-period SMA
→ confirms a clear upward trend.
Price momentum:
The closing price is above the SMA25 line,
→ showing that the market currently trades with bullish momentum.
Trend acceleration:
The gap between SMA25 and SMA200 has been increasing for the last 5 consecutive bars.
→ mathematically:
gap_t > gap_(t-1) > gap_(t-2) > gap_(t-3) > gap_(t-4)
→ indicates that the short-term trend is pulling away from the long-term trend and accelerating upward.
✅ When all three conditions are met, the strategy enters a long trade at the close of the current candle.
🔴 Exit Conditions (Close Long)
The position is closed when the uptrend starts to lose strength:
Trend deceleration:
The gap between SMA25 and SMA200 has been shrinking for 3 consecutive bars.
→ mathematically:
gap_t < gap_(t-1) < gap_(t-2)
→ signals that the short-term moving average is converging toward the long-term average, showing weakening momentum.
🚪 When this condition is met, the strategy closes the position at market price.
⚙️ Summary of Logic
Phase Condition Meaning
Entry SMA25 > SMA200 Long-term trend is up
Entry Close > SMA25 Short-term momentum is bullish
Entry Gap rising 5 bars Trend is accelerating
Exit Gap falling 3 bars Trend is weakening
💡 Interpretation
This strategy aims to:
Enter only when a strong, accelerating uptrend is confirmed.
Stay in the trade as long as momentum remains intact.
Exit early when the market starts losing strength, before the trend fully reverses.
It works best in trending markets and helps avoid false entries during sideways or weak phases.
Script de código abierto
Siguiendo fielmente el espíritu de TradingView, el creador de este script lo ha publicado en código abierto, permitiendo que otros traders puedan revisar y verificar su funcionalidad. ¡Enhorabuena al autor! Puede utilizarlo de forma gratuita, pero tenga en cuenta que la publicación de este código está sujeta a nuestras Normas internas.
Exención de responsabilidad
La información y las publicaciones que ofrecemos, no implican ni constituyen un asesoramiento financiero, ni de inversión, trading o cualquier otro tipo de consejo o recomendación emitida o respaldada por TradingView. Puede obtener información adicional en las Condiciones de uso.
Script de código abierto
Siguiendo fielmente el espíritu de TradingView, el creador de este script lo ha publicado en código abierto, permitiendo que otros traders puedan revisar y verificar su funcionalidad. ¡Enhorabuena al autor! Puede utilizarlo de forma gratuita, pero tenga en cuenta que la publicación de este código está sujeta a nuestras Normas internas.
Exención de responsabilidad
La información y las publicaciones que ofrecemos, no implican ni constituyen un asesoramiento financiero, ni de inversión, trading o cualquier otro tipo de consejo o recomendación emitida o respaldada por TradingView. Puede obtener información adicional en las Condiciones de uso.