OPEN-SOURCE SCRIPT
Gann Swing Points

Indicator Logic
This is a GANN-style swing indicator that classifies bars based on their high/low structure relative to the previous bar.
I strongly encourage you to replay bars on Tradingview using this indicator to get a sense of how it creates pivot (or swing) points
Bar Classification:
Up-Bar (direction: 'up'): Higher High and Higher Low (HH/HL)
Down-Bar (direction: 'down'): Lower High and Lower Low (LH/LL)
Outside-Bar (generates 2 directions):
Green: 'down' then 'up'
Red: 'up' then 'down'
Inside-Bar: No direction generated (HL/LH)
Swing Line Logic
The swing line continues in the current direction until n opposite directions are detected.
n is the "n-direction" parameter (commonly set to 2, so 2 consecutive opposite direction is needed to turn the swing)
When n opposing directions occur, the swing turns, creating a pivot point
Inside bar is ignored, so e.g up-bar -> inside-bar -> up-bar generates "up", "up" direction
A top pivot is formed when the swing turns down
A bottom pivot is formed when it turns up
Note: This swing logic is inherently lagging — it only confirms tops/bottoms after the fact
This swing structure gives the system a clear and noise-resistant way to identify pivot points (swing-points)
This is a GANN-style swing indicator that classifies bars based on their high/low structure relative to the previous bar.
I strongly encourage you to replay bars on Tradingview using this indicator to get a sense of how it creates pivot (or swing) points
Bar Classification:
Up-Bar (direction: 'up'): Higher High and Higher Low (HH/HL)
Down-Bar (direction: 'down'): Lower High and Lower Low (LH/LL)
Outside-Bar (generates 2 directions):
Green: 'down' then 'up'
Red: 'up' then 'down'
Inside-Bar: No direction generated (HL/LH)
Swing Line Logic
The swing line continues in the current direction until n opposite directions are detected.
n is the "n-direction" parameter (commonly set to 2, so 2 consecutive opposite direction is needed to turn the swing)
When n opposing directions occur, the swing turns, creating a pivot point
Inside bar is ignored, so e.g up-bar -> inside-bar -> up-bar generates "up", "up" direction
A top pivot is formed when the swing turns down
A bottom pivot is formed when it turns up
Note: This swing logic is inherently lagging — it only confirms tops/bottoms after the fact
This swing structure gives the system a clear and noise-resistant way to identify pivot points (swing-points)
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.