OPEN-SOURCE SCRIPT
Percent of Time Above 200 EMA (3 Years)

This script calculates how much time (in percentage)
a stock has spent trading ABOVE its 200-day EMA
over the last 3 years (approx. 756 trading days).
🔎 How it works:
1. Calculates 200 EMA.
2. Looks back ~252 trading days × 3 years = 756 bars.
3. Counts how many days closed above the 200 EMA.
4. Divides by total bars → percentage.
5. Shows result as a label on the latest candle.
✅ Example:
If the result shows 65%, it means in the last 3 years
the stock closed ABOVE the 200 EMA on 65% of trading days.
⚠️ Notes:
- Uses daily chart data (switch to 1D timeframe).
- If the stock has <3 years of history,
it uses available data.
- You can change "lookbackYears" input to 1, 2, 5, etc.
a stock has spent trading ABOVE its 200-day EMA
over the last 3 years (approx. 756 trading days).
🔎 How it works:
1. Calculates 200 EMA.
2. Looks back ~252 trading days × 3 years = 756 bars.
3. Counts how many days closed above the 200 EMA.
4. Divides by total bars → percentage.
5. Shows result as a label on the latest candle.
✅ Example:
If the result shows 65%, it means in the last 3 years
the stock closed ABOVE the 200 EMA on 65% of trading days.
⚠️ Notes:
- Uses daily chart data (switch to 1D timeframe).
- If the stock has <3 years of history,
it uses available data.
- You can change "lookbackYears" input to 1, 2, 5, etc.
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.
Declinazione di responsabilità
Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.
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.
Declinazione di responsabilità
Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.