| import pandas as pd |
| import plotly.graph_objects as go |
| from plotly.subplots import make_subplots |
| import os |
|
|
| |
| 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 |
|
|
| |
| df = pd.read_csv(csv_file_path, skipinitialspace=True) |
| df.columns = df.columns.str.strip().str.replace('\ufeff', '') |
| |
| |
| 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) |
| |
| |
| |
| df['range'] = df['high'] - df['low'] |
| df['RDBSin'] = df['range'] / df['spread'] |
| |
| |
| expected_diff = pd.Timedelta(minutes=3) |
| df['TimeDiff'] = df['time'].diff() |
| gaps = df[df['TimeDiff'] > expected_diff] |
| |
| |
| fig = make_subplots( |
| rows=2, cols=1, |
| shared_xaxes=True, |
| vertical_spacing=0.05, |
| row_heights=[0.7, 0.3] |
| ) |
| |
| |
| 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 |
| ) |
| |
| |
| 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 |
| ) |
| |
| |
| 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 |
| ) |
| |
| |
| 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") |
|
|
| |
| process_and_plot_rdbs(file_name) |