SMA + Heiken Ashi Signals with BB Width Filter (Toggle + Label)

This script gives Buy, Sell, Exit Buy, and Exit Sell signals based on:
SMA crossovers
Heiken Ashi candle trend reversal
Bollinger Band Width filter to avoid trades in sideways markets
It’s designed for clean signal-only trading, with no actual order execution — ideal for discretionary or alert-based traders.
🧠 Logic Explained
✅ 1. Entry Signals (Buy/Sell)
Based on a fast SMA crossing a slow SMA
→ Uses 1-minute data (via request.security) for faster signal generation even on higher timeframes.
Only triggers if:
✅ Price is trending in the direction of the trade (above or below a 50-period SMA)
✅ Bollinger Band width is wide enough, indicating a strong trend
✅ You're not already in that direction (prevents duplicate signals)
❌ 2. Exit Signals (Exit Buy / Exit Sell)
Based on 3-minute Heiken Ashi candles
Exit Buy when: Heiken Ashi candle turns red (bearish)
Exit Sell when: Heiken Ashi candle turns green (bullish)
This smooths out the exit and prevents premature exits from short-term noise.
📊 3. Bollinger Band Width Filter
Measures distance between BB upper & lower bands
Normalized by dividing by the midline (basis) → bbWidth
If bbWidth < minWidth, signals are blocked to avoid consolidating markets
You can toggle this filter on/off and adjust the minWidth input.
🔁 4. Trade State Tracking
Uses two var bool flags:
inLong: True if in a long position
inShort: True if in a short position
Prevents the script from repeating signals until an exit occurs
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Per un accesso rapido a un grafico, aggiungi questo script ai tuoi preferiti: per saperne di più clicca qui.
Declinazione di responsabilità
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Per un accesso rapido a un grafico, aggiungi questo script ai tuoi preferiti: per saperne di più clicca qui.