OPEN-SOURCE SCRIPT

Optimal Buy Time 60 vs 252 Sessions Comparison

590
Optimal Buy Time — 60 vs 252 Sessions Comparison

This indicator statistically analyzes at what time of day a security tends to have its lowest price relative to the daily close, identifying the historically most favorable intraday time slots for opening a long position, whether intraday or multi-day.
How it works
For each 30-minute time slot of the NYSE session (09:30–16:00 ET) the script calculates, on a historical basis, the average return obtainable by buying during that slot and holding until the daily close. The calculation is performed over two parallel periods — 60 sessions (approximately 3 months) and 252 sessions (approximately 1 year) — allowing you to see whether a pattern is recent or structural, and whether it is improving or deteriorating.
The central table
The table displays all 13 time slots with the following data for each:

60d ret. — average return % if you buy during that slot, calculated over the last 60 sessions
60d win% — percentage of times the closing price was higher than the entry price
252d ret. — same calculation over the last year
252d win% — annual win rate
Trend — indicates whether the recent pattern is improving, deteriorating, or stable compared to the full year

Green cells indicate historically favorable buying slots, red cells indicate slots to avoid. The best slot is highlighted with a more intense green.
The colored background
During the market session the panel background colors in real time: green when you are in a historically favorable slot, red when you are in a slot to avoid.
How to set it up

Recommended timeframe: 30 minutes
Sessions to analyze: default 60 and 252 — adjustable in settings. Increasing the value improves statistical robustness but reduces sensitivity to recent changes
Good threshold %: default 0.1 — minimum average return for a slot to be considered favorable. Lowering it to 0.05 shows more green slots, raising it to 0.3 restricts them to slots with a more significant edge
Show table: enables or disables the summary table
Color background: enables or disables the real-time background color

Important notes
Times in the table are shown in both Italian time and ET (Eastern Time, New York). Italian time corresponds to ET +6 hours — verify the active time zone on your broker before trading.
Data is purely statistical and based on the historical behavior of the security. It does not constitute a buy or sell signal. Intraday patterns change over time depending on market conditions — it is recommended to periodically reassess the analysis and not to use this indicator as the sole decision-making criterion.





Fascia Oraria Ottimale di Acquisto — Confronto 60 vs 252 sedute
Questo indicatore analizza statisticamente a che ora della giornata un titolo tende ad avere il prezzo più basso rispetto alla chiusura, identificando le fasce orarie storicamente più convenienti per aprire una posizione long intraday o multi-giorno.
Come funziona
Per ogni fascia oraria da 30 minuti della sessione NYSE (09:30–16:00 ET) lo script calcola, su base storica, il rendimento medio ottenibile acquistando in quella fascia e tenendo fino alla chiusura di giornata. Il calcolo viene eseguito su due periodi in parallelo — 60 sedute (circa 3 mesi) e 252 sedute (circa 1 anno) — permettendo di vedere se un pattern è recente o strutturale, e se sta migliorando o peggiorando.
La tabella centrale
La tabella mostra tutte le 13 fasce orarie con i seguenti dati per ognuna:

60g rend. — rendimento medio % se acquisti in quella fascia, calcolato sulle ultime 60 sedute
60g succ. — percentuale di volte in cui il prezzo di chiusura è stato superiore al prezzo di acquisto
252g rend. — stesso calcolo sull'ultimo anno
252g succ. — tasso di successo annuale
Trend — indica se il pattern recente sta migliorando, peggiorando o è stabile rispetto all'anno

Le celle verdi indicano fasce storicamente favorevoli all'acquisto, le rosse fasce da evitare. La fascia migliore è evidenziata con verde più intenso.
Lo sfondo colorato
Durante la sessione di mercato lo sfondo del pannello si colora in tempo reale: verde quando sei in una fascia storicamente favorevole, rosso quando sei in una fascia da evitare.
Come impostarlo

Timeframe consigliato: 30 minuti
Sedute da analizzare: default 60 e 252 — modificabili nelle impostazioni. Aumentare il valore aumenta la solidità statistica ma riduce la reattività ai cambiamenti recenti
Soglia buona %: default 0.1 — soglia minima di rendimento medio per considerare una fascia favorevole. Abbassarla a 0.05 mostra più fasce verdi, alzarla a 0.3 le restringe alle sole fasce con vantaggio più marcato
Mostra tabella: attiva o disattiva la tabella riepilogativa
Colora sfondo: attiva o disattiva il colore di sfondo in tempo reale

Note importanti
Gli orari in tabella sono mostrati sia in ora italiana che in ET (Eastern Time, fuso di New York). L'ora italiana corrisponde a ET +6 ore in orario solare e ET +6 ore in orario legale — verificare il fuso attivo sul proprio broker prima di operare.
I dati sono puramente statistici e basati sul comportamento passato del titolo. Non costituiscono un segnale di acquisto o vendita. I pattern intraday cambiano nel tempo in funzione del contesto di mercato — si consiglia di rieseguire l'analisi periodicamente e di non utilizzare questo indicatore come unico criterio decisionale.

Wyłączenie odpowiedzialności

Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.