OPEN-SOURCE SCRIPT
Williams Fractals with Buy/Sell Signals

🧠 Concept:
This indicator is based on the concept of fractal swing highs and lows, commonly used in Bill Williams’ trading methods. A fractal forms when a candle’s high or low is higher/lower than a set number of candles on both sides. This structure helps identify local market turning points.
⚙️ Inputs:
Fractal Sensitivity (swingSensitivity):
Number of candles required on each side of the central bar to validate a fractal.
For example, if set to 2, a swing high is detected when a bar’s high is higher than the previous 2 bars and the next 2 bars.
✅ Features:
Fractal Detection:
Plots white triangles above swing highs (down fractals).
Plots white triangles below swing lows (up fractals).
Buy/Sell Signals:
Buy Signal: Triggered when the candle closes above the most recent down fractal.
Sell Signal: Triggered when the candle closes below the most recent up fractal.
Signals alternate — a Buy must follow a Sell and vice versa to reduce noise.
Signal Labels:
"BUY" label appears below the candle in green.
"SELL" label appears above the candle in red.
Alerts:
Real-time alerts are available for both Buy and Sell signals via alertcondition().
📌 Use Case:
This indicator can help you:
Detect short-term reversals.
Confirm breakouts or structure shifts.
Time entries with clear logic based on price action.
This indicator is based on the concept of fractal swing highs and lows, commonly used in Bill Williams’ trading methods. A fractal forms when a candle’s high or low is higher/lower than a set number of candles on both sides. This structure helps identify local market turning points.
⚙️ Inputs:
Fractal Sensitivity (swingSensitivity):
Number of candles required on each side of the central bar to validate a fractal.
For example, if set to 2, a swing high is detected when a bar’s high is higher than the previous 2 bars and the next 2 bars.
✅ Features:
Fractal Detection:
Plots white triangles above swing highs (down fractals).
Plots white triangles below swing lows (up fractals).
Buy/Sell Signals:
Buy Signal: Triggered when the candle closes above the most recent down fractal.
Sell Signal: Triggered when the candle closes below the most recent up fractal.
Signals alternate — a Buy must follow a Sell and vice versa to reduce noise.
Signal Labels:
"BUY" label appears below the candle in green.
"SELL" label appears above the candle in red.
Alerts:
Real-time alerts are available for both Buy and Sell signals via alertcondition().
📌 Use Case:
This indicator can help you:
Detect short-term reversals.
Confirm breakouts or structure shifts.
Time entries with clear logic based on price action.
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.