// This Pine Script® code is licensed under Apache-2.0
// SPDX-License-Identifier: Apache-2.0
// © PineForge contributors 2026
//
// PF TV golden 49 - na/nz/fixnan history chain
//
// Purpose: isolate warmup behavior for history references, nz(), fixnan(), and chained series.
// 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 TV golden 49 - na nz history", shorttitle="PF_G49_NA", 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)
rawDelta = close - close[1]
safeDelta = nz(rawDelta, 0)
heldDelta = fixnan(rawDelta)
score = ta.sma(safeDelta + nz(heldDelta, 0), 8)
longSignal = not na(score) and score > 0 and nz(score[1], 0) <= 0
flatSignal = not na(score) and score < 0 and nz(score[1], 0) >= 0
if longSignal and strategy.position_size == 0
strategy.entry("N", strategy.long, qty=1, comment="na chain long")
if flatSignal and strategy.position_size > 0
strategy.close("N", comment="na chain flat")