File size: 2,547 Bytes
6164f9e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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)