import pandas as pd import plotly.graph_objects as go from plotly.subplots import make_subplots import os # --- 1. File Selection --- file_name = 'XAUUSDc_M3_data.csv' def process_and_plot_rdbs(csv_file_path): if not os.path.exists(csv_file_path): print(f"Error: {csv_file_path} not found.") return # Load and clean headers df = pd.read_csv(csv_file_path, skipinitialspace=True) df.columns = df.columns.str.strip().str.replace('\ufeff', '') # Parse time and sort df['time'] = pd.to_datetime(df['time'], errors='coerce') df.dropna(subset=['time'], inplace=True) df.sort_values('time', inplace=True) df.reset_index(drop=True, inplace=True) # Calculate Indicator: RDBSin = individual range / spread # RDBSin_value calculation df['range'] = df['high'] - df['low'] df['RDBSin'] = df['range'] / df['spread'] # Identify time gaps (M3 = 3 minutes) expected_diff = pd.Timedelta(minutes=3) df['TimeDiff'] = df['time'].diff() gaps = df[df['TimeDiff'] > expected_diff] # Create Subplots fig = make_subplots( rows=2, cols=1, shared_xaxes=True, vertical_spacing=0.05, row_heights=[0.7, 0.3] ) # Top Pane: OHLC Candlestick fig.add_trace( go.Candlestick( x=df['time'], open=df['open'], high=df['high'], low=df['low'], close=df['close'], name='XAUUSD OHLC' ), row=1, col=1 ) # Bottom Pane: RDBSin Indicator fig.add_trace( go.Scatter( x=df['time'], y=df['RDBSin'], mode='lines', name='RDBSin', line=dict(color='blue', width=1.5) ), row=2, col=1 ) # Visualizing Gaps: Red with 10% opacity for idx, row in gaps.iterrows(): start_time = df['time'].iloc[idx-1] end_time = row['time'] fig.add_vrect( x0=start_time, x1=end_time, fillcolor="red", opacity=0.1, line_width=0, row="all", col=1 ) # Formatting fig.update_layout( template="plotly_white", title="XAUUSD M3: RDBS Indicator Analysis", xaxis_rangeslider_visible=False, height=900, showlegend=True ) fig.update_yaxes(title_text="Price", row=1, col=1) fig.update_yaxes(title_text="RDBSin Value", row=2, col=1) fig.show(renderer="colab") # Execute process_and_plot_rdbs(file_name)