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.
Skrip sumber terbuka
Dalam semangat TradingView sebenar, pencipta skrip ini telah menjadikannya sumber terbuka, jadi pedagang boleh menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupuan anda boleh menggunakan secara percuma, ingat bahawa penerbitan semula kod ini tertakluk kepada Peraturan Dalaman.
Penafian
Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.
Skrip sumber terbuka
Dalam semangat TradingView sebenar, pencipta skrip ini telah menjadikannya sumber terbuka, jadi pedagang boleh menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupuan anda boleh menggunakan secara percuma, ingat bahawa penerbitan semula kod ini tertakluk kepada Peraturan Dalaman.
Penafian
Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.