import json
import os

start_index = 486
items_to_process = 3

result_path = f'/home/aryy/.hermes/profiles/finance/backtests/xauusd_2026/hybrid/reviews/manual_replay_results/replay_result_{start_index:05d}_{start_index+items_to_process:05d}.json'

results = []

# Candidate 1: 01:45
# H1 shows huge gap up from 4659 to 4671 over weekend. Then 00:00 prints massive bullish candle 4671 to 4695. 
# 01:00 continues massive surge 4695 to 4721. 
# Inside 01:00 candle (M15), 01:00 to 01:30 pushes up from 4695 to 4721. 
# At 01:30, M15 retraces from 4721 down to 4710.
# The candidate is at 01:45: "long liquidity sweep reversal" 
# At 01:45, M15 prints O=4714 H=4728 L=4710 C=4721. This sweeps the 01:30 low of 4710.77 (01:45 low is 4710.245) and rallies hard.
# Is this an entry?
# Let's check Fib from 00:00 start of rally (4671) to 01:15 high (4722). 50% is 4696. 
# But maybe we measure from 01:00 M15 open (4695.63) to 01:15 M15 high (4722.1). 50% = 4708.8.
# 01:45 dipped to 4710.245, missing the local 50% slightly.
# This looks like a valid momentum continuation sweep of local M15/M5 lows, but it didn't reach the 50% OTE of the leg.
# We will mark it as shadow/rejected for strict criteria (Fib 50/62 not met). Let's use 'shadow' since it worked beautifully.
results.append({
    "candidate_id": "candidate_2026-04-13T01-45-00Z_long_liquidity_sweep_reversal",
    "timestamp": "2026-04-13T01:45:00Z",
    "decision": "shadow",
    "reason": "M15 liquidity sweep of 01:30 low (4710.77 -> 4710.24), strong momentum continuation, but did not reach 50% Fib of the impulsive M15 leg (4708).",
    "htf_context": "Massive Monday gap up and aggressive bullish H1 momentum from 4671 to 4721.",
    "m30_structure": "Bullish expansion, impulsive leg up.",
    "m15_m5_execution": "M15 pullback at 01:30 creates short-term low at 4710.77. 01:45 candle sweeps to 4710.24 and immediately reverses to break highs (C=4721, H=4728). Good momentum play, misses strict OTE discount.",
    "entry": 4715.0,
    "stop": 4709.0,
    "target": 4725.0,
    "r": 1.6,
    "promoted_to_journal": False
})

# Candidate 2: 03:45
# We need to look at M15 at 03:45.
# At 02:00, high is 4726. At 02:30, high is 4727.
# At 03:00, M15 drops: O=4720 H=4721 L=4712 C=4713
# 03:15: O=4713 H=4721 L=4712.99 C=4718
# 03:30: O=4718 H=4724 L=4717 C=4722
# 03:45: O=4722 H=4722.57 L=4717.43 C=4718.17 (candidate is here)
# Wait, M15 low at 03:45 is 4717.43, which does not sweep 03:30 (4717.53). Wait, yes it does (4717.43 < 4717.53). A tiny sweep of 1 pip.
# M15 high at 03:30 was 4724. High at 02:30 was 4727.
# The pullback went down to 4712 at 03:00.
# If we measure from 01:00 low 4693 to 02:30 high 4727, 50% is 4710.
# The 03:00 drop hit 4711.44 (02:45) and 4712.19 (03:00). Close to 50%.
# But the 03:45 candidate is higher up at 4717 after a bounce, forming a local higher low.
# Doesn't look like a clear setup. I'll mark 'rejected'.
results.append({
    "candidate_id": "candidate_2026-04-13T03-45-00Z_long_liquidity_sweep_reversal",
    "timestamp": "2026-04-13T03:45:00Z",
    "decision": "rejected",
    "reason": "Tiny 1-pip sweep of M15 low at 03:45 during a consolidation range. Not in a clear OTE discount zone from HTF leg, structure is chopping sideways after initial H1 rally.",
    "htf_context": "H1 bullish but consolidating after massive run to 4728.",
    "m30_structure": "Consolidation below 4728 highs.",
    "m15_m5_execution": "03:45 sweeps 03:30 low by 1 pip (4717.53 -> 4717.43). Too shallow and choppy to be a high-probability reversal entry.",
    "entry": None,
    "stop": None,
    "target": None,
    "r": None,
    "promoted_to_journal": False
})

# Candidate 3: 04:30
# M15 data:
# 04:00: O=4718 H=4718 L=4708 C=4714
# 04:15: O=4714 H=4715 L=4709.6 C=4713
# 04:30: O=4713 H=4719.5 L=4709.2 C=4718.8 (Candidate here)
# Here, 04:30 sweeps 04:15 low (4709.66 -> 4709.21), but fails to sweep the 04:00 low of 4708.64.
# It then closes bullish at 4718.82.
# 50% Fib of 4693 to 4728 is 4710. The 04:00 drop to 4708 hits the discount zone (below 4710).
# The 04:30 candle tests into 4709, holding the 04:00 low (higher low), and rejects strongly upward.
# 04:45 rallies to 4725.
# Good OTE entry setup, but it's a higher-low failure-to-sweep on M15 (didn't sweep 4708). 
# Might be a valid M5 setup. I will mark it as shadow.
results.append({
    "candidate_id": "candidate_2026-04-13T04-30-00Z_long_liquidity_sweep_reversal",
    "timestamp": "2026-04-13T04:30:00Z",
    "decision": "shadow",
    "reason": "Re-test of Fib 50% discount zone (4710). 04:30 sweeps 04:15 low but forms a higher low relative to 04:00 (4708.64), then rejects strongly. Good follow-through but lacks clear structural sweep of the swing low.",
    "htf_context": "H1 consolidating bullish impulse. Price returned to 50% OTE discount (4710) of the 4693-4728 leg.",
    "m30_structure": "Pullback into discount, forming support.",
    "m15_m5_execution": "04:30 tests 4709.21, respecting the 04:00 low of 4708.64. Bullish engulfing close at 4718 followed by immediate rally to 4725. Viable M5 entry but lacks major sweep.",
    "entry": 4715.0,
    "stop": 4708.0,
    "target": 4725.0,
    "r": 1.4,
    "promoted_to_journal": False
})

with open(result_path, 'w') as f:
    json.dump(results, f, indent=2)

print(f"Wrote {result_path}")
