on running the following code :


import pandas as pd
import matplotlib.pyplot as plt

# === 1. Load the Data ===
# Replace 'your_data.csv' with the actual path to your CSV file
df = pd.read_csv('/media/dulu/PART2HDD/VS_Code_Projects/stock_screener/FOREX TRADING TUTORIAL/FOREX DATA/D1-MAY7/AUDUSD_D1.csv', parse_dates=['Time'])

# === 2. Feature Engineering ===
df['Hour'] = df['Time'].dt.hour
df['Date'] = df['Time'].dt.date

# Mid price: average of High and Low
df['MidPrice'] = (df['High'] + df['Low']) / 2

# Hourly return: Close of next hour - Close of current hour
df['Next_Close'] = df['Close'].shift(-1)
df['HourlyReturn'] = df['Next_Close'] - df['Close']

# === 3. Group by Hour of Day ===
hourly_stats = df.groupby('Hour').agg({
    'MidPrice': 'mean',
    'HourlyReturn': 'mean',
    'Volume': 'mean'
}).reset_index()

# Rename for clarity
hourly_stats.columns = ['Hour', 'AvgMidPrice', 'AvgHourlyReturn', 'AvgVolume']

# === 4. Sort to Find Best Buy/Sell Hours ===
best_buy_hours = hourly_stats.sort_values('AvgMidPrice')  # Buy at low prices
best_sell_hours = hourly_stats.sort_values('AvgMidPrice', ascending=False)  # Sell at high prices

# === 5. Plotting ===
plt.figure(figsize=(14, 6))

# Plot average mid price by hour
plt.subplot(1, 2, 1)
plt.plot(hourly_stats['Hour'], hourly_stats['AvgMidPrice'], marker='o')
plt.title('Average Mid Price by Hour')
plt.xlabel('Hour of Day')
plt.ylabel('Average Mid Price')
plt.grid(True)

# Plot average hourly return by hour
plt.subplot(1, 2, 2)
plt.bar(hourly_stats['Hour'], hourly_stats['AvgHourlyReturn'], color='green', alpha=0.7)
plt.title('Average Hourly Return by Hour')
plt.xlabel('Hour of Day')
plt.ylabel('Avg Return (NextClose - Close)')
plt.axhline(0, color='black', linestyle='--')
plt.grid(True)

plt.tight_layout()
plt.show()

# === 6. Display Key Results ===
print("\nTop 3 Best Hours to BUY (Lowest Avg Prices):")
print(best_buy_hours[['Hour', 'AvgMidPrice', 'AvgHourlyReturn']].head(3))

print("\nTop 3 Best Hours to SELL (Highest Avg Prices):")
print(best_sell_hours[['Hour', 'AvgMidPrice', 'AvgHourlyReturn']].head(3))

print("\nFull Hourly Stats:")
print(hourly_stats)


I get :
dulu@dulu:~$ /bin/python3 "/media/dulu/PART2HDD/VS_Code_Projects/stock_screener/FOREX TRADING TUTORIAL/Forex_buy_sell_entry_time_gpt.py"

Top 3 Best Hours to BUY (Lowest Avg Prices):
   Hour  AvgMidPrice  AvgHourlyReturn
0     0     0.799572        -0.000017

Top 3 Best Hours to SELL (Highest Avg Prices):
   Hour  AvgMidPrice  AvgHourlyReturn
0     0     0.799572        -0.000017

Full Hourly Stats:
   Hour  AvgMidPrice  AvgHourlyReturn      AvgVolume
0     0     0.799572        -0.000017  106120.094925


the graphs appear but the Average Mid Price By hour Graph only plots a blue point in the middle of the graph and the average hourly return by hour graph plots green on all grids :


my sample sample data set is as follows :

Time	Open	High	Low	Close	Volume
2009-04-13 00:00:00	0.72305	0.73269	0.72194	0.72809	34511
2009-04-14 00:00:00	0.72808	0.7303	0.71527	0.71663	55756
2009-04-15 00:00:00	0.71668	0.73151	0.71462	0.72756	69681
2009-04-16 00:00:00	0.7275	0.72855	0.71369	0.71949	60422
2009-04-17 00:00:00	0.71952	0.72283	0.71661	0.72075	47891
2009-04-19 00:00:00	0.71642	0.71878	0.71587	0.71818	2165
2009-04-20 00:00:00	0.71821	0.71974	0.69523	0.70152	68677
2009-04-21 00:00:00	0.70159	0.71293	0.69755	0.70466	71420
2009-04-22 00:00:00	0.70459	0.71166	0.7002	0.70455	78160
2009-04-23 00:00:00	0.70451	0.71559	0.70444	0.71451	78661
2009-04-24 00:00:00	0.71456	0.72382	0.71094	0.72239	50202
2009-04-26 00:00:00	0.71666	0.71666	0.71072	0.71143	3757
2009-04-27 00:00:00	0.7114	0.71699	0.70235	0.70464	65763
2009-04-28 00:00:00	0.70463	0.71384	0.69892	0.71341	66179
2009-04-29 00:00:00	0.71345	0.72996	0.71099	0.72701	83271
2009-04-30 00:00:00	0.72702	0.73836	0.72352	0.72653	93368
2009-05-01 00:00:00	0.72651	0.73459	0.72513	0.73006	50582
2009-05-03 00:00:00	0.73645	0.73888	0.73479	0.73484	2943
2009-05-04 00:00:00	0.73481	0.74266	0.73126	0.73811	52417
2009-05-05 00:00:00	0.73809	0.74788	0.73351	0.73631	87806
2009-05-06 00:00:00	0.7363	0.75611	0.73503	0.75232	80413
2009-05-07 00:00:00	0.75228	0.76166	0.75072	0.75261	91899
2009-05-08 00:00:00	0.75263	0.77078	0.75228	0.76787	57391
2009-05-10 00:00:00	0.76522	0.76908	0.76511	0.76767	3198
2009-05-11 00:00:00	0.76766	0.76993	0.75615	0.76008	81668
2009-05-12 00:00:00	0.76004	0.77034	0.75768	0.76799	89040
2009-05-13 00:00:00	0.768	0.77036	0.75077	0.75115	105720
2009-05-14 00:00:00	0.75112	0.76171	0.74658	0.75896	99251
2009-05-15 00:00:00	0.75894	0.76016	0.74762	0.74959	73067
2009-05-17 00:00:00	0.74603	0.74784	0.74593	0.74691	2197
2009-05-18 00:00:00	0.74687	0.76674	0.74678	0.76653	73267
2009-05-19 00:00:00	0.76648	0.77836	0.76502	0.77171	87778
2009-05-20 00:00:00	0.77168	0.78091	0.76911	0.77619	87839
2009-05-21 00:00:00	0.77616	0.78213	0.76683	0.77933	88505
2009-05-22 00:00:00	0.77928	0.78673	0.77716	0.78386	66125
2009-05-24 00:00:00	0.77986	0.78028	0.77721	0.77806	2743
2009-05-25 00:00:00	0.7781	0.78253	0.77447	0.77768	26552
2009-05-26 00:00:00	0.77775	0.78869	0.77026	0.78708	81412
2009-05-27 00:00:00	0.78707	0.78906	0.77422	0.77685	85291
2009-05-28 00:00:00	0.77681	0.78859	0.77591	0.78731	95681
2009-05-29 00:00:00	0.78719	0.80124	0.78704	0.80069	73472
2009-05-31 00:00:00	0.80378	0.80646	0.80366	0.80531	2584