OPEN-SOURCE SCRIPT
SuperTrend Strategy [Long/Short]

SuperTrend Strategy [Long/Short]
A clean SuperTrend-based strategy with dynamic stop-loss, built on Pine Script v6.
Automatically flips between Long and Short on trend reversals, with SuperTrend acting as both entry trigger and trailing stop.
━━━━━━━━━━━━━━━━━━━━━━━
🔹 HOW IT WORKS
━━━━━━━━━━━━━━━━━━━━━━━
SuperTrend is calculated using ATR (Average True Range) and a multiplier factor.
When the trend direction flips, the strategy closes the current position and opens the opposite — a full reversal (flip) system.
- Bullish flip → Closes Short, opens Long
- Bearish flip → Closes Long, opens Short
━━━━━━━━━━━━━━━━━━━━━━━
🔹 STOP-LOSS LOGIC
━━━━━━━━━━━━━━━━━━━━━━━
The SuperTrend line acts as a dynamic stop-loss level.
- Long position → SL applied when SuperTrend is below current price
- Short position → SL applied when SuperTrend is above current price
This keeps the stop adaptive to market volatility rather than fixed.
━━━━━━━━━━━━━━━━━━━━━━━
🔹 FEATURES
━━━━━━━━━━━━━━━━━━━━━━━
- Enable / Disable strategy execution independently
→ When disabled, the SuperTrend line and signals still display on the chart.
- Lot Size input
→ Set a fixed quantity per entry.
- Commission & Slippage
→ Defaults: 0.05% commission, 3 ticks slippage.
→ Edit directly in the script, or override via Strategy Properties tab.
- Visual BUY / SELL labels plotted directly on the chart.
━━━━━━━━━━━━━━━━━━━━━━━
🔹 ALERT CONDITIONS (2 total)
━━━━━━━━━━━━━━━━━━━━━━━
- 🟢 Buy Alert — Bullish flip detected
- 🔴 Sell Alert — Bearish flip detected
Alerts include ticker and timeframe in the message: {{ticker}}, {{interval}}
━━━━━━━━━━━━━━━━━━━━━━━
🔹 SETTINGS
━━━━━━━━━━━━━━━━━━━━━━━
- ATR Length : 10 (default)
- Factor : 3.0 (default)
- Lot Size : 1.0 (default)
Increase the Factor to reduce signal frequency and filter noise.
Decrease it for more responsive signals on shorter timeframes.
━━━━━━━━━━━━━━━━━━━━━━━
⚠️ DISCLAIMER
━━━━━━━━━━━━━━━━━━━━━━━
This script is for educational and backtesting purposes only.
Past performance does not guarantee future results.
Always apply proper risk management before using any strategy in live markets.
A clean SuperTrend-based strategy with dynamic stop-loss, built on Pine Script v6.
Automatically flips between Long and Short on trend reversals, with SuperTrend acting as both entry trigger and trailing stop.
━━━━━━━━━━━━━━━━━━━━━━━
🔹 HOW IT WORKS
━━━━━━━━━━━━━━━━━━━━━━━
SuperTrend is calculated using ATR (Average True Range) and a multiplier factor.
When the trend direction flips, the strategy closes the current position and opens the opposite — a full reversal (flip) system.
- Bullish flip → Closes Short, opens Long
- Bearish flip → Closes Long, opens Short
━━━━━━━━━━━━━━━━━━━━━━━
🔹 STOP-LOSS LOGIC
━━━━━━━━━━━━━━━━━━━━━━━
The SuperTrend line acts as a dynamic stop-loss level.
- Long position → SL applied when SuperTrend is below current price
- Short position → SL applied when SuperTrend is above current price
This keeps the stop adaptive to market volatility rather than fixed.
━━━━━━━━━━━━━━━━━━━━━━━
🔹 FEATURES
━━━━━━━━━━━━━━━━━━━━━━━
- Enable / Disable strategy execution independently
→ When disabled, the SuperTrend line and signals still display on the chart.
- Lot Size input
→ Set a fixed quantity per entry.
- Commission & Slippage
→ Defaults: 0.05% commission, 3 ticks slippage.
→ Edit directly in the script, or override via Strategy Properties tab.
- Visual BUY / SELL labels plotted directly on the chart.
━━━━━━━━━━━━━━━━━━━━━━━
🔹 ALERT CONDITIONS (2 total)
━━━━━━━━━━━━━━━━━━━━━━━
- 🟢 Buy Alert — Bullish flip detected
- 🔴 Sell Alert — Bearish flip detected
Alerts include ticker and timeframe in the message: {{ticker}}, {{interval}}
━━━━━━━━━━━━━━━━━━━━━━━
🔹 SETTINGS
━━━━━━━━━━━━━━━━━━━━━━━
- ATR Length : 10 (default)
- Factor : 3.0 (default)
- Lot Size : 1.0 (default)
Increase the Factor to reduce signal frequency and filter noise.
Decrease it for more responsive signals on shorter timeframes.
━━━━━━━━━━━━━━━━━━━━━━━
⚠️ DISCLAIMER
━━━━━━━━━━━━━━━━━━━━━━━
This script is for educational and backtesting purposes only.
Past performance does not guarantee future results.
Always apply proper risk management before using any strategy in live markets.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.