import json

def load_json(path):
    with open(path, 'r') as f:
        return json.load(f)['bars']

h4_data = load_json('/home/aryy/.hermes/profiles/finance/backtests/xauusd_2026/hybrid/data/ohlcv_H4.json')
h1_data = load_json('/home/aryy/.hermes/profiles/finance/backtests/xauusd_2026/hybrid/data/ohlcv_H1.json')
m30_data = load_json('/home/aryy/.hermes/profiles/finance/backtests/xauusd_2026/hybrid/data/ohlcv_M30.json')
m15_data = load_json('/home/aryy/.hermes/profiles/finance/backtests/xauusd_2026/hybrid/data/ohlcv_M15.json')
m5_data = load_json('/home/aryy/.hermes/profiles/finance/backtests/xauusd_2026/hybrid/data/ohlcv_M5.json')

def analyze_context(target_time, direction):
    print(f"\n--- Analyzing {target_time} {direction} ---")
    
    # H4 context
    print("H4:")
    last_h4 = None
    for b in h4_data:
        if b['time'] <= target_time:
            last_h4 = b
    if last_h4:
        h4_idx = h4_data.index(last_h4)
        for b in h4_data[max(0, h4_idx-3):h4_idx+1]:
            print(f"  {b['time']}: O={b['open']} H={b['high']} L={b['low']} C={b['close']}")

    # H1 context
    print("H1:")
    last_h1 = None
    for b in h1_data:
        if b['time'] <= target_time:
            last_h1 = b
    if last_h1:
        h1_idx = h1_data.index(last_h1)
        for b in h1_data[max(0, h1_idx-3):h1_idx+1]:
            print(f"  {b['time']}: O={b['open']} H={b['high']} L={b['low']} C={b['close']}")
        
    # M15 context around trigger
    print("M15 around target:")
    for i, b in enumerate(m15_data):
        if b['time'] == target_time:
            for mb in m15_data[max(0, i-2):min(len(m15_data), i+5)]:
                print(f"  {mb['time']}: O={mb['open']} H={mb['high']} L={mb['low']} C={mb['close']}")
            break
            
    # M5 context around trigger
    print("M5 around target:")
    for i, b in enumerate(m5_data):
        if b['time'] == target_time:
            for mb in m5_data[max(0, i-2):min(len(m5_data), i+10)]:
                print(f"  {mb['time']}: O={mb['open']} H={mb['high']} L={mb['low']} C={mb['close']}")
            break

analyze_context("2026-01-13T02:00:00Z", "Long")
analyze_context("2026-01-13T02:30:00Z", "Long")
analyze_context("2026-01-13T05:30:00Z", "Short")

