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.
開源腳本
秉持TradingView一貫精神,這個腳本的創作者將其設為開源,以便交易者檢視並驗證其功能。向作者致敬!您可以免費使用此腳本,但請注意,重新發佈代碼需遵守我們的社群規範。
免責聲明
這些資訊和出版物並非旨在提供,也不構成TradingView提供或認可的任何形式的財務、投資、交易或其他類型的建議或推薦。請閱讀使用條款以了解更多資訊。
開源腳本
秉持TradingView一貫精神,這個腳本的創作者將其設為開源,以便交易者檢視並驗證其功能。向作者致敬!您可以免費使用此腳本,但請注意,重新發佈代碼需遵守我們的社群規範。
免責聲明
這些資訊和出版物並非旨在提供,也不構成TradingView提供或認可的任何形式的財務、投資、交易或其他類型的建議或推薦。請閱讀使用條款以了解更多資訊。