OPEN-SOURCE SCRIPT
Gann Swing [Kodeus]

Gann Swing neon-styled take on classic Gann swing logic. It detects swing peaks and valleys, draws confirmed legs with a soft glow, and projects a live (developing) leg in real time. An “Outside Bar Rule” lets you choose how to resolve bars that break both the prior swing high and low, so the swing state machine behaves exactly how you prefer across volatile candles. Optional labels, trend-tinted bars, and alert conditions round out a clean, informative visual.

🔷 Key Features
Configurable Outside Bar Rule : Choose how to handle bars that make both a higher high and lower low:
Magnitude→Close, Close direction, Always Up, Always Down, or Ignore Outside (Next Bar).
Real-time “Live Leg” : Dotted line with adjustable transparency updates every bar until the swing confirms and is drawn as a solid, glowing leg.
Peak/Valley Labels : One-tap toggles for labels at confirmed turning points (🔻 for peaks, 🔺 for valleys).
Color Themes : Pick from neon palettes for uptrends and downtrends.
Alerts : Built-in alert conditions for Trend Up (valley confirmed) and Trend Down (peak confirmed).
🔷 Calculations
Outside Bar Rule (how “both” is resolved)
When a bar breaks both the running high and low, the script determines a preferred direction based on your setting:
Magnitude→Close (default)
Compare overshoots on each side:
Pine Script®
Why: favors the side that extended further beyond the previous extreme; ties fall back to candle body bias.
Close direction
Ignore magnitude, use bar body direction only:
Pine Script®
Why: simple, body-driven resolution for indecisive wicks.
Always Up
Pine Script®
Why: forces upward continuation on outside bars (useful for trend-following bias tests).
Always Down
Pine Script®
Why: forces downward continuation on outside bars.
Ignore Outside (Next Bar)
Pine Script®
Why: avoids whipsaws from single, highly volatile candles.
🔷 Disclaimer
Use with Caution: This indicator is provided for educational and informational purposes only and should not be considered as financial advice. Users should exercise caution and perform their own analysis before making trading decisions based on the indicator's signals.
Not Financial Advice: The information provided by this indicator does not constitute financial advice, and the creator shall not be held responsible for any trading losses incurred as a result of using this indicator.
Backtesting Recommended: Traders are encouraged to backtest the indicator thoroughly on historical data before using it in live trading to assess its performance and suitability for their trading strategies.
Risk Management: Trading involves inherent risks, and users should implement proper risk management strategies, including but not limited to stop-loss orders and position sizing, to mitigate potential losses.
No Guarantees: The accuracy and reliability of the indicator's signals cannot be guaranteed, as they are based on historical price data and past performance may not be indicative of future results.
🔷 Key Features
Configurable Outside Bar Rule : Choose how to handle bars that make both a higher high and lower low:
Magnitude→Close, Close direction, Always Up, Always Down, or Ignore Outside (Next Bar).
Real-time “Live Leg” : Dotted line with adjustable transparency updates every bar until the swing confirms and is drawn as a solid, glowing leg.
Peak/Valley Labels : One-tap toggles for labels at confirmed turning points (🔻 for peaks, 🔺 for valleys).
Color Themes : Pick from neon palettes for uptrends and downtrends.
Alerts : Built-in alert conditions for Trend Up (valley confirmed) and Trend Down (peak confirmed).
🔷 Calculations
Outside Bar Rule (how “both” is resolved)
When a bar breaks both the running high and low, the script determines a preferred direction based on your setting:
Magnitude→Close (default)
Compare overshoots on each side:
upMag = high - lastTrendHigh
dnMag = lastTrendLow - low
If upMag > dnMag → prefer Up
If dnMag > upMag → prefer Down
If equal → use the bar close vs open (close ≥ open → Up, else Down)
Why: favors the side that extended further beyond the previous extreme; ties fall back to candle body bias.
Close direction
Ignore magnitude, use bar body direction only:
close ≥ open → Up, else Down.
Why: simple, body-driven resolution for indecisive wicks.
Always Up
Always resolve outside bars Up.
Why: forces upward continuation on outside bars (useful for trend-following bias tests).
Always Down
Always resolve outside bars Down.
Why: forces downward continuation on outside bars.
Ignore Outside (Next Bar)
Treat outside bars as not trend bars for that candle (isTrendBar = false when both), deferring swing decisions to the next bar.
Why: avoids whipsaws from single, highly volatile candles.
🔷 Disclaimer
Use with Caution: This indicator is provided for educational and informational purposes only and should not be considered as financial advice. Users should exercise caution and perform their own analysis before making trading decisions based on the indicator's signals.
Not Financial Advice: The information provided by this indicator does not constitute financial advice, and the creator shall not be held responsible for any trading losses incurred as a result of using this indicator.
Backtesting Recommended: Traders are encouraged to backtest the indicator thoroughly on historical data before using it in live trading to assess its performance and suitability for their trading strategies.
Risk Management: Trading involves inherent risks, and users should implement proper risk management strategies, including but not limited to stop-loss orders and position sizing, to mitigate potential losses.
No Guarantees: The accuracy and reliability of the indicator's signals cannot be guaranteed, as they are based on historical price data and past performance may not be indicative of future results.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Get access to our exclusive tools: pinescriptmarket.com/
All content provided by Kodeus is for informational & educational purposes only. Past performance does not guarantee future results.
All content provided by Kodeus is for informational & educational purposes only. Past performance does not guarantee future results.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Get access to our exclusive tools: pinescriptmarket.com/
All content provided by Kodeus is for informational & educational purposes only. Past performance does not guarantee future results.
All content provided by Kodeus is for informational & educational purposes only. Past performance does not guarantee future results.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.