// This Pine Script® code is licensed under Apache-2.0
// SPDX-License-Identifier: Apache-2.0
// © PineForge contributors 2026
//
// PF probe 96 - multi-cycle deferred-flip growth, cross-bar variant
//
// Purpose: same diagnostic as probe 95, but with ``process_orders_on_close=true``
// so the ``strategy.close`` market exit fires on the SAME bar as the
// cross event (at that bar's close), while the stop entry still waits
// for the NEXT bar's open. This forces close and stop fire onto
// different bars — exercising the cross-bar deferred-flip path (probe 92's
// territory) rather than the same-bar paired-close path.
//
// If probe 95 (same-bar) and probe 96 (cross-bar) both reach excellent,
// the deferred-flip implementation is sound for both regimes and the
// residual probes 52 / 63 divergence is genuinely sub-bar fill
// precision, not the carry rule.
//
// Weekly forced-flat at Monday 00:00 caps the chain length at ~14 cycles
// per week so the position notional stays well below initial_capital
// (avoids TV's broker capital-cap split behaviour).
//
// TV setup: 15m chart, same symbol/window as data/ohlcv_ETH-USDT-USDT_15m.csv.
// Export TradingView "List of trades" to trades.csv in this folder.
//@version=6
strategy("PF probe 96 - multi-cycle POOC cross-bar", shorttitle="PF_P96_POOC",
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=true)
isDown = hour == 8 and minute == 0
isUp = hour == 14 and minute == 0
// Open-guaranteed stop levels (see probe 95 for derivation).
shortStop = high * 10.0
longStop = low * 0.1
if isDown
strategy.entry("SE", strategy.short, qty=1, stop=shortStop, comment="open-guaranteed short")
strategy.cancel("LE")
if isUp
strategy.entry("LE", strategy.long, qty=1, stop=longStop, comment="open-guaranteed long")
strategy.cancel("SE")
if isDown and strategy.position_size > 0
strategy.close("LE", comment="flip flat long")
if isUp and strategy.position_size < 0
strategy.close("SE", comment="flip flat short")
if dayofweek == 2 and hour == 0 and minute == 0 and strategy.position_size != 0
strategy.close_all(comment="weekly reset")