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.
Script de código aberto
Em verdadeiro espírito do TradingView, o criador deste script o tornou de código aberto, para que os traders possam revisar e verificar sua funcionalidade. Parabéns ao autor! Embora você possa usá-lo gratuitamente, lembre-se de que a republicação do código está sujeita às nossas Regras da Casa.
Aviso legal
As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.
Script de código aberto
Em verdadeiro espírito do TradingView, o criador deste script o tornou de código aberto, para que os traders possam revisar e verificar sua funcionalidade. Parabéns ao autor! Embora você possa usá-lo gratuitamente, lembre-se de que a republicação do código está sujeita às nossas Regras da Casa.
Aviso legal
As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.