// This Pine Script® code is licensed under Apache-2.0
// SPDX-License-Identifier: Apache-2.0
// © PineForge contributors 2026
//
// PF probe wunder-scalper-probe-integration — explicit reverse routing + alert hooks
// Clean-room: written from validation goal, not from source.
//
// Purpose: composes the two surfaces isolated by `wunder-scalper-probe-01..02`
// into a single end-to-end WunderTrading-style scalp strategy. The engine
// surface under test is the cross-surface composition: every cross signal
// triggers (a) explicit `strategy.close_all()` if positioned the wrong way
// followed by `strategy.entry(...)` to open new direction, AND (b) an
// `alert(...)` with TV-side placeholder strings. The engine must reproduce
// the two-trade reversal pattern AND parse the alert calls without raising.
// Alert message content is not validated.
//
// Validation goal: bit-exact trade list against TradingView's broker emulator
// on the reference 15-minute ETH-USDT-USDT feed. Trade list parity is the
// pass criterion.
//
// TV setup: 15m chart, ETH-USDT-USDT (Binance USDT-M Perpetual). Full window
// matching corpus/data/ohlcv_ETH-USDT-USDT_15m.csv. Strategy properties:
// leave defaults from script header. Export "List of trades" → tv_trades.csv.
//@version=6
strategy("PF probe wunder-scalper-probe-integration", shorttitle="PF_WSINT",
overlay=true, initial_capital=1000000,
commission_type=strategy.commission.percent, commission_value=0,
slippage=0, default_qty_type=strategy.fixed, default_qty_value=1,
pyramiding=1, process_orders_on_close=false)
// ---- inputs --------------------------------------------------------
int i_fast = input.int(5, "Fast EMA", minval=2, maxval=50)
int i_slow = input.int(13, "Slow EMA", minval=3, maxval=100)
// ---- direction signal ---------------------------------------------
float ema_fast = ta.ema(close, i_fast)
float ema_slow = ta.ema(close, i_slow)
bool long_signal = ta.crossover(ema_fast, ema_slow)
bool short_signal = ta.crossunder(ema_fast, ema_slow)
// ---- explicit reverse routing + alert hooks -----------------------
if long_signal
if strategy.position_size < 0
strategy.close_all(comment="integ reverse close short")
strategy.entry("L", strategy.long, qty=1, comment="integ open long")
alert("{{strategy.order.action}} {{ticker}} long", alert.freq_once_per_bar)
if short_signal
if strategy.position_size > 0
strategy.close_all(comment="integ reverse close long")
strategy.entry("S", strategy.short, qty=1, comment="integ open short")
alert("{{strategy.order.action}} {{ticker}} short", alert.freq_once_per_bar)