"""TR-RSI-Supertrend W7-TEST: vectorbtpro run on Dukascopy H1 Bid (EURUSD, EURJPY).

Run: py -3.11 test.py   (from this folder; vectorbtpro required)
Reads gitignored working copies in ../_data, writes results/ CSVS.
Base rule: RSI(14) cross above 70 / below 30 with Supertrend(10, 3.0)
direction, SL at the line, fixed 1.5R target, next-bar entry, one position,
stop-first on ambiguous bars.
"""
import os
import sys

assert sys.version_info[:2] == (3, 11), "requires py -3.11, got %s" % sys.version
import vectorbtpro  # noqa: F401  (hard requirement: real engine, no fallback)

sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from w7_vbt import run_strategy

BASE = {
    "st_period": 10, "st_mult": 3.0, "rsi_period": 14, "rsi_mode": "cross",
    "adx_period": 14, "adx_thr": 25.0, "adx_rising": False,
    "stop_buf_atr": 0.0, "wide_skip_atr": 0.0,
}
VARIANTS = [
    dict(BASE, id="base"),
    dict(BASE, id="rsi7", rsi_period=7),
    dict(BASE, id="hold", rsi_mode="hold"),
    dict(BASE, id="st72", st_period=7, st_mult=2.0),
]

if __name__ == "__main__":
    outdir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "results")
    rows = run_strategy("tr-rsi-supertrend", VARIANTS, outdir, use_vbt=True)
    for s in rows:
        print("%s %-8s n=%d TP=%d SL=%d END=%d wr=%.2f%% be=%.2f%% effR=%s ddR=%s IS=%d/%.0f%% OOS=%d/%.0f%% both=%d" % (
            s["scope"], s["variant"], s["n_trades"], s["n_tp"], s["n_sl"], s["n_end"],
            100 * s["win_rate"], 100 * s["breakeven_win_rate"], s["effective_R"], s["maxdd_R"],
            s["is_n"], 100 * s["is_winrate"], s["oos_n"], 100 * s["oos_winrate"], s["both_hit_trades"]))
    print("vbt", rows[0]["vbt_version"], "reconciled", rows[0]["vbt_reconciled"])
