OPEN-SOURCE SCRIPT

oppliger trendfollow

46
📈 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.

Thông báo miễn trừ trách nhiệm

Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.