import json
import sys

def write_result(results):
    res_path = "/home/aryy/.hermes/profiles/finance/backtests/xauusd_2026/hybrid/reviews/manual_replay_results/replay_result_00207_00210.json"
    with open(res_path, 'w') as f:
        json.dump(results, f, indent=2)
    print(f"Wrote {res_path}")
    
def analyze():
    # Item 207: candidate_2026-02-13T17-15-00Z_long_liquidity_sweep_reversal
    # HTF Context: H1 was bullish (14:00 open 4987 -> 16:00 close 5007), making higher highs.
    # M30 shows a strong bullish impulse from 4975 (16:00) to 5028.
    # At 17:00, price pulled back. M5 at 17:15 hit low 5006.1.
    # Is there a valid entry on M5 after 17:15?
    # M5 17:15 candle: open 5015.8, high 5016.2, low 5006.1, close 5010.6. This is a sweep of 5006 level (from 17:00).
    # M5 17:25 candle closes at 5017.7, reversing the sweep.
    # Entry around 5017. SL below 5006 (e.g. 5004). Target: recent highs at 5028.
    # Price hits 5025 at 17:30, then 5029 at 17:35. Target reached. R ~1:1 or 1:1.5. But the entry at 17:25 closing is 5017, SL 5004 (13 pts), TP 5028 (11 pts). R is less than 1.
    # Better entry: at Fib 50% of the 17:15 tail. But we don't have intra-candle data.
    # Let's reject or mark shadow due to poor R:R.
    
    # Item 208: candidate_2026-02-13T18-00-00Z_long_liquidity_sweep_reversal
    # At 18:00, price sweeps low 5015.4.
    # 18:05 reverses up, closes 5021.5. Entry 5021. SL 5014. (7 pts)
    # TP: recent high 5030. (9 pts). R ~ 1.3.
    # Price hits 5030 at 18:15.
    # It works, but R:R is marginal. Let's shadow it.

    # Item 209: candidate_2026-02-16T00-00-00Z_short_liquidity_sweep_reversal
    # 2026-02-16 00:00:00Z Short.
    # H4 closing at Feb 13 18:00 was 5042. At Feb 15 23:00 it's opening 5017. Gap down over weekend.
    # At 00:00, price drops from 5020 to 5000, closing at 5008.
    # This is an impulsive drop. The short candidate suggests entering short on a sweep reversal.
    # After 00:00, price bounces to 5021 (00:15) then drops to 5009 (00:30).
    # The setup is a bit messy with the weekend gap. Let's keep it needs_more_context / rejected due to gap volatility.

    results = [
        {
            "candidate_id": "candidate_2026-02-13T17-15-00Z_long_liquidity_sweep_reversal",
            "timestamp": "2026-02-13T17:15:00Z",
            "decision": "shadow",
            "reason": "Sweep of 5006 with quick reversal, but R:R to recent highs is poor (< 1).",
            "htf_context": "H1 strongly bullish making higher highs into 5028.",
            "m30_structure": "Bullish impulse on M30, pulling back.",
            "m15_m5_execution": "M5 swept 5006 at 17:15 and reversed, but entry distance to SL vs TP at highs offered poor R:R.",
            "entry": 5017.7,
            "stop": 5005.0,
            "target": 5028.5,
            "r": 0.85,
            "promoted_to_journal": False
        },
        {
            "candidate_id": "candidate_2026-02-13T18-00-00Z_long_liquidity_sweep_reversal",
            "timestamp": "2026-02-13T18:00:00Z",
            "decision": "shadow",
            "reason": "Valid M5 sweep of 5015 level with reversal, but marginal R:R.",
            "htf_context": "Bullish trend continuing on HTF.",
            "m30_structure": "Consolidation after impulse.",
            "m15_m5_execution": "M5 swept 5015 at 18:00 and closed bullish at 18:05. Target 5030 hit quickly.",
            "entry": 5021.6,
            "stop": 5014.5,
            "target": 5030.8,
            "r": 1.29,
            "promoted_to_journal": False
        },
        {
            "candidate_id": "candidate_2026-02-16T00-00-00Z_short_liquidity_sweep_reversal",
            "timestamp": "2026-02-16T00:00:00Z",
            "decision": "needs_more_context",
            "reason": "Weekend gap down creates messy structure; M5 drop at 00:00 lacks clean entry.",
            "htf_context": "Gap down from 5042 to 5017 over weekend.",
            "m30_structure": "Volatile opening action.",
            "m15_m5_execution": "M5 huge drop at 00:00 to 5000, bounced to 5021, messy price action without clean Fib/OTE.",
            "entry": None,
            "stop": None,
            "target": None,
            "r": None,
            "promoted_to_journal": False
        }
    ]
    
    write_result(results)

if __name__ == "__main__":
    analyze()
